/* INCLUDE.JS */
/* Standard functions included on all pages in Baba.com.my */

////////////////////////////////////////////////////////////
// getAffiliateIDFromQueryString function
	function getAffiliateIDFromQueryString() {
		var query = window.location.search.substring(1);
		var pairs = query.split("&");
		var argname, argvalue;
		var affiliate_id = "";
		for (var i=0;i<pairs.length;i++) {
			var pos = pairs[i].indexOf('=');
			if (pos >= 0) {
				var argname = pairs[i].substring(0,pos);
				var argvalue = pairs[i].substring(pos+1);
				if (argname == "AffiliateID") {
					affiliate_id = argvalue;
				}
			}
		}		
		return affiliate_id;
	}
//
////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////
// setAffiliateID function
	function setAffiliateID() {				
		var AffiliateID = getAffiliateIDFromQueryString();
		var TimeOfArrival; Today = new Date(); TimeOfArrival = Today.getTime();
		// Set AffiliateID from QueryString and TimeOfArrival to the ONECOMMERCE cookie
		if (AffiliateID != ""){
			setCookie("AffiliateID", AffiliateID, 999999);			
			//setCookie("TimeOfArrival", TimeOfArrival, 999999); -- client side so this does not work for time capture
		}
	}
	// call setAffiliateID function for all pages
	//setAffiliateID();
//
////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////
// jump2Page function
  function jump2Page(slt)
  {
   window.location = slt.options[slt.selectedIndex].value;
  }
// jump2Page function
////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////
// gotourl function
	function gotourl(URL)
	{	
		document.location=URL;
	}
// gotourl function
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// popup function
	function popup(url, name, w, h, x, y)
	{	
		if( (name == "") || (name == null) )	{	var Winname = "BabaPopUp";	}
		else	{	var Winname = name;	}
		window.open(url, Winname, 'resizable=yes,toolbar=no,location=no,status=yes,scrollbars=yes,menubar=no,width='+w+',height='+h+',left='+x+',top='+y);
	}
// popup function
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// browser functions
	var nVersion = parseInt(navigator.appVersion)
	var isNavigator = navigator.appName.indexOf('Netscape')
	if (document.images)
		var browserswell = true;
// browser functions
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// setCookie function
// Sets a cookie. Give the cookie a name and a value, and set how many days or the date it will expire.
function setCookie(cookieName, cookieValue, days, month, year)
{	if (year && month)
	{	var expDate = new Date(year, month, days);
		document.cookie = cookieName + "=" + escape(cookieValue) + "; expires=" + expDate.toGMTString() + "; path=/";
	}
	else if (days)
	{	var expDate = new Date(); // current date
		expDate.setTime(expDate.getTime()+1000*60*60*24*days);
		document.cookie = cookieName + "=" + escape(cookieValue) + "; expires=" + expDate.toGMTString() + "; path=/";
	}
	else
	{	document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/";
	}
}
// setCookie function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// getCookie function
// Returns the value associated with the cookie of this name. Returns undefined if there is no such cookie.
function getCookie(cookieName)
{	var cookies = document.cookie.split(';'); 
	var cookiePieces;
	var i = -1;
	while (cookies[++i])
	{	cookiePieces = cookies[i].split('=');
	
		if (cookiePieces[0].substring(0,1) == ' ')
			cookiePieces[0] = cookiePieces[0].substring(1, cookiePieces[0].length);
		
		if (cookiePieces[0] == cookieName)
			return ""+unescape(cookiePieces[1]);
	}
	return ""
}
// getCookie function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// validateInventoryIDSelection function
function validateInventoryIDSelection(eForm){
	var iNumElems = eForm.elements.length;
	for (var i=0; i<iNumElems; i++) {
		var eElem = eForm.elements[i];
		if (eElem.type == "select-one") {
			var cOpts = eElem.options;
			var iNumOpts = cOpts.length;
			var eOpt = cOpts[0];
			if (eOpt.selected == true){
				alert("Please " + eOpt.text);
				return false;
			}
		}
	}
}
// validateInventoryIDSelection function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


