var webName = "MyORCOPL";
var pary;
function koki_load(name)
{
	var allkoki = document.cookie;
	if(allkoki == "") return false;
	var seekkoki =""
	for(var mm=0;mm<18;mm++)
	{
		var start = allkoki.indexOf(name+mm+'=');
		if(start == -1) break;
		var end = allkoki.indexOf(';',start);
		if(end == -1)
			end = allkoki.length;
		seekkoki += allkoki.substring(start-1,end)+";";
	}
	if(seekkoki.length>0)
	{
		seekkoki=seekkoki.substring(0,seekkoki.length-1);
		pary = seekkoki.split(';');
		for(var i=0; i<pary.length; i++)
		{
			var pp = pary[i].split('=');
			pary[i] = pp[1].split(":");
		}
		return true;
	}
	return false;
}
function koki_compact()
{
	var tt="";
	for(var k=0;k<pary.length;k++)
	{
		tt += pary[k][0] +":"+ pary[k][1] +":"+ pary[k][2];
	}
	return tt ;
}
function koki_search(xxtyp,xxname)
{
	for(var j=0;j<pary.length;j++)
	{
//	alert(pary[j][0]+"=="+ xxtyp +" && "+ unescape(pary[j][1]) +"=="+ xxname);
		if(pary[j][0] == xxtyp && unescape(pary[j][1]) == xxname )
			return j;
	}
	return -1;
}

function AddInCok(aname,objid)
{
	docurl = window.location;
	xdocurl = docurl.pathname + docurl.search;
	xtyp = 'P';
	var xname = "";
	if(docurl.search != "")
	{
		// Object
		xtyp='O';
		xname = objid;
	}
	else
	{
		// project
//		var sName = document.getElementById("city") ;
		xname = docurl.pathname.substring(1,docurl.pathname.length);
	}	

	if(koki_load(webName))
	{
		var kk = pary.length;
		if(kk<18)
		{			
			if(koki_search(xtyp,xname)<0)
			{
				document.cookie= webName + kk +"="+ xtyp +":"+ escape(aname) + ":" + escape(xname) +":" + escape(xdocurl) +";path=/; expires=Fri, 1 Jan 2010 23:59:59 GMT;";
				alert("Object added to My choice");				
			}
			else
			{
				alert("Object already exists in My choice");
			}
		}
		else
		{
			alert("Maximum limit of objects reached");
			return; 
		}
	}
	else
	{
		document.cookie= webName + "0="+ xtyp + ":" + escape(aname) + ":" + escape(xname) +":" + escape(xdocurl) +";path=/; expires=Fri, 1 Jan 2010 23:59:59 GMT;";
		alert("Object added to My choice");
	}
}

function DelCCoki()
{
		document.cookie= webName + "City=;path=/; expires=Tue, 1 Jan 2002 23:59:59 GMT;";
}



function EnAddInCok(aname,objid)
{
	docurl = window.location;
	xdocurl = docurl.pathname + docurl.search;
	xtyp = 'P';
	var xname = "";
	if(docurl.search != "")
	{
		// Object
		xtyp='O';
		xname = objid;
	}
	else
	{
		// project
//		var sName = document.getElementById("city") ;
		xname = docurl.pathname.substring(1,docurl.pathname.length);
	}	

	if(koki_load(webName))
	{
		var kk = pary.length;
		if(kk<18)
		{			
			if(koki_search(xtyp,xname)<0)
			{
				document.cookie= webName + kk +"="+ xtyp +":"+ escape(xname) +":" + escape(xdocurl) +";path=/; expires=Fri, 1 Jan 2010 23:59:59 GMT;";
				alert( aname +"\r\n  added to My IPB Real");
			}
			else
			{
				alert( aname +"\r\n  already exists in My IPB Real");
			}
		}
		else
		{
			alert("Not enough capacity");
			return; 
		}
	}
	else
	{
		document.cookie= webName + "0="+ xtyp +":"+ escape(xname) +":" + escape(xdocurl) +";path=/; expires=Fri, 1 Jan 2010 23:59:59 GMT;";
		alert( aname +"\r\n  added to My IPB Real");
	}
}

// open new win func
function openWin( path, width, height ) {
	ipbwin=window.open(path,'_ipb'+width+height,'scrollbars=yes,resizable=yes,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width) );
	ipbwin.focus();
}
function openHardWin( path, width, height ) {
	ipbwin=window.open(path,'_ipbh'+width+height,'scrollbars=no,resizable=no,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width) );
	ipbwin.focus();
}
	
function openBannerWin(path, width, height) {
	BannerWin=window.open(path,'BannerWin','scrollbars=no,resizable=no,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width) );
	BannerWin.focus();
}
	
function getCenterW(width) {
	return parseInt( eval( (screen.width-parseInt(width))/2 ) );
}

function getCenterH(height) {
	return parseInt( eval( (screen.height-parseInt(height))/2 ) );
}

