/*************************************/
		function CutOff(strValue)
			{
				var ResultString="";
				var InitLength=strValue.length;
				//var trimLeft=false;

				if (InitLength!=0)
					{
					//Left Portion
					for (j=0; j<InitLength; j++)
							{
							tmpChar=strValue.charAt(j);
							if (tmpChar!=' ')
								{
								//ResultString=strValue.substring(j, InitLength-1)
								ResultString=strValue.substring(j)
								break;
								}
							}	
							
					//Right Portion
					
					if (ResultString.length!=0)
						{
						var tmpIndex=ResultString.indexOf(' ')
						if (tmpIndex > -1)
							{
							ResultString=ResultString.substring(0,tmpIndex)
							} 
						}	
					}	
				return ResultString;		
			}
		/*************************************/

	//*********************************************************
	
	
	function Email(formName, textName){
		
		var CheckControl=document.forms[formName].elements[textName]
		var CheckResult;
	
		
		var tmpValue=CutOff(CheckControl.value)
		if ((tmpValue.length!=0) && (tmpValue.indexOf('@') >0))
			{
				for (i=0; i<tmpValue.length; i++) 
					{
					tmpChar=tmpValue.charAt(i)
					if (((tmpChar>='A') && (tmpChar<='Z')) || 
						((tmpChar>='a') && (tmpChar<='z')) ||
						((tmpChar>='0') && (tmpChar<='9')) ||
						((( tmpChar=='.' ) || ( tmpChar=='_' ) || ( tmpChar=='-' ))
							&& ( i!=0)  && (  i!=(tmpValue.length-1))))		 
						{
						CheckResult=true;
						}
					else if	((tmpChar=='@') && 
							(i!=0)  && (i!=(tmpValue.length-1)) && 
							(tmpValue.lastIndexOf('@')==i) &&
							(tmpValue.lastIndexOf('.')>(i+1)))
						{
						CheckResult=true;
						}
					else
						{
						CheckResult=false;
						break
						}			
									
					}
			}
		else
			{
			CheckResult=false
			}
		
		//Final Step
		if (CheckResult)
			{
			CheckControl.value=tmpValue;
			}
		//else
		//	{
			//alert(errMsg);
		//	CheckControl.focus()
		//	}
		return CheckResult;
	}


function validateNumber(obj) {
	var myButton = window.event.keyCode ;
	if (myButton >= 48 && myButton <= 57) {
		return true; }
	else {
		return false;
	}
	
}
var empty = new Image(); empty.src = "../images/fieldempty.gif";
var email = new Image(); email.src = "../images/emailerror.gif";
var phone = new Image(); phone.src = "../images/phoneerror.gif";
var i=0

var haveerrors = 0;
function showImage(imagename, imageurl, errors) {
document[imagename].src = imageurl;
if (!haveerrors && errors) haveerrors = errors;
}
var i=0
function validateForm(form,argSession) {
haveerrors = 0;
(form.txtFName.value.length < 1) // validate first name length
? showImage("FNameError", "../images/fieldempty.gif", true)   // no semi-colon after this line!
: showImage("FNameError", "../images/blankimage.gif", false); // true = errors, false = no errors

(form.txtLName.value.length < 1) // validate last name length
? showImage("LNameError", "../images/fieldempty.gif", true)
: showImage("LNameError", "../images/blankimage.gif", false);
Phonelength = form.txtDPhoneA.value.length + 
form.txtDPhoneT.value.length + form.txtDPhoneF.value.length;
(Phonelength  !=10) // validate last name length
? showImage("PhoneError", "../images/fieldempty.gif", true)
: showImage("PhoneError", "../images/blankimage.gif", false);


if(Number(argSession)==0){
	
	(!Email('frmRegister','txtScrName')) // validate email	
	? showImage("ScrNameError", "../images/emailerror.gif", true)
	: showImage("ScrNameError", "../images/blankimage.gif", false);

	(form.txtPWD.value.length < 1) // validate email	
	? showImage("PWDNameError", "../images/fieldempty.gif", true)
	: showImage("PWDNameError", "../images/blankimage.gif", false);

}
if (haveerrors==0){return true;
}else{return false;
 }}

			




function ReloadMe()
		{
			aStr=document.frmProceed.selShipMethod.name + '=' + document.frmProceed.selShipMethod.value
			alert(aStr) 
			aStr+='&optBilling='+document.frmProceed.ThisBillAddressID.value
			aStr+='&optShipping='+document.frmProceed.ThisShipAddressID.value
			 
			NewStr=self.location.pathname + '?' + aStr
			
			self.location=NewStr
				
		}


function Reset(){
	document.forms[0].reset();
	return false;
 }
 
 
 
 function check_data(){	
				
				var check = false;
				var Billing = document.frmGotoOrder.optBilling;
				
				var Shipping = document.frmGotoOrder.optShipping;
				//var ShipMethod = document.frmGotoOrder.selShipMethod.selectedIndex;
								
				if(Billing.checked){
				   check = true;}
				for (i=0;i<Billing.length;i++){				
					if (Billing[i].checked){
						check = true;
						break;
					}
				}
				if(!check){
					alert("You have to Select Billing Address");
					return false;
				}
				
				check=false;
				if(Shipping.checked){
				   check = true;}
				for (j=0;j<Shipping.length;j++){
					if (Shipping[j].checked){
						check = true;
						break
					}
				}
				if(!check){
					alert("You have to Select Shipping Address");
					return false;
				}
				 
				// if (ShipMethod == 0){
				//	alert("Please choose the Shipping Method!");
				//	document.forms[0].selShipMethod.focus();
				//	return false;
				//	}
				
			}
			function new_window(TmpWin){
				TmpWindow = window.open(TmpWin,'','toolbox=no','')
			}
				