function CurrencyFormatted(amount)
{
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}

function selectQty(theForm){
fieldchecked=false;
for(k=0; k<(document.form1.purchaseqty.length); k++)
{
	if (document.getElementById("show"+(k+1))==null)
	{	
		if (document.form1.purchaseqty[k].value != "Qty")
		{
			if ((document.form1.purchaseqty[k].value) != "" )	
			{
				if(isNaN(document.form1.purchaseqty[k].value) || document.form1.purchaseqty[k].value<=0)
				{ 
					alert("Please enter a Positive Integer Value!!");
					document.form1.purchaseqty[k].value ="";
					document.form1.purchaseqty[k].focus();
					//return(false);
				}
				if((document.form1.purchaseqty[k].value).indexOf('.')>=0)
				{
					alert("Please enter a Positive Integer Value!!");
					document.form1.purchaseqty[k].value ="";
					document.form1.purchaseqty[k].focus();
					//return(false);
				}
				fieldchecked=true;
			}
		}
	}
	else
	{	
		if (document.form1.purchaseqty[k].value != "Qty")
		{		
			if((document.form1.purchaseqty[k].value != "") && (document.form1.purchaseModel[k].value != ""))
			{				
				fieldchecked=true;
				if(isNaN(document.form1.purchaseqty[k].value) || document.form1.purchaseqty[k].value<=0)
				{ 
					alert("Please enter a Positive Integer Value!!");
					document.form1.purchaseqty[k].value ="";
					document.form1.purchaseqty[k].focus();
					//return(false);	
				}	
				if((document.form1.purchaseqty[k].value).indexOf('.')>=0)
				{
					alert("Please enter a Positive Integer Value!!");
					document.form1.purchaseqty[k].value ="";
					document.form1.purchaseqty[k].focus();
					//return(false);
				}   	
			}	
			if((document.form1.purchaseModel[k].value == "") && (document.form1.purchaseqty[k].value != "Qty") && (document.form1.purchaseqty[k].value != ""))
			{				
				alert("Please Select Model !!");
				document.form1.purchaseModel[k].focus();
				//return(false);
			}
			if (document.form1.avail_model)
			{
				if((document.form1.avail_model[k].value == "") && (document.form1.purchaseqty[k].value != "Qty") && (document.form1.purchaseqty[k].value != ""))
				{				
					alert("Please Select Model !!");
					document.form1.avail_model[k].focus();
					//return(false);
				}
			}
		}
	}
}
if (fieldchecked == false)
{
	alert('You must enter at least one item');
	document.form1.purchaseqty[0].value=""; 
	document.form1.purchaseqty[0].focus(); 
	//return(false);
}
}
function submitByScroll()
{
fieldchecked=false;
for(k=0; k<(document.form1.purchaseqty.length); k++)
{
if (document.getElementById("show"+(k+1))==null)
{	
if (document.form1.purchaseqty[k].value != "Qty")
{
if ((document.form1.purchaseqty[k].value) != "" )
{
if(isNaN(document.form1.purchaseqty[k].value) || document.form1.purchaseqty[k].value<=0)
{ 
alert("Please enter a Positive Integer Value!!");
document.form1.purchaseqty[k].value ="";
document.form1.purchaseqty[k].focus();
return(false);
}

if((document.form1.purchaseqty[k].value).indexOf('.')>=0)
{
alert("Please enter a Positive Integer Value!!");
document.form1.purchaseqty[k].value ="";
document.form1.purchaseqty[k].focus();
return(false);
}
fieldchecked=true;
}
}
}
else
{	
if (document.form1.purchaseqty[k].value != "Qty")
{		
if((document.form1.purchaseqty[k].value != "") && (document.form1.purchaseModel[k].value != "")){				
fieldchecked=true;
if(isNaN(document.form1.purchaseqty[k].value) || document.form1.purchaseqty[k].value<=0){ 
alert("Please enter a Positive Integer Value!!");
document.form1.purchaseqty[k].value ="";
document.form1.purchaseqty[k].focus();
return(false);	
}	
if((document.form1.purchaseqty[k].value).indexOf('.')>=0){
alert("Please enter a Positive Integer Value!!");
document.form1.purchaseqty[k].value ="";
document.form1.purchaseqty[k].focus();
return(false);}   	
}	
if((document.form1.purchaseModel[k].value == "") && (document.form1.purchaseqty[k].value != "Qty") && (document.form1.purchaseqty[k].value != ""))
{				
alert("Please Select Model !!");
document.form1.purchaseModel[k].focus();
return(false);
}
}
}
}
if (fieldchecked == false){
alert('You must enter at least one item');
document.form1.purchaseqty[0].value=""; 
document.form1.purchaseqty[0].focus(); 
return(false);
}
document.form1.submit();
}
function showPdetail(selvalue,id)
{
if (selvalue!= "")
{
var arrvalue = selvalue.split("#");
document.form1.purchaseModel[id].value = arrvalue[0];
document.form1.ProductID[id].value = arrvalue[1];

}
}

function showRelateddetail(selvalue,id)
{
if (selvalue!= "")
{
var arrvalue = selvalue.split("#");
document.getElementById("sku"+id).innerHTML= arrvalue[2];
document.getElementById("show"+id).innerHTML="List Price: $<s>"+arrvalue[1]+"</s><br><strong><font color='#990000'>Sale Price: $"+CurrencyFormatted(parseFloat(arrvalue[1])-parseFloat(arrvalue[1]*0.10))+"</font></strong>";			

}
else
{
var price = document.form1.RealPrice[id-1].value;
document.getElementById("sku"+id).innerHTML= document.form1.purchaseSKU[id-1].value;
document.getElementById("show"+id).innerHTML= "List Price: $<s>"+price+"</s><br><strong><font color='#990000'>Sale Price: $"+CurrencyFormatted(parseFloat(price)-parseFloat(price*0.10))+"</font></strong>";						
}	
}


function check_return(form1)
{
if (document.form.modi_qty.length) {
var j = (document.form.modi_qty.length);
for(k=0; k<j; k++)
{
if ((document.form.modi_qty[k].value) == "" ){
alert("Please enter a Positive Integer Value!!");
document.form.modi_qty[k].focus();
return(false);}
if(isNaN(document.form.modi_qty[k].value) || document.form.modi_qty[k].value<=0){ 
alert("Please enter a Positive Integer Value!!");
document.form.modi_qty[k].focus();
return(false);}
if((document.form.modi_qty[k].value).indexOf('.')>=0)
{ 
alert("Please enter a Positive Integer Value!!");
document.form.modi_qty[k].focus();
return(false);
}
if (document.form.modi_qty[k].value > 0){	
if ((document.form.modi_qty[k].value) != (document.form.myqty[k].value))
{
document.form.Billing.value="Update My Cart";
document.form.update.value="YES";
document.form.action="XMLupdate.asp";
document.form.submit();
}		
}
}
}
else
{
if ((document.form.modi_qty.value) == "" ){
alert("Please enter a Positive Integer Value!!");
document.form.modi_qty.focus();
return(false);}
if(isNaN(document.form.modi_qty.value) || document.form.modi_qty.value<=0){ 
alert("Please enter a Positive Integer Value!!");
document.form.modi_qty.focus();
return(false);}
if((document.form.modi_qty.value).indexOf('.')>=0)
{ 
alert("Please enter a Positive Integer Value!!");
document.form.modi_qty.focus();
return(false);
}
if (document.form.modi_qty.value > 0){	
if ((document.form.modi_qty.value) != (document.form.myqty.value))
{
document.form.Billing.value="Update My Cart";
document.form.update.value="YES";
document.form.action="XMLupdate.asp";
document.form.submit();
}		
}
}
return true;	
}
function UpdateCart()
{
	var totqty=0;
	var Total = 0;
	var netamount = 0;
	if (document.form.modi_qty.length)
	{
		var j = (document.form.modi_qty.length);
		for(k=0; k< j; k++)
		{
			if(isNaN(document.form.modi_qty[k].value) || document.form.modi_qty[k].value<=0)
			{
				alert("Please enter a Positive Integer Value!!");
				document.form.modi_qty[k].style.background="#000000";
				document.form.modi_qty[k].style.color="#ffffff";
				document.form.modi_qty[k].focus();
				return(false);
			}
			if((document.form.modi_qty[k].value).indexOf('.')>=0)
			{
				alert("Please enter a Positive Integer Value!!");
				document.form.modi_qty[k].style.background="#000000";
				document.form.modi_qty[k].style.color="#ffffff";
				document.form.modi_qty[k].focus();
				return(false);
			}
			if(parseInt(document.form.modi_qty[k].value/1) == document.form.modi_qty[k].value)
			{
				document.form.modi_qty[k].style.background="#ffffff";
				document.form.modi_qty[k].style.color="#000000";
				Total=CurrencyFormatted(parseFloat(document.form.updateprice[k].value) * parseInt(document.form.modi_qty[k].value/1));
				document.getElementById("total"+(k+1)).innerHTML="<strong>$"+Total+"</strong>";
			}
			netamount = parseFloat(netamount) + (parseFloat(document.form.updateprice[k].value) * parseInt(document.form.modi_qty[k].value/1));
			totqty = parseInt(totqty)+parseInt(document.form.modi_qty[k].value/1);
		}
		document.form.Billing.value="Update My Cart";
		document.form.update.value="YES";
		document.form.action="XMLupdate.asp";
		document.getElementById("tqty").innerHTML="<strong id='meroon'>"+totqty+"</strong>";
		document.getElementById("nettotal").innerHTML="<strong id='meroon'>$"+CurrencyFormatted(netamount)+"</strong>";
	}
	else
	{
		if(isNaN(document.form.modi_qty.value) || document.form.modi_qty.value<=0)
		{
			alert("Please enter a Positive Integer Value!!");
			document.form.modi_qty.style.background="#000000";
			document.form.modi_qty.style.color="#ffffff";
			document.form.modi_qty.focus();return(false);
		}
		if((document.form.modi_qty.value).indexOf('.')>=0)
		{
			alert("Please enter a Positive Integer Value!!");
			document.form.modi_qty.style.background="#000000";
			document.form.modi_qty.style.color="#ffffff";
			document.form.modi_qty.focus();
			return(false);
		}
		if(parseInt(document.form.modi_qty.value/1) == document.form.modi_qty.value)
		{
			document.form.modi_qty.style.background="#ffffff";
			document.form.modi_qty.style.color="#000000";
			Total=CurrencyFormatted(parseFloat(document.form.updateprice.value) * parseInt(document.form.modi_qty.value/1));
			document.getElementById("total1").innerHTML="<strong>$"+Total+"</strong>";
		}
		netamount = parseFloat(netamount) + (parseFloat(document.form.updateprice.value) * parseInt(document.form.modi_qty.value/1));
		totqty = parseInt(totqty)+parseInt(document.form.modi_qty.value/1);	
		document.form.Billing.value="Update My Cart";
		document.form.update.value="YES";
		document.form.action="XMLupdate.asp";
		document.getElementById("tqty").innerHTML="<strong id='meroon'>"+totqty+"</strong>";
		document.getElementById("nettotal").innerHTML="<strong id='meroon'>$"+CurrencyFormatted(netamount)+"</strong>";
	}
}
function removeItem(productId) 
{
if (document.form.related) 
{ var cnf = confirm("Your Related Product will be remove."); }
else
{ var cnf = confirm("Are You Sure You Want Remove This Product."); }
if (cnf)
{
if (check_return('form'))
{	
document.form.action = "XMLupdate.asp";
document.form.RemproductId.value = productId;
document.form.remove.value = "YES";
document.form.submit();
}
else
{ return false; }	

}
else
{
return false;
}
}
function removeRelatedItem(productId) 
{
var cnf = confirm("Are You Sure You Want Remove This Product.");
if (cnf)
{
if (check_return('form'))
{
document.form.action = "XMLupdate.asp";
document.form.RelatedproductId.value = productId;
document.form.remove.value = "YES";
document.form.submit();
}
else
{ return false; }	
}
else
{
return false;
}
}
function topselles(page,sku_no)
{
document.frm_gotopage.method="POST";
document.frm_gotopage.action=page;
document.frm_gotopage.sku_no.value=sku_no;
document.frm_gotopage.submit();
}

function gotohtmpage(model,category)
{
	if (category=="")
	{
		window.open(model+".htm",'_self');
	}
	else if (model=="" && category != "")
	{
		window.open('ipod-'+category+".htm",'_self');
	}
	else if (model!="" && category != "")
	{
		window.open(model+"-"+category+".htm",'_self');
	}
	else
	{
		window.open("accessories.asp",'_self');
	}
}
function gotopaging(first,total)
{
	var totalpage,firstpaging
	totalpage=parseInt(total);
	firstpaging=parseInt(first);
	if(document.form1.pageno.value=="")
	{
		alert("please insert integer value into text box");
		document.form1.pageno.focus();
		return (false);
	}
	 if (isNaN(document.form1.pageno.value))
	 {
		 alert("please insert integer value ");
		 document.form1.pageno.focus();
		 return (false);
	 }
	  if(parseInt(document.form1.pageno.value)!=document.form1.pageno.value)
	 {
		 alert("please insert only integer value");
		 document.form1.pageno.focus();
		 return(false);
	 }
	 
	 if(document.form1.pageno.value > totalpage)
	 {
		 alert("please insert valid range into text box");
		 document.form1.pageno.focus();
		 return (false);
	 }
	 if(document.form1.pageno.value < 1 )
	 {
		 alert("please insert valid range into text box");
		 document.form1.pageno.focus();
		 return (false);
	 }
	 document.frmstyle.page.value=firstpaging;
	 document.frmstyle.propage.value=document.form1.pageno.value;
	 document.frmstyle.srctext.value=document.form1.srctext.value;
     document.frmstyle.submit();
}
