/**
 * Functions used by plentyShop & plentyCMS.
 * Copyright © 2007 plentySystems GmbH www.plentymarkets.de
 * All rights reserved.
 */
 
var pop_windows = new Array();

function $(id)
{
	return document.getElementById(id);
}

function doOpenWin(page,name,width,height,left,screenY,top,toolbar)
{
	var t = "";

	if( toolbar==false ){
		t = "toolbar=no,";
	}else{
		t = "toolbar=yes,";
	}
		if(pop_windows[name]){
			pop_windows[name].close();
		}

		//this.blur();
		var f = window.open(page,name,"width=" + width + ",height=" + height + ",scrollbars,resizable=yes,status=yes," + t + "left=" + left + ",screenY=" + screenY + ",top=" + top);
		f.focus();

		pop_windows[name] = f;
}


function OpenWin(page)
{
		doOpenWin(page,"plenty_win1",650,400,0,0,0,false);
}

function ImgWin(page)
{
		doOpenWin(page,"plenty_win_img",650,500,0,0,0,false);
}

function OpenWinBIG(page)
{
        doOpenWin(page,"plenty_win2",1000,500,0,0,0,false);
}

function OpenXSWin(page)
{
        doOpenWin(page,"plenty_win2",400,400,0,0,0,false);
}

function LOADWINSELF(page)
{
        var f= window.open(page,"_self");
        f.focus();
}

function isFormEmty(theForm, theFieldName)
{
    var isEmpty  = 1;
    var theField = theForm.elements[theFieldName];

	if(theField.value == "0")
	{
		theField.value = "1";
		return true;
	}else{
		return false;
	}

}

/**
 * Displays an confirmation box, this function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the sql query to submit
 *
 * @return  boolean  whether to run the query or not
 */
function confirmDangerousLink(theLink, theQuery)
{
    var is_confirmed = confirm(theQuery);
    if (is_confirmed)
	{
        theLink.href += '&is_js_confirmed=1';
    }

    return is_confirmed;
} // end of the 'confirmDangerousLink()' function

function calculateNewValueAndReset(targetID,sourceID)
{
	targetID.value = sourceID.value*1 + targetID.value*1;
	if(targetID.value<0)
		targetID.value.value = 0;
}

function switch_it(id)
{
	if($(id).style.display=="" || $(id).style.display=="block")
	{
		$(id).style.display = 'none';
	}
	else
	{
		$(id).style.display = '';
	}
}

function showBookTarget(txt)
{
	$('bookTarget').innerHTML=txt;
}

function bookThis(bookTarget)
{
	doc=encodeURIComponent(location.href);

	title=encodeURIComponent(document.title);

	switch(bookTarget) 
	{		
		case 'delicious':
			window.open('http://del.icio.us/post?url='+doc+'&title='+sbtitle);
			break;
		case 'mrwong':
			window.open('http://www.mister-wong.de/index.php?action=addurl&bm_url='+doc+'&bm_description='+title);
			break;
		case 'blinkList':
			window.open('http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url='+doc+'&Title='+title);
			break;
		case 'yahoo':
			window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+doc+'&t='+title);
			break;
		case 'yigg':
			window.open('http://yigg.de/neu?exturl='+doc+'&exttitle='+title);
			break;	
		case 'furl':
			window.open('http://www.furl.net/storeIt.jsp?u='+doc+'&t='+title);
			break;
		case 'oneview':
			window.open('http://beta.oneview.de:80/quickadd/neu/addBookmark.jsf?URL='+doc+'&title='+title);			
			break;
		case 'folkd':
			window.open('http://www.folkd.com/submit/page/'+doc);
			break;
		case 'linkarena':	
			window.open('http://linkarena.com/bookmarks/addlink/?url='+doc+'&title='+title+'&desc=&tags=');
			break;
		case 'google': 		
			window.open('http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+doc+'&title='+title);
			break;
		case 'webnews': 		
			window.open('http://www.webnews.de/einstellen?url='+doc+'&title='+title);
			break;
	}
}
