function IsNumeric(strString)

 {

	 blnResult=true;

   if(isNaN(strString) || strString<=0 ||  ( parseInt(strString)!=strString ))

   {

   	blnResult = false;

   }

   	return blnResult;

}

function CheckMax(getval,maxval)

{

	//alert(getval);

	//alert(maxval);

	

	validdemand=true;

	if (getval > maxval){validdemand=false;}

	else{validdemand=true;}

	return validdemand;

}



function gtpage()

{

	document.printform.action='index.php';

	document.printform.submit();

}



function chkNumeric(strString)

   {

   var strValidChars = "0123456789.-";

   var strChar;

   var blnResult = true;



   if (strString.length == 0)

   	 return false;

   for (i = 0; i < strString.length && blnResult == true; i++)

      {

      strChar = strString.charAt(i);

      if (strValidChars.indexOf(strChar) == -1)

         {

         blnResult = false;

         }

      }

   return blnResult;

   }







function check_valid()

{
	

	var  totalrows= parseInt(document.printform.totalrows.value);

	var fieldchecked = false;
	

	//alert(totalrows);

	//multople Rows

	

	if (totalrows > 0)

	{

		for(var k=0;k<totalrows;k++)

		{

			if(document.getElementsByName('pid[]')[k].disabled==false)

			{

				if(document.getElementsByName('replaceqty[]')[k].value !='no' && document.getElementsByName('replaceqty[]')[k].value !='' )

				{

					if (chkNumeric(document.getElementsByName('replaceqty[]')[k].value)==false || document.getElementsByName('replaceqty[]')[k].value.indexOf('.')>=0)

					{

						alert("Please Enter a positive Integer value");

						document.getElementsByName('replaceqty[]')[k].value="";

						document.getElementsByName('replaceqty[]')[k].focus();

						return false;

					}

				}

				if(document.getElementsByName('refundqty[]')[k].value !='no' && document.getElementsByName('refundqty[]')[k].value !='' )

				{

					if (IsNumeric(document.getElementsByName('refundqty[]')[k].value)==false || document.getElementsByName('refundqty[]')[k].value.indexOf('.')>=0)

					{

						alert("Please Enter a positive Integer value");

						document.getElementsByName('refundqty[]')[k].value="";

						document.getElementsByName('refundqty[]')[k].focus();

						return false;

					}

				}

			//---------------------------------------------------------------------------

			//alert(document.getElementsByName('replaceqty[]')[k].value);

			//alert(document.getElementsByName('refundqty[]')[k].value);

			if (((document.getElementsByName('replaceqty[]')[k].value !='')&&(document.getElementsByName('replaceqty[]')[k].value !='no'))||((document.getElementsByName('refundqty[]')[k].value !='') && (document.getElementsByName('refundqty[]')[k].value !='no')))

			{

				if(document.getElementsByName('pid[]')[k].checked==false)

				{

					alert("Please Check The related Checkbox");

					document.getElementsByName('pid[]')[k].focus();

					return false;

				}

			}

			//-------------------------------------------------------------------------------

			if(document.getElementsByName('pid[]')[k].checked)

			{

				fieldchecked=true;

				//alert(k);

				if ((document.getElementsByName('replaceqty[]')[k].value =='' || document.getElementsByName('replaceqty[]')[k].value =='no') && (document.getElementsByName('refundqty[]')[k].value =='' ||document.getElementsByName('refundqty[]')[k].value =='no'))

				{

					

						alert("QTY can't be empty, Please insert some value \n or uncchek the box  if Nothing for Replace/Refund !! ");

						document.getElementsByName('replaceqty[]')[k].focus();

						return false;

					

				}
				var m = document.printform.remarks.value;
				m = m.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
				if(m == '') 
				{
				alert("Some information is missing below. All fields are mandatory.");
			
				document.printform.remarks.focus();	
			
				return false;
				}

			}

			

			//--------------------------------------------------------------------------------------

			if  (document.getElementsByName('replaceqty[]')[k].value != '' || document.getElementsByName('refundqty[]')[k].value != '')

				{

						if(document.getElementsByName('replaceqty[]')[k].value == '' || document.getElementsByName('replaceqty[]')[k].value=='no' ){rplqty=0;}

						else{rplqty=parseInt(document.getElementsByName('replaceqty[]')[k].value);}

						if(document.getElementsByName('refundqty[]')[k].value == '' || document.getElementsByName('refundqty[]')[k].value=='no'){rfndqty=0;}

						else{rfndqty=parseInt(document.getElementsByName('refundqty[]')[k].value);}

						askedqty=parseInt(rplqty+rfndqty);

						//----------------------------------------------------

					

						if (CheckMax(askedqty,document.getElementsByName('totalqty[]')[k].value)==false)

						{

							alert("Cant Ask more than you have!!");

							if(document.getElementsByName('replaceqty[]')[k].value !='no' )

							{

								document.getElementsByName('replaceqty[]')[k].focus();

								return false;

							}

							if(document.getElementsByName('refundqty[]')[k].value !='no' )

							{

								document.getElementsByName('refundqty[]')[k].focus();

								return false;

							}

							return false;

						}

				}

			//-------------------------------------------------------------

							

			}//checkbox not disabled

		}//forloop

			

		}//Multiple Condition ends

	

	if (fieldchecked == false){alert('You must check at least one item');return false;}



	//return false;

	if(document.printform.asprev.checked==false)

	{

			if(document.printform.s_name.value=='')

			{

				alert("please Enter your shipname or check the box as previous!!");

				document.printform.s_name.focus();

				return false;

			}

			 var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

			  for (var i = 0; i < document.printform.s_name.value.length; i++) 

			  {

				if (iChars.indexOf(document.printform.s_name.value.charAt(i)) != -1) 

				{

					alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");

					document.printform.s_name.value = "";

					document.printform.s_name.focus();

					return false;

				}

			  }

			if(document.printform.s_address.value=='')

			{

				alert("Please Enter your ShipAddrress or check the box as previous!!");

				document.printform.s_address.focus();

				return false;

				

			}

			 var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

			  for (var i = 0; i < document.printform.s_address.value.length; i++) 

			  {

				if (iChars.indexOf(document.printform.s_address.value.charAt(i)) != -1) 

				{

					alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");

					document.printform.s_address.value = "";

					document.printform.s_address.focus();

					return false;

				}

			  }

			if(document.printform.country.value=='')

			{

				alert("Please select  your Shipcountry or check the box as previous!!");

				document.printform.country.focus();

				return false;

			}			

			if(document.printform.s_state.value=='')

			{

				alert("Please Enter your ShipState or check the box as previous!!")

				document.printform.s_state.focus();

				return false;

			}

			if(document.printform.s_city.value=='')

			{

				alert("Please Enter your ShipCity or check the box as previous!!")

				document.printform.s_city.focus();

				return false;

			}

			if(document.printform.s_zip.value=='')

			{

				alert("Please Enter your ShipZip or check the box as previous!!")

				document.printform.s_zip.focus();

				return false;

			}
			

			 var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

			  for (var i = 0; i < document.printform.s_zip.value.length; i++) 

			  {

				if (iChars.indexOf(document.printform.s_zip.value.charAt(i)) != -1) 

				{

					alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");

					document.printform.s_zip.value = "";

					document.printform.s_zip.focus();

					return false;

				}

			  }



		

		

	}

}







function gtpage()

{

	document.printform.action='index.php';

	document.printform.submit();

}



function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}

//-->

function showstate()
{

	document.getElementById('Stateid').innerHTML="";



if(document.printform.country.value =="UNITED STATES")

	{



		var option;

		option="";

		strstates="Select State,Alabama,Alaska,American Samoa,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District Of Columbia,Federated States OF Micronesia,Florida,Georgia,Guam,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisana,Maine,Marshall Islands,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Northern Mariana Islands,Ohio,Oklahoma,Oregon,Palau,Pennsylvania,Puerto Rico,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virgin Islands,Virginia,Washington,West Virginia,Wisconsin,Wyoming,AA,AE,AP";

		arrstateval=" ,AL,AK,AS,AZ,AR,CA,CO,CT,DE,DC,FM,FL,GA,GU,HI,ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA,PR,RI,SC,SD,TN,TX,UT,VT,VI,VA,WA,WV,WI,WY,AA,AE,AP";

		arrstates=strstates.split(",");

		arrstateval=arrstateval.split(",");

	

	for ( i = 0; i <=62; i++ )

	{

		

		if (option=="")

		{

			option="<option value="+ arrstateval[0]+">"+arrstates[0]+"</option>";

		}

		else

		{

		option=option+"<option value='"+arrstateval[i]+"'>"+arrstates[i]+"</option>";

		}	

	}



	innertable="<select name='s_state' id='s_state' class='txtfield'>"+option+"</select>";

	

}



else

{

	innertable="<input name='s_state' type='text' id='s_state' class='form-contact'>";



}

	if(document.printform.country.value =="")

	{

		innertable="<input name='s_state' type='text' id='s_state' class='form-contact'>";

	}

	document.getElementById('Stateid').innerHTML=innertable;

}



function unitedstate(ship_country)

{

	//alert(ship_country);

var count="";

var country=str;

var option;

option="";

country=str.split(",");

	var selbox,k;

	selbox= document.printform.country;

	selbox.options.length =null;

    selbox.options[0] = new Option("Select Country","");

	

	for(k=1; k<country.length;k++)

	{

		if(ship_country==country[k-1])

		{

			count=k;

		}

		selbox.options[selbox.options.length] = new Option(country[k-1],country[k-1]);

		

	}

	

	selbox.options[count].selected=true;

	//alert(count);

	

	

}





function sameasprev()

{

		if(document.printform.asprev.checked==false)

		{

			document.printform.s_name.readOnly=false;

			document.printform.s_address.readOnly=false;

			document.printform.country.disabled=false;

			document.printform.s_state.readOnly=false;

			document.printform.s_city.readOnly=false;

			document.printform.s_zip.readOnly=false;

			

		}

		if(document.printform.asprev.checked)

		{

			unitedstate(document.printform.ship_country.value);

			document.printform.s_name.value=document.printform.ship_name.value;

			document.printform.s_address.value=document.printform.ship_address.value;

			document.printform.s_state.value=document.printform.ship_state.value;

			document.printform.s_city.value=document.printform.ship_city.value;

			document.printform.s_zip.value=document.printform.ship_zip.value;

			

			

			

			document.printform.s_name.readOnly=true;

			document.printform.s_address.readOnly=true;

			document.printform.country.disabled=true;

			document.printform.s_state.readOnly=true;

			document.printform.s_city.readOnly=true;

			document.printform.s_zip.readOnly=true;

			

		}

	

}



function billing()

{



if (document.printform.name.value=="")

  	{

   		alert("Please enter Your Name.");

    	document.printform.name.focus();

    	return (false);

  }

  

 if (document.frm_billing.bill_street.value=="")

  {

   alert("Please enter Your Address.");

    document.frm_billing.bill_street.focus();

    return (false);

  }

  if (document.frm_billing.bill_country.value == "")

  {

    alert("Please Select your Country.");

    document.frm_billing.bill_country.focus();

    return (false);

  }

   if(document.getElementById('s_state').value=="")

   {

   alert("Please Select your state.");

  document.getElementById('s_state').focus();

    return (false);

   }

   else

   	{

		document.frm_billing.bill_state.value=document.getElementById('s_state').value;

	}

	if (document.frm_billing.bill_city.value=="")

  	{

	   	alert("Please enter Your City.");

    document.frm_billing.bill_city.focus();

    return (false);

  	}

  if (document.frm_billing.bill_zip.value=="")

  {

   alert("Please enter Your Zip.");

    document.frm_billing.bill_zip.focus();

    return (false);

  }

document.frm_billing.phone.value= document.frm_billing.countrycode.value+'-'+ document.frm_billing.areacode.value+'-'+ document.frm_billing.phno.value;



}

var str='UNITED STATES,ARGENTINA,AUSTRALIA,AUSTRIA,BELGIUM,BULGARIA,CANADA,CHINA,COSTA RICA,CZECH REPUBLIC,DENMARK,FIJI,FINLAND,FRANCE,GERMANY,GREECE,HONG KONG,HUNGARY,INDIA,IRELAND,ISREAL,ITALY,JAPAN,JORDAN,KUWAIT,LUXEMBOURG,MEXICO,NETHERLANDS,NEW ZEALAND,PANAMA,POLAND,PORTUGAL,PUERTO RICO,QATAR,ROMANIA,SAUDI ARABIA,SINGAPORE,SPAIN,SWEDEN,SWITZERLAND,UNITED ARAB EMIRATES,UNITED KINGDOM,YUGOSLAVIA,'


