var Total=0
var configArr, sCustomFields

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function used to format numbers.
//	@		                	If we pass 100 , this funciton will return 100.00.
//	@	  Pages Affected  : CustomKitItems.asp
//  @		Function Name		: formatValue(value)									
//	@		Input Parameters: value = then number to be formatted
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function formatValue(value){
	return Math.round(value*100)/100;
}
// End of the function formatValue(value)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This printkit function is to show the printable version of the Kit. 
//	@		                	It opens Customprint.htm and shows the ItemImage, ItemName, Item desc 
//	@		                	and Price. These data's are taken from the hidden fields. It checks  
//	@		                	for callforprice also. Qty is taken as 1 by default. It checks for 
//	@		                	the selected item in the combo box and dispalays the category 
//	@		                	for selected item and the corresponding item. It checks for '[' in the 
//	@		                	item name and removes all character's after '['.
//	@	  Pages Affected  : CustomKitItems.asp
//  @		Function Name		: printkit()									
//	@		Input Parameters: null
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


function printkit()
{
	var iIndex,myWin,iCount,sString1,len,sString2,sImgLink;
	myWin = window.open('','_kit','width=500,height=500,toolbar,scrollbars')
	//myWin.document.open();
	iCount = 0;
	len = document.frmKitUpgrades.elements.length;
	myWin.document.write("<TITLE>"+getMessage("iPrintVerKit")+"</TITLE>");
	myWin.document.write("<table border =0 cellspacing = '8'><tr><td width = 100% colspan=4 valign = top><font face = 'verdana, arial' size = 1><B>");
	sImgLink=document.frmKitAmt.imglink.value 
	if (sImgLink.substring(sImgLink.length - 1, sImgLink.length) != "/" )
	myWin.document.write("<img src='" + document.frmKitAmt.imglink.value + "' align=left>");
	myWin.document.write(document.frmKitAmt.itemname.value);
	myWin.document.write("</B><br><br>");
	myWin.document.write(document.frmKitAmt.description.value);
	if (sKitCall4Price == "T") {
		myWin.document.write("</td></tr><tr><td colspan=3><font face = 'verdana, arial' size = 1 valign=top>"+getMessage("iKitPrice")+":&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+getMessage("iCallForPrice"));
	}
	else {
		myWin.document.write("</td></tr><tr><td colspan=2><font face = 'verdana, arial' size = 1 valign=top><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+getMessage("iQty")+" : "+ iQty + "</td></tr><tr><td colspan='3'><font face = 'verdana, arial' size = 1>"+getMessage("iKitPrice")+":&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + sCurrSymbol);
		myWin.document.write(document.frmKitAmt.txtTotalKitValue.value);
		if (sAdditionalCurrencySymbol != "") {
			myWin.document.write("&nbsp; (" + sAdditionalCurrencySymbol + document.frmKitAmt.txtTotalKitValue_Add_Curr.value +")");
		}
	}
	myWin.document.write("</b></font></td></tr>");
	if (bShowCustomFields) {
		myWin.document.write(sCustomFields);
	}
	for(iIndex=0;iIndex<=parseInt(len)-1;iIndex++)
	{
		if((document.frmKitUpgrades.elements[iIndex].type.substring(0,3) == "sel") || (document.frmKitUpgrades.elements[iIndex].name.substring(0,8) == "upg_name"))
		{		
				if(iCount==0) {
					myWin.document.write("<tr><td colspan=4><font face = 'verdana, arial' size = 1 valign=top><b>"+getMessage("iKitItem"));
					if (sKitClubTotal != "T" && sKitCall4Price != "T") {
						myWin.document.write(" " + getMessage("iIndividualPrice"))
					}
					myWin.document.write(" " + getMessage("iShownBelow")+"</b></font></td></tr>");
				}
				iCount++;
				myWin.document.write("<tr><td><font face = 'verdana, arial' size = 1>");
				myWin.document.write(eval("document.frmKitUpgrades.kitname" + iCount + ".value")+"</td></font>");
				//Added to Show individual kit items price
				if (sKitClubTotal != "T" && sKitCall4Price != "T") {
					myWin.document.write("<td nowrap><font face = 'verdana, arial' size = 1>" + sCurrSymbol);
					myWin.document.write(eval("document.frmKitUpgrades.price" + iCount + ".value"));
					if (sAdditionalCurrencySymbol != "") {
						myWin.document.write(" &nbsp;(" + sAdditionalCurrencySymbol + eval("document.frmKitUpgrades.Add_Curr_price" + iCount + ".value")+ ") ");
					}
					myWin.document.write("</td></font>")
				}
				//Ends Here
				myWin.document.write("<td><font face = 'verdana, arial' size = 1>");
				if(document.frmKitUpgrades.elements[iIndex].type.substring(0,3) == "sel"){
					sString1 = document.frmKitUpgrades.elements[iIndex].options[document.frmKitUpgrades.elements[iIndex].selectedIndex].text;
					sString2 = sString1.indexOf("[");
					if(sString2 != -1)
						sString1 = sString1.substring(0,sString2-1);
				}	
				else
					sString1 = document.frmKitUpgrades.elements[iIndex].value

				myWin.document.write(sString1);
				myWin.document.write("</td></tr>");
			}
	}	
	myWin.document.write("</table>");
	myWin.document.close();
	myWin.focus();
}
// End of the function printkit()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is to popup the details of the item selected in the list box.
//	@	  Pages Affected  : CustomKitItems.asp
//  @		Function Name		: printitem(sel)									
//	@		Input Parameters: sel = To find the name of the list box
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function printitem(sel)
{
	var code,arr;
	code =eval("document.frmKitUpgrades.sel" + sel + ".options[document.frmKitUpgrades.sel" + sel + ".selectedIndex].value");
	arr = code.split("#");
	code = "sNonSecurePath+printItem.asp?Source=CK&ic="+arr[0];
	if(arr[3]=="T")
		window.open(sNonSecurePath+"printItem.asp?Source=CK&ic="+arr[0],"winPrint","toolbar,height=400,width=550,scrollbars,resizable");
	else
		alert(getMessage("iMoreInfoNotAvail"));
}
// End of the function printitem(sel)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is to recalculate the total whenever user changes 
//  @                     the configuration, and to change the price in the text box.
//	@	  Pages Affected  : CustomKitItems.asp
//  @		Function Name		: CalculateTotal()									
//	@		Input Parameters: null
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function CalculateTotal(kitprice,clubtotal,sLocaleId,addKitPrice){
	if(sLocaleId == "")
		sLocaleId = iEnglishLocaleId;
	var i,sel_Count;
	var Sum,addSum,temp,addtemp,arr,arr2,totalvalue,addTotalvalue,sKitValue,sAddKitValue,objKitFld,objAddKitFld;
	totalvalue=0;
	addTotalvalue=0;
	configArr=""
	
	len = document.frmKitUpgrades.elements.length;
	// Start of If Loop
	if (sKitCall4Price != "T") {
		if(clubtotal=='T'){
			Sum=getEnglishLocale(kitprice,sLocaleId);
			addSum = getEnglishLocale(addKitPrice,sLocaleId);
		}
		else{
			Sum = 0.0;
			addSum = 0.0;
		}
			
		sel_Count = 0;
		
		for(i=0;i<=parseInt(len)-1;i++)	{
			if(document.frmKitUpgrades.elements[i].type.substring(0,3) == "sel") {				
				arr =  document.frmKitUpgrades.elements[i].options[document.frmKitUpgrades.elements[i].selectedIndex].value.split("#");
				arr2 = document.frmKitUpgrades.elements[i].options[0].value.split("#");
				if (document.frmKitUpgrades.elements[i].selectedIndex == 0){
					if (clubtotal != 'T'){
						Sum = formatValue(parseFloat(Sum) + parseFloat(getEnglishLocale(arr[1],sLocaleId) * parseInt(arr[2])));
						addSum = formatValue(parseFloat(addSum) + parseFloat(getEnglishLocale(arr[4],sLocaleId) * parseInt(arr[2])));
					}
						
				}
				else{
					if (clubtotal == 'T'){					
						Sum = formatValue(parseFloat(Sum) + parseFloat(getEnglishLocale(arr[1],sLocaleId) * parseInt(arr[2])));
						addSum = formatValue(parseFloat(addSum) + parseFloat(getEnglishLocale(arr[4],sLocaleId) * parseInt(arr[2])));
					}
					else {
						Sum = formatValue(parseFloat(Sum) + parseFloat((parseFloat(getEnglishLocale(arr[1],sLocaleId)) + parseFloat(getEnglishLocale(arr2[1],sLocaleId))) * parseInt(arr2[2])));
						addSum = formatValue(parseFloat(addSum) + parseFloat((parseFloat(getEnglishLocale(arr[4],sLocaleId)) + parseFloat(getEnglishLocale(arr2[4],sLocaleId))) * parseInt(arr2[2])));
					}
				}				
				configArr = configArr + parseInt(document.frmKitUpgrades.elements[i].selectedIndex)+ "#";
				sel_Count = parseInt(sel_Count) + 1;
				if (clubtotal != 'T'){
					if(document.frmKitUpgrades.elements[i].selectedIndex == 0)	{
						temp = getEnglishLocale(arr2[1],sLocaleId)*arr2[2];
						addtemp	=getEnglishLocale(arr2[4],sLocaleId)*arr2[2];
						eval("document.frmKitUpgrades.price" + sel_Count + ".value=" + formatValue(temp));
						fldname="frmKitUpgrades.price" + sel_Count;
						setFormat(fldname);
						objKitFld = eval("document.frmKitUpgrades.price" + sel_Count);						 
						objKitFld.value= getCurrentLocale(objKitFld.value,sLocaleId);
						if (sAdditionalCurrencySymbol != "") {
							eval("document.frmKitUpgrades.Add_Curr_price" + sel_Count + ".value=" + formatValue(addtemp));												
							addfldname="frmKitUpgrades.Add_Curr_price" + sel_Count;
							setFormat(addfldname);
							objAddKitFld = eval("document.frmKitUpgrades.Add_Curr_price" + sel_Count);	
							objAddKitFld.value= getCurrentLocale(objAddKitFld.value,sLocaleId);				
						}
					}
					else	{
						temp = getEnglishLocale(arr[1],sLocaleId);
						temp = (parseFloat(temp) + parseFloat(getEnglishLocale(arr2[1],sLocaleId)))*arr2[2];
						addtemp = getEnglishLocale(arr[4],sLocaleId);
						addtemp = (parseFloat(addtemp) + parseFloat(getEnglishLocale(arr2[4],sLocaleId)))*arr2[2];
						eval("document.frmKitUpgrades.price" + sel_Count + ".value=" + formatValue(temp));
						fldname="frmKitUpgrades.price" + sel_Count;
						setFormat(fldname);
						objKitFld = eval("document.frmKitUpgrades.price" + sel_Count);
						objKitFld.value= getCurrentLocale(objKitFld.value,sLocaleId);
						if (sAdditionalCurrencySymbol != "") {
							eval("document.frmKitUpgrades.Add_Curr_price" + sel_Count + ".value=" + formatValue(addtemp));												
							addfldname="frmKitUpgrades.Add_Curr_price" + sel_Count;
							setFormat(addfldname);
							objAddKitFld = eval("document.frmKitUpgrades.Add_Curr_price" + sel_Count);						 
							objAddKitFld.value= getCurrentLocale(objAddKitFld.value,sLocaleId);				
						}
					}
				}
			}
			
			if(document.frmKitUpgrades.elements[i].name.substring(0,13) == "upgradehidden")	{
				configArr = configArr + 0 + "#"
				sel_Count = parseInt(sel_Count) + 1;
			}
		}
	
		if(clubtotal != 'T'){
			for(i=0;i<=parseInt(len)-1;i++)	{
				if(document.frmKitUpgrades.elements[i].name.substring(0,13) == "upgradehidden")
					totalvalue= totalvalue + parseFloat(getEnglishLocale(document.frmKitUpgrades.elements[i].value,sLocaleId));
				if(document.frmKitUpgrades.elements[i].name.substring(0,22) == "Add_Curr_upgradehidden")
					addTotalvalue= addTotalvalue + parseFloat(getEnglishLocale(document.frmKitUpgrades.elements[i].value,sLocaleId));									
					
			}
		}
		sKitValue=parseFloat(Sum)+ totalvalue;	
		sAddKitValue = parseFloat(addSum)+ addTotalvalue;	
		if(sKitValue < 0 || (sAdditionalCurrencySymbol != "" && sAddKitValue<0))
			alert(getMessage("iValidPriceComb"));
		document.frmKitAmt.txtTotalKitValue.value = sKitValue;
		setFormat("frmKitAmt.txtTotalKitValue");
				
		stempKitVal = document.frmKitAmt.txtTotalKitValue.value;
		document.frmKitAmt.txtTotalKitValue.value = getCurrentLocale(stempKitVal,sLocaleId);
		if (document.frmKitUpgrades) {
			if (document.frmKitUpgrades.txtTotalKitValue2) {
				document.frmKitUpgrades.txtTotalKitValue2.value = getCurrentLocale(stempKitVal,sLocaleId);
			}
		}
		if (document.frmBottKitPrice) {
			if (document.frmBottKitPrice.txtTotalKitValue2) {
				document.frmBottKitPrice.txtTotalKitValue2.value = getCurrentLocale(stempKitVal,sLocaleId);
			}
		}
		if (sAdditionalCurrencySymbol != "") {
			document.frmKitAmt.txtTotalKitValue_Add_Curr.value = sAddKitValue		
			setFormat("frmKitAmt.txtTotalKitValue_Add_Curr");
			stempAddKitVal = document.frmKitAmt.txtTotalKitValue_Add_Curr.value;
			document.frmKitAmt.txtTotalKitValue_Add_Curr.value = getCurrentLocale(stempAddKitVal,sLocaleId);
		}
	}
	// End of If Loop
}
// End of the function CalculateTotal()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function used to format the contents in the field.
//	@		                	If value is 100.0 , this funciton will change it to 100.00.
//	@	  Pages Affected  : CustomKitItems.asp
//  @		Function Name		: setFormat(field)									
//	@		Input Parameters: field = name of the form and fieldto be formatted
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function setFormat(field){
		var i, idiff,strval;
		var m_Field = eval("document." + field);
		m_Field.value = m_Field.value + "";
  	if(m_Field.value.indexOf(".") < 0)
			m_Field.value = m_Field.value + ".00";
		if(m_Field.value.length-m_Field.value.indexOf(".") == 2)
			m_Field.value = m_Field.value + "0";
		else if(m_Field.value.length-m_Field.value.indexOf(".") > 3){
			m_Field.value=m_Field.value.substring(0,m_Field.value.indexOf(".") +3)		
		}
	  idiff=10-m_Field.value.length	
		strval=""
		for(i=0;i< 10;i++)	{
			strval=strval+ " "  
			if (i==idiff-1){
				strval=strval+m_Field.value;
				break;
			}
		}
}// End of the function setFormat(field)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function is used to validate the quantity and submit the form.
//	@	  Pages Affected  : CustomKitItems.asp
//  @		Function Name		: CheckConfig(todo)									
//	@		Input Parameters: todo = action to be done, whether to add, or update a kit 
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function CheckConfig(todo){
	var retval,iKitqty,iTotalqty,iMaxCount;
	iKitqty=document.frmKitAmt.qty.value
	retval=IsNumeric(iKitqty)
	if(document.frmKitAmt.txtTotalKitValue.value < 0){
		alert(getMessage("iValidPriceComb"));
		return;
	}	
	if(retval == 1)	{
		alert(getMessage("iValidQuantity"));
		document.frmKitAmt.qty.value=1;
		document.frmKitAmt.qty.focus();
		return;
	}
	iKitqty = iKitqty*1
	if ((iMaxCount != "") && (bMaxItem.toLowerCase()=="true")){
		iTotalqty = parseInt(sCartItems)
		if(todo=="update")
			iTotalqty=iTotalqty - parseInt(iQty)
		if((iKitqty + iTotalqty)>parseInt(iMaxCount)){
			alert(getMessage("iTotalQtyExceed") + " " + iMaxCount);
			document.frmKitAmt.qty.value=1;
			document.frmKitAmt.qty.focus();
			return;
		}
	}
	document.frmKitInfo.qty.value = document.frmKitAmt.qty.value;
	document.frmKitInfo.configArr.value = configArr;
	document.frmKitInfo.todo.value = todo;
	document.frmKitInfo.submit();
}
// End of the function CheckConfig(todo)

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: Function IsNumeric checks whether the entered value is a 
//	@											numeric and greater than Zero.
//  @		Function Name		: IsNumeric(value)									
//	@		Input Parameters: value to be tested
//	@		Return Value		: 0 - Success	  1 - Failure			
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function IsNumeric(value){
	var validate=/(^\d+$)/
	if ((validate.test(value)) && (value > 0))
		return 0; 
	else
		return 1; 
}
// End of the function IsNumeric(value)
