// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}
/* function modified by raju for CHR67 starts here*/
function submitDoc(formName,tab) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		if(findObj(formName).name!='gateway')
		{
			if(findObj(formName).name!='addreview')
			{
			if(tab!="" || tab=="undefined")
				findObj(formName).action+="&tab="+tab;	
			}
			else
				findObj(formName).action+="&tab=RR";
		}
		findObj(formName).submit(); 
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}
/* function modified by raju for CHR67 ends here*/
//Function to validate Terms and conditions.
function validateTC(tcCheckbox)
{
	if(tcCheckbox == true)
	{
		document.getElementById('continueNo').style.display = 'none';
		document.getElementById('continueYes').style.display = 'block';
	}
	else
	{
		document.getElementById('continueNo').style.display = 'block';
		document.getElementById('continueYes').style.display = 'none';
	}
}

// This function sets a client-side cookie as above.  Only first 2 parameters are required
// Rest of the parameters are optional. If no szExpires value is set, cookie is a session cookie.
//
// Prototype : setCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,bSecure])
//******************************************************************************************

function setCookie(szName, szValue, szExpires, szPath, szDomain, bSecure)
{
 	var szCookieText = 	   escape(szName) + '=' + escape(szValue);
	szCookieText +=	 	   (szExpires ? '; EXPIRES=' + szExpires.toGMTString() : '');
	szCookieText += 	   (szPath ? '; PATH=' + szPath : '');
	szCookieText += 	   (szDomain ? '; DOMAIN=' + szDomain : '');
	szCookieText += 	   (bSecure ? '; SECURE' : '');
	
	document.cookie = szCookieText;
}

//******************************************************************************************
// This functions reads & returns the cookie value of the specified cookie (by cookie name) 
//
// Prototype : getCookie(szName)
//******************************************************************************************

function getCookie(szName)
{
 	var szValue =	  null;
	if(document.cookie)	   //only if exists
	{
       	var arr = 		  document.cookie.split((escape(szName) + '=')); 
       	if(2 <= arr.length)
       	{
           	var arr2 = 	   arr[1].split(';');
       		szValue  = 	   unescape(arr2[0]);
       	}
	}
	return szValue;
}

//******************************************************************************************
// To delete a cookie, pass name of the cookie to be deleted
//
// Prototype : deleteCookie(szName)
//******************************************************************************************

function deleteCookie(szName)
{
	var confm = confirm('Are you sure to clear search history?');
	if(confm)
	{
		var tmp = getCookie(szName);
		if(tmp) 
		{ setCookie(szName,tmp,(new Date(1))); }
		else
		{
			var url = window.location.href;	
			url = encodeURIComponent(url); 
			window.location = 'deleteCookie.php?searchhistory=clear&url='+url;
		}
		document.getElementById('searchHistoryDivId').style.display = 'none';
	}
	return false;
}
//*****************************************************************************
//new function added by raju on mar16-2009 to change product price for on changing 
//of product options code starts here
//******************************************************************************
function priceChange2(val)
{    
	var optSign="";
	var w = document.getElementById('productOptions[]').selectedIndex;
	var optValue = document.getElementById('productOptions[]').options[w].text;	
	var exist = optValue.indexOf("$");
	if(exist != -1)
	{
		var optArray = optValue.split("(");
		optSign = optArray[2].charAt(0);
		var optPrice = optArray[2].substr(2,5);		
	}
	if(document.getElementById('salePrice').value!="")
	{		
		var mytool_array=document.getElementById('salePrice').value.split("$");
		var newPrice = mytool_array[1];
		if(optSign != "")
		{
			if(optSign == '+')
				newPrice = parseFloat(newPrice)+parseFloat(optPrice);
			else
				newPrice = parseFloat(newPrice)-parseFloat(optPrice);
		}		
		var formattedPrice = format_numberex(newPrice,2);
		document.getElementById('prodSalePrice').innerHTML = '$'+formattedPrice;
	}
	else
	{
		var mytool_array=document.getElementById('price').value.split("$");
		var newPrice = mytool_array[1];		
		if(optSign != "")
		{
			if(optSign == '+')
				newPrice = parseFloat(newPrice)+parseFloat(optPrice);
			else
				newPrice = parseFloat(newPrice)-parseFloat(optPrice);
		}
		var formattedPrice = format_numberex(newPrice,2);
		document.getElementById('prodPrice').innerHTML = '$'+formattedPrice;
	}
}
function format_numberex(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}
//*****************************************************************************
//new function added by raju on mar16-2009 to change product price for on changing 
//of product options code ends here
//******************************************************************************
//new function for advanced product tab starts here
function getdata(current,tabIds){
	var tabIdsArr = tabIds.split(",");
	var tabscount = tabIdsArr.length;
	var tdid= current+'td';
	for(var i=0;i<tabscount;i++)
	{
		document.getElementById("inf_tab_0"+tabIdsArr[i]).className="adv_inf_tabs_h";
		document.getElementById("inf_tab_0"+tabIdsArr[i]+"td").className="adv_tab_off";
	}
	document.getElementById(tdid).className="adv_tab_on"
	document.getElementById(current).className="adv_inf_tabs"
}
//CHR60: added new functions by raju for remedy production options starts here
function assignSelectedProducts()
{
	var to = document.addtobasket.productOptions;
	var productsLength = to.options.length;
	if(productsLength > 0)
	{
		var arrProduct = new Array();
		var ProductIds = '';
		for(var i=0;i<productsLength;i++)
		{
			ProductIds += to.options[i].value+',';
		}
		strLen = ProductIds.length;
		ProductIds = ProductIds.slice(0,strLen-1); 
		document.getElementById('selectedOptions').value = ProductIds;
		
		// Remove remedy ids from myorder cookie
		var tmp = getCookie('myorder');
		if(tmp) 
		{ setCookie('myorder',tmp,(new Date(1))); }
		
		document.addtobasket.submit();
	}
	else
	{
		alert("Please add atleast a Remedy product option to the cart.");
		return false;
	}
}
function openProds(current,tabscount,classStr,color){
	var classArray = classStr.split(",");
	var tdid= current+'td';
	var curlen = current.length;
	if(curlen == 11)
	{
		var curNum = current.charAt(curlen-2);	
		curNum+= current.charAt(curlen-1);
		var ltdid= 'ltab'+curNum+'td';
		var rtdid= 'rtab'+curNum+'td';
	}
	else
	{
		var curNum = current.charAt(curlen-1);			
		var ltdid= 'ltab'+curNum+'td';
		var rtdid= 'rtab'+curNum+'td';
	}
	for(var i=1;i<=tabscount;i++)
	{		
		document.getElementById("inf_tab_0"+i).className="adv_inf_tabs_h";
		if(classArray[i-1] == "blue")
		{			
			document.getElementById("inf_tab_0"+i+"td").className="adv_tab_remedy_off";
			document.getElementById("ltab"+i+"td").className='remedytab_img_off';
			document.getElementById("rtab"+i+"td").className='remedytab_img_off';
		}
		else
		{
			document.getElementById("inf_tab_0"+i+"td").className="oadv_tab_remedy_off";
			document.getElementById("ltab"+i+"td").className='oremedytab_img_off';
			document.getElementById("rtab"+i+"td").className='oremedytab_img_off';
		}
	}
	if(color == "orange")
	{
		document.getElementById(tdid).className="oadv_tab_remedy_on"
		document.getElementById(ltdid).className='oremedytab_img_on';
		document.getElementById(rtdid).className='oremedytab_img_on';
	}
	else
	{
		document.getElementById(tdid).className="adv_tab_remedy_on"
		document.getElementById(ltdid).className='remedytab_img_on';
		document.getElementById(rtdid).className='remedytab_img_on';
	}
	document.getElementById(current).className="adv_inf_tabs"
}
//CHR60: added new function by raju for remedy production options ends here