﻿function test1_Add()
{
	checker();
	var CurrentBixesCnt;
	CurrentBixesCnt=parseInt(document.express.t1.value);

	document.express.t1.value=parseInt(document.express.t1.value)+parseInt(5);
	j=parseInt(document.express.t1.value);
	if (j=="" || j=="0" ){j=9;document.express.t1.value=9;}
	if(j>999)
	{ 
	alert("You can add upto 999 items at a time") 
	//j=0
	return true;
	
	}
	var x = new String();
	//x="<table align='center'  border=0 width='300' valign='top'><tr><td  align=right width='60' >&nbsp;</td><td class='rpan-table-color' align=center width=69><b>Sno</b></td><td class='rpan-table-color' align=center width=94> <b>Item no</b> </td><td class='rpan-table-color' align=center width='67' >&nbsp;<b>Quantity</b></td></tr>";
	x="<table align='center'  border=0 width='300' valign='top'>";
	for(i=CurrentBixesCnt+1;i<=j;i++)
	{ 
	x=x +  " <tr><td align=right width='60'> </td><td align=center width=69>&nbsp;"+ i + " </td><td align=center width=94><input type = text maxlength=6 size=15 name=prod  ></input></td><td align=center width='67'><input type = text value=1 maxlength = 3 size=5 name=qty onBlur=addcheck(this) ></input><input type = hidden name=hid></input></td></tr>";
	
	}

	var y = new String();
	y=document.getElementById("san1").innerHTML;
	document.getElementById("san1").innerHTML  = y + "  "+ x + "</table>"
	checker1();
}

function addcheck(x)
{
	var st1 = "qty"+(document.express.t1.value-1);
	var st2 = x.name;

	if(st1==st2)
	{
		test1_Add();
	}


}
function test2_Remove()
{
	j=document.express.t1.value;
	if(j==9)
	{
		alert("You cant remove items");
		return true;
	}

	if(parseInt(document.express.t1.value)>9)
	{document.express.t1.value=parseInt(document.express.t1.value)-parseInt(5);}
	
	j=parseInt(document.express.t1.value);
	if (j=="" || j=="0" ){j=9;document.express.t1.value=9;}
	
	
	var x= new String();
	x="<table align='center'  border=0 width='300' valign='top'><tr><td  align=right width='60' >&nbsp;</td><td class='rpan-table-color' align=center width=69><b>Sno</b></td><td class='rpan-table-color' align=center width=94> <b>Item no</b> </td><td class='rpan-table-color' align='center' width='67' >&nbsp;<b>Quantity</b></td></tr>";
	//x="<table align='center'  border=0 width='300' valign='top'>";
	for(i=1;i<=j;i++)
	{
	//x=x +  " <tr><td>&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;"+ i + " </td><td ><input type = text maxlength=6 size=15 name=" + i +  "   ></input></td><td ><input type = text value=1  size=5 name=qty" + i + " onBlur=addcheck(); ></input></td></tr>";
	x=x +  " <tr><td align=right width='60'> </td><td align=center width=69>&nbsp;"+ i + " </td><td align=center width=94><input type = text maxlength=6 size=15 name=" + i +  "   ></input></td><td align=center width='67'><input type = text value=1  size=2 name=qty" + i + " onBlur=addcheck(this) ></input></td></tr>";
	
	}
	document.getElementById("san1").innerHTML  = x;
}

function test_DefaultDisplay()
{
	j=Trim(document.express.t1.value);
	if (j=="" || j=="0" ){j=9;document.express.t1.value=9;}
	
	if(j>999)
	{
	alert("You can add upto 999 items at a time") 
	//j=0
	return true;
	}
	var x= new String();
	x="<table align='center'  border=0 width='300' valign='top'><tr ><td  align=right width='60' >&nbsp;</td><td  align=center width=69 class='rpan-table-color'><b>Sno</b></td><td class='rpan-table-color' align=center width=94> <b>Item no</b> </td><td class='rpan-table-color' align=center width='67' >&nbsp;<b>Quantity</b></td></tr>";
	for(i=1;i<=j;i++)
	{
	  x=x +  " <tr><td align=right width='60'> </td><td align=center width=69>&nbsp;"+ i + " </td><td align=center width=94><input type = text maxlength=6 size=15 name=prod   ></input></td><td align=center width='67'><input type = text value=1  maxlength=3 size=5 name=qty onBlur=addcheck(this) ></input></input><input type = hidden name=hid></input></td></tr>";
	//x=x +  " <tr><td>&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ i + " </td><td ><input type = text maxlength=6 size=15 name=" + i +  "   ></input></td><td ><input type = text value=1  size=5 name=qty" + i + " onBlur=addcheck(this)></input></td></tr>";

	}
	document.getElementById("san1").innerHTML  = x + "<table>"; //"<tr><td>&nbsp;<td><td align='center'><a href='javascript:submitpg();'> <img src='/images/addtocart.gif' border='0'> </a></td><td align='center'><input type=reset value=' Reset '  name=reset1></input></td></tr></table>";

	
}


function check()
{
var k;
var r=1;
len=0;
/*
brow = navigator.userAgent.toLowerCase();

if(brow.substr(0,11)=="mozilla/5.0")
{
	alert('moz');
	var r=2;
}
else
{
	var r=1;
}

*/
//alert(document.getElementById("san1").innerHTML);
//alert(document.express.length);
l=Trim(document.express.t1.value);



for ( k=0;k<l;k++)
{

	//alert(document.express[r].value.length);
	//alert(document.express[r].name);
	//alert(document.express.prod[k].value);
	len=len + document.express.prod[k].value.length;
	r=r+2;
}

//alert(len);
if(len==0)
{
alert("Please Enter atleast one item no1"); 
//document.express.prod[k].focus();
return(false);
}

//r=1;


for ( k=0;k<l;k++)
{

	if(isNaN(Trim(document.express.prod[k].value)))
	{
	//alert(document.express[r].value);
	alert("Please Enter atleast one item no2 ");
	document.express.prod[k].focus();
	return(false);
	}
	else if (isNaN(Trim(document.express.qty[k].value) ))
	{
	alert("Please Enter atleast one item no3 ");
	document.express.qty[k].focus();
	return(false);
	}
	else if (Trim(document.express.qty[k].value)<=0)
	{
	alert("Please Enter quantity greater than 0 ");
	document.express.qty[k].focus();
	return(false);
	}
	else if((document.express.qty[k].value)>999)
	{
	alert("You can add upto 999 items at a time");
	return(false);
	}
	
}
return true;
} 

function test_reset()
{
	//window.location.reload();
	location.href="Expressorder.asp";
}

function submitpg()
{
if  (check()==true)
	{
	document.express.submit();
	}
}


function checker()
{
		var val;
		probj = document.getElementsByName("prod");
		hidobj = document.getElementsByName("hid");
		for(j=0; j<probj.length; j++)
		{
			hidobj[j].value = probj[j].value;
		}
		//probj[3].value="vijay";
		
		//for(i=0;i<hidobj.length;i++)
		//alert(hidobj[i].value);
}		

function checker1()
{
	var m=0;
	probj = document.getElementsByName("prod");
	hidobj = document.getElementsByName("hid");
	m = document.express.t1.value;
	for(j=0; j<probj.length; j++)
	{
		probj[j].value = hidobj[j].value;
	}
/*	
	for(t=(m-5); t<=m; t++)
	{
		probj[t].value=0;
	}
*/
}
/*
function sub1()
{
	probj = document.getElementsByName("prod");
	for(i=1; i<=probj.length; i++)
	{
		if(probj[i].value == "")
		{
			probj[i].value = 0;
		}
	}
	return true;
	
}

*/
