/***************************************************************************
Last Updated: Feb. 25, 2002
***************************************************************************/

/***************************************************************************
                         Javascript Client-side functions
***************************************************************************/

	var popup = '&popup=1';
	var popupq = '?popup=1';
	
	function AddPopup(url)
	{
		if(url.indexOf('?') >=0)
		{
			return url + popup
		}
		return url + popupq;
	}

   function OpenCBS(url) {
	           open("/global/scripts/jump_frame.epx?content=" + url,"CBS","width=575,height=515,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=yes");
	}
	
    function OpenDemo(url) {
	           open("/global/scripts/jump_frame.epx?content=" + url,"demo","width=610,height=410,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=yes");
	}
	
    function OpenOnlineDemo(url) {
	           open("/global/scripts/jump_frame.epx?content=" + url,"onlinedemo","width=810,height=625,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=no,status=no,dependent=no,scrollbars=no");
	}
	  
	function OpenPDF(url,closelabel) {
		if(!closelabel) closelabel="";
	           open("/global/scripts/jump_frame.epx?content=" + url + "&CloseLabel=" + closelabel,"pdf","width=610,height=480,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=yes");
	}
	
	function OpenVideo(url) {
	           open("/global/scripts/jump_frame.epx?content=" + url,"video","width=545,height=420,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=no,status=no,dependent=no,scrollbars=no");
	}
	
	function OpenMediaPlayer(url,closelabel,country) {
	           open("/global/scripts/jump_frame.epx?CloseLabel=" + closelabel + "&country=" + country + "&content=" + url,"video","width=545,height=420,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=no,status=no,dependent=no,scrollbars=no");
	}
	
	function OpenSite(url,width,height,closelabel) {
		if(!closelabel) closelabel="";
	           open("/global/scripts/jump_frame.epx?content=" + escape(url) + "&CloseLabel=" + closelabel,"site","width="+width+",height="+height+",left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=no");
	}

	function OpenSite640(url,closelabel) {
		var url = unescape(url);

		if(url.indexOf('/mk/get/sap_cfe?') >= 0)
		{
			var query = url.substring(url.indexOf('?') + 1);
			query = query.replace(/PDF_URL1/i, 'collateral');
			query = query.replace(/Atype/i, 'type');
			location.replace('/cdrp/index.epx?referrer=' + escape(location.href) + '&' + query);
		}else{
			if(!closelabel) closelabel="";
				open("/global/scripts/jump_frame.epx?content=" + escape(url) + "&CloseLabel=" + closelabel,"site","width=640,height=480,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=no");
	    }
	}
	
	function OpenSitePrebooking(url,closelabel,title,country) {
		if(!closelabel) closelabel="";
	           open("/global/scripts/jump_frame.epx?pagetitle=" + title + "&country=" + country + "&content=" + escape(url) + "&CloseLabel=" + closelabel,"site","width=640,height=480,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=no");
	}


		   function nameParent(newName,url) {
		   window.name = newName;
	           OpenSite800(url)
	}

	function OpenSite800(url,closelabel) {
		if(!closelabel) closelabel="";
	           open("/global/scripts/jump_frame.epx?content=" + escape(url) + "&CloseLabel=" + closelabel,"site","width=800,height=520,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=no");
	}

	function OpenCSP() {
	           open('/partners/software/directory/directory.asp','csp','width=650,height=450,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=yes');
	}

	function OpenCalc(url,title,width,height) {
	           open("/global/scripts/jump_frame.epx?CalcDisplay=1&content=" + escape(url) +"&title=" + escape(title),"site","width="+width+",height="+height+",left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=yes,status=no,dependent=no,scrollbars=no");
	}
	
	function OpenCalc_(url) {
	           open( url,'calc','width=900,height=600,menubar=yes,toolbar=yes,locationbar=yes,resizable=yes,status=no,dependent=no,scrollbars=yes');
	}
	
 	function OpenWebcast (url, title) {
    		 open(AddPopup(url), title, 'width=840,height=610,left=20,top=20,menubar=no,toolbar=no,locationbar=no,directories=no,resizable=yes,status=no,dependent=no');
    }  
	function openBrWindow(theURL,winName,features){
  		window.open(theURL,winName,features);
	}

function Search_SpecChar(){
   if(document.SAPcom_search.ct.value=="poland"){
	var search_query;
	var query_len;
	search_query=document.SAPcom_search.q1.value;
	query_len=search_query.length;
	var ucode;
	ucode="";

	for(i=0;i<query_len;i++){
		if(i==query_len-1){
			ucode=ucode + search_query.charCodeAt(i);
		}else{
			ucode=ucode + search_query.charCodeAt(i) + "-";
		}
	}
	document.SAPcom_search.q2.name="q1";
	document.SAPcom_search.q2.value=ucode;
	document.SAPcom_search.q1.name="q2";
    }
}

/***********************************************************
Added 8/11/2004 By C5054450
Search
Site Roles 
***********************************************************/
function searchPressed(obj, postback)
{
	var evt;
	var etype;
	
	if(window.event)
	{
		evt = window.event;
		etype = 1;
	}
	else if(arguments.callee)
	{
		evt = arguments.callee.caller.arguments[0];
		etype = 2;
	}
	if(evt)
	{
		var keyCode = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
		if(keyCode == 13)
		{
			eval(postback);

			if(etype == 1)
			{
				evt.cancelBubble = true;
				evt.returnValue = false;
			}else{
				return false;
			}
		}
	}
}

function changeRole(strValue)
{
	if (strValue != "")
	{
		var dt = new Date();
		dt.setDate(dt.getDate() + 10);
		document.cookie = "role=" + escape(strValue) + "; path=/; expires=" + dt.toGMTString();
	}
}
/*
function changeRole(select)
{
	if (select != null && select.selectedIndex != -1)
	{
		var dt = new Date();
		dt.setDate(dt.getDate() + 10);

		document.cookie = "role=" + escape(select.options[select.selectedIndex].text) + "; path=/; expires=" + dt.toGMTString();
		alert(document.cookie);
	}
}
*/
function cleanForm()
{
	for(i = 0; i < document.forms[0].length; i++)
	{
		var el = document.forms[0][i];
		if(el.type == 'text' || el.type == 'textarea')
		{
			while(el.value.indexOf('>') >= 0 || el.value.indexOf('<') >= 0 || el.value.indexOf('javascript') >= 0 || el.value.indexOf('onkeypress') >= 0)
			{
				el.value = el.value.replace('<', '').replace('>', '').replace('javascript', '').replace('onkeypress', '');
			}
		}
	}
}

function launchCollateral()
{
	if(isPDF)
	{
		window.open(collateralURL, '', 'menubar=yes, toolbar=yes, locationbar=yes, resizable=yes, status=yes, scrollbars=yes');
	}
	else if(isFlash)
	{
		if(location.search.indexOf('flash_detection.epx') >= 0)
			window.open(collateralURL,"x","width=670, height=575")
		else
			window.open("/global/scripts/jump_frame.epx?content=" + collateralURL,"onlinedemo","width=810,height=625,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=no,status=no,dependent=no,scrollbars=no");
	}		
	else if(isVideo)
	{
		window.open("/global/scripts/jump_frame.epx?content=" + collateralURL,"video","width=545,height=420,left=20,top=20,menubar=no,toolbar=no,locationbar=no,resizable=no,status=no,dependent=no,scrollbars=no");
	}
	else
	{
		window.open(collateralURL, '', 'menubar=yes, toolbar=yes, locationbar=yes, resizable=yes, status=yes, scrollbars=yes');
	}
	return false;
}

function CampaignCodeOnload()
{
	var key = 'campaigncode=';
	var search = location.search.toLowerCase();
	if(search.indexOf(key) >= 0)
	{
		var campaign_code = search.substring(search.indexOf(key) + key.length);
		if(campaign_code.indexOf('&') >= 0)
			campaign_code = campaign_code.substring(0, campaign_code.indexOf('&'));
		if(!(document.cookie.indexOf('cmpgn.init.code') >= 0))
			document.cookie = "cmpgn.init.code=" + campaign_code + "; Path=/";
	}
	AddToSiteCookie("cmpgn.url", location.href);
}

function GetCookie(Name) 
{
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search)
		if (offset != -1) 
		{ 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) 
				end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function AddToSiteCookie(Key, Value)
{
	var cookie = GetCookie("SAP.SITE.COOKIE");
	var items = new Array();
	items = cookie.split("&");
	if(items.length > 0 && items[0] != '')
	{
		cookie = '';
		for(i = 0; i < items.length -1; i++)
		{
			if(items[i] != '')
			{
				if(items[i].indexOf(Key + "=") >= 0)
				{
					cookie += Key + "=" + escape(Value) + "&";
				}else{
					cookie += items[i] + "&";
				}
			}
		}
		cookie = cookie.substring(0, cookie.length - 1);
	}else{
		if(cookie.length != 0)
			cookie += "&";
		cookie += Key + "=" + escape(Value);
	}
	cookie = "SAP.SITE.COOKIE=" + cookie + "; path=/; "
	if (strDomain && strDomain != null && strDomain != '')
		cookie += 'domain=' + strDomain;
	document.cookie = cookie;
}
