/* loads the Query Parameter aprm and oeid ; also calls set_action */
function load_aprm()
{
	//set_action();

	var addAPRMParam = find_query_value("aprm");
	if( addAPRMParam.length > 0 )
	{
		document.giftselections.aprm.value = addAPRMParam;
	}
	var addOEIDParam = find_query_value("oeid");
	if( addOEIDParam.length > 0 )
	{
		document.giftselections.oeid.value = addOEIDParam;
	}
}

/* loads the keycode; also calls set_action */

function load_keycode()
{

	//set action if site uri is specified
	set_action();

	//load oeid and aprm if specified
	load_aprm();

	var keycode = find_query_value("keycode");
	if( keycode.length > 0 )
	{
		document.giftselections.keycode.value = keycode;
		//(ctrl) != "undefined"
		if(typeof(document.forms[0].hdnActionURL) != "undefined")
		{
			if(document.forms[0].hdnActionURL.value != "")
			{
				document.giftselections.action = document.giftselections.hdnActionURL.value;
				document.giftselections.submit();
			}		
		}
		return true;
	}
	else
	{
      		alert("No keycode found.");
		return false;
	}
	
}

/* rewrites the form action url */

function set_action()
{
	var site_uri = find_query_value("site_uri");
	if( site_uri.length > 0 )
	{
		document.giftselections.action = "http://" + site_uri + "/gevalia/continuity/enroll/gift.aspx";
	}
	return;
}

/* gets the url query parameter value */

function find_query_value(name)
{
	var str = unescape(document.location.toString());
	var loc = str.lastIndexOf(name+"=");
	var value="";
	if( loc >= 0 )
	{
		var str1 = str.substring(loc+name.length+1);
		var loc1 = str1.indexOf("&");
		if( loc1 >= 0 )
		{
			value = str1.substring(0,loc1);
		}
		else
		{
			var loc2 = str1.indexOf("#");
			if( loc2 >= 0 )
			{
				value = str1.substring(0,loc2);
			}
			else
			{
				value = str1.substring(0);
			}
		}
	}
	return value;
}

function launch_search(param)
{
	var site_uri = find_query_value("site_uri");
	if( site_uri.length > 0 )
	{
		self.location.href = "http://" + site_uri + "/Gevalia/catalog/search_results.aspx?query=" + param;
	} else {
		self.location.href = "http://www.gevalia.com/Gevalia/catalog/search_results.aspx?query=" + param;
	}
	
	return;
}

function cc()
{
 /* check for a cookie */
  if (document.cookie == "") 
  {
    document.giftselections.cookieexists.value ="false"  
  } else {
    document.giftselections.cookieexists.value ="true"
  }
}

/* Set a cookie to be sure that one exists.
   Note that this is outside the function*/
document.cookie = 'killme' + escape('nothing')



function PopUp(imgURL){
	reWin=window.open('/common/popup.htm?path='+imgURL,'Popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=580,top=100,left=100');
}

function PopUpNew(imgURL){
	reWin=window.open('/common/popupnew.htm?path='+imgURL,'Popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=580,top=100,left=100');
}

