function changeCustType()
{
	var SelectedCustomerType= document.frmRegistration.customertype.value;
	
	var numberOfAllDivs = document.getElementsByTagName('div').length;
	if(SelectedCustomerType ==1 )
	{
		for(var counter=0; counter < numberOfAllDivs; counter++)
		{
			var currentDiv = document.getElementsByTagName('div')[counter];
			if(currentDiv.id == 'divrep')
			currentDiv.style.display = 'inline';
			if(currentDiv.id == 'divwholesale')
			currentDiv.style.display = 'none';
			
		}
	}
	if(SelectedCustomerType ==2 )
	{
		for(var counter=0; counter < numberOfAllDivs; counter++)
		{
			
			var currentDiv = document.getElementsByTagName('div')[counter];
			if(currentDiv.id == 'divwholesale')
			currentDiv.style.display = 'inline';
			if(currentDiv.id == 'divrep')
			currentDiv.style.display = 'none';
			
		}
	}	
//document.forms["frmRegistration"].action = "register.php";		
	//document.forms["frmRegistration"].submit();
}
	
function isValidUserName(str)
{
	var a=0;
	while(a<str.length)
	{
		if(!(( str.charAt(a) >= '0' && str.charAt(a) <= '9' ) || ( str.charAt(a) >= 'A' && str.charAt(a) <= 'Z' ) || ( str.charAt(a) >= 'a' && str.charAt(a) <= 'z' ) || str.charAt(a) == '_' ))
			return false;
		a++;
	}
	return true;
}

function CheckEmailSpecialCharacter(str)
{
	var a=0;
	while(a<str.length)
	{
		if(!(( str.charAt(a) >= '0' && str.charAt(a) <= '9' ) || ( str.charAt(a) >= 'A' && str.charAt(a) <= 'Z' ) || ( str.charAt(a) >= 'a' && str.charAt(a) <= 'z' ) || str.charAt(a) == '.' || str.charAt(a) == '@' || str.charAt(a) == '_' ))
			return false;
		a++;
	}
	return true;
}

function isValidName(str)
{
	var a=0;
	while(a<str.length)
	{
		if(!(( str.charAt(a) >= '0' && str.charAt(a) <= '9' ) || ( str.charAt(a) >= 'A' && str.charAt(a) <= 'Z' ) || ( str.charAt(a) >= 'a' && str.charAt(a) <= 'z' )))
			return false;
		a++;
	}
	return true;
}

function isValidString(str)
{
	var a=0;
	while(a<str.length)
	{
		if( str.charAt(a)== '\'' || str.charAt(a) == '\\' )
			return false;
		a++;
	}
	return true;
}

	function isCharsInBag (s, bag)
  {
    var i;
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return(false);
    }
    return true;
  }
  
	function EmailCheck(email){
		
		if(email.value==''){
			alert("Enter Email Address");
            email.focus();            
            return false;
		}
		if ( !this.isCharsInBag( email.value, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._@-" ))
		{
		      
            alert("Invalid Email Address");
            email.focus();            
            return false;
		}
	
	if(email.value != '')
	   {
		var str=email.value;	
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var sdot=str.indexOf(dot,ldot+1);

		if (str.indexOf(at)==-1){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		if (str.substring(ldot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.substring(sdot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if(str.lastIndexOf(".") == str.length-1)
		 {
		 	alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
	}//end of else
	return true;
}

function RegistrationSubmit()
{
	var cusType,first,last,pass,conf,user,email;
	
	var custType = MWJ_findObj('customertype');
	
	if(custType.value == "-1")
	{
		window.alert('Select Customer Type');
		//custType.focus();
		return;
	}
	
	
	first = MWJ_findObj('firstName');
	if(trim(first.value) == '')
	{
		window.alert('Enter First Name');
		first.focus();
		return;
	}
	if(!isValidName(first.value))
	{
		window.alert('Special characters are not allowed in First Name');
		first.focus();
		return;
	}
	last = MWJ_findObj('lastName');
	if(trim(last.value) == '')
	{
		window.alert('Enter Last Name');
		last.focus();
		return;
	}
	if(!isValidName(last.value))
	{
		window.alert('Special characters are not allowed in Last Name');
		last.focus();
		return;
	}
	
	
	//alert("customer type"+custType.value);
		if ( custType.value == "1" )
		{
		var Company_Name = MWJ_findObj('company_Name');
		 if ( trim(Company_Name.value) == '' )
			{
				window.alert('Enter Company Name');
				Company_Name.focus();
				return;
			}	
			if(!isValidName(Company_Name.value))
			{
				window.alert('Special characters are not allowed in Company Name');
				Company_Name.focus();
				return;
			}
		}
		
		if ( custType.value == "2" )
		{
			var bussName = MWJ_findObj('businessName');
			if ( trim(bussName.value) == '' )
			{
				window.alert('Enter Business Name');
				bussName.focus();
				return;
			}	
			if(!isValidName(bussName.value))
			{
				window.alert('Special characters are not allowed in Business Name');
				bussName.focus();
				return;
			}
			var shipAddr = MWJ_findObj('shippingAddress');
				if(trim(shipAddr.value) == '')
				{
					window.alert('Enter Shipping Address');
					shipAddr.focus();
					return;
				}
				if(!isValidString(shipAddr.value))
				{
					window.alert('Special characters such as \',\\ are not allowed in Shipping Address');
					shipAddr.focus();
					return;
				}
				
				var taxIdent = MWJ_findObj('taxIdentification');	
				if(trim(taxIdent.value) == '')
				{
					window.alert('Enter Tax Identification Number');
					taxIdent.focus();
					return;
				}
				if(!isValidString(taxIdent.value))
				{
					window.alert('Special characters such as \',\\ are not allowed in Tax Identification Number');
					taxIdent.focus();
					return;
				}
						//else
				//window.alert('Enter Company Name');
			
			/*if ( custType.value == "Wholesale" )
				window.alert('Enter Business Name');
			else
				window.alert('Enter Company Name');
				else			
				window.alert('Special characters are not allowed in Company Name');
			
			*/
		}
	
	
	/*if(!isValidName(bussName.value))
	{
		//if ( custType.value == "Wholesale" )
		if ( custType.value == "2" )
			window.alert('Special characters are not allowed in Business Name');
		else			
			window.alert('Special characters are not allowed in Company Name');
		bussName.focus();
		return;
	}*/
	
	//if ( custType.value == "Wholesale" )
	/*if ( custType.value == "2" )
	{
		var shipAddr = MWJ_findObj('shippingAddress');
		if(trim(shipAddr.value) == '')
		{
			window.alert('Enter Shipping Address');
			shipAddr.focus();
			return;
		}
		if(!isValidString(shipAddr.value))
		{
			window.alert('Special characters such as \',\\ are not allowed in Shipping Address');
			shipAddr.focus();
			return;
		}
		
		var taxIdent = MWJ_findObj('taxIdentification');	
		if(trim(taxIdent.value) == '')
		{
			window.alert('Enter Tax Identification Number');
			taxIdent.focus();
			return;
		}
		if(!isValidString(taxIdent.value))
		{
			window.alert('Special characters such as \',\\ are not allowed in Tax Identification Number');
			taxIdent.focus();
			return;
		}
	}*/
		
	var addr1 = MWJ_findObj('address1');
	if(trim(addr1.value) == '')
	{
		window.alert('Enter first line of Address');
		addr1.focus();
		return;
	}
	if(!isValidString(addr1.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in first line of Address');
		addr1.focus();
		return;
	}
	addr1 = MWJ_findObj('address2');
	if(!isValidString(addr1.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in second line of Address');
		addr1.focus();
		return;
	}
	var city = MWJ_findObj('city');
	if(trim(city.value) == '')
	{
		window.alert('Enter City');
		city.focus();
		return;
	}
	if(!isValidString(city.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in City');
		city.focus();
		return;
	}
	var state = MWJ_findObj('state');
	if(state.value == 'sel')
	{
		window.alert('Enter State');
		state.focus();
		return;
	}
	var zip = MWJ_findObj('zipCode');
	if(trim(zip.value) == '')
	{
		window.alert('Enter Zip Code');
		zip.focus();
		return;
	}
	else if(zip.value.length != 5)
	{
		window.alert('Enter a valid Zip Code');
		zip.focus();
		return;
	}
	
	if (!isInteger(zip.value))
	{
      alert("Invalid Zip Code");
      zip.focus();            
      return;
	}

	var country = MWJ_findObj('country');
	if(country.value == 'sel')
	{
		window.alert('Enter Country');
		country.focus();
		return;
	}
	var phone = MWJ_findObj('phone');
	if(trim(phone.value) == '')
	{
		window.alert('Enter Phone');
		phone.focus();
		return;
	}
	if(!isValidString(phone.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in Phone');
		phone.focus();
		return;
	}
	email = MWJ_findObj('email');
	if(!this.EmailCheck(email)){
		return false;
	}
	
	user = MWJ_findObj('userid');
	if(trim(user.value) == '')
	{
		window.alert('Enter User Id');
		user.focus();
		return;
	}
	if(!isValidUserName(user.value))
	{
		window.alert('User ID can be composed of letters(a-z,A-Z), numbers(0-9) and underscore(_) only');
		user.focus();
		return;
	}
	pass = MWJ_findObj('pass');
	conf = MWJ_findObj('confirm');
	if(trim(pass.value)=='' || pass.value.length < 5 || pass.value.length > 8)
	{
		window.alert('Password should be of length 5-8');
		pass.focus();
		return;
	}
	if(!isValidString(pass.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in Password');
		pass.focus();
		return;
	}
	if(trim(pass.value) != trim(conf.value))
	{
		window.alert('Password and Confirm Password fields do not match');
		pass.focus();
		return;
	}
	state.disabled = false;


	var cfirst = MWJ_findObj('cfirstName');
	var clast = MWJ_findObj('clastName');
	var ctype = MWJ_findObj('cardtype');
	var cnumber = MWJ_findObj('cardnumber');
	var cmonth = MWJ_findObj('expmonth');
	var cyear = MWJ_findObj('expyear');
	var cverification = MWJ_findObj('verification');

	if(cfirst.value!='')
	{
		if(!isValidName(cfirst.value))
		{
		window.alert('Special characters are not allowed in First Name');
		cfirst.focus();
		return;
		}
		if ( !isValidString( cfirst.value, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ))
		{
            alert("Credit Card Holder First Name can only contain Alphabets");
            cfirst.focus();            
            return;
		}
		
		if(clast.value == '')
		{
			window.alert('Enter Credit Card Holder Last Name');
			clast.focus();
			return;
		}
		if(!isValidName(clast.value))
		{
		window.alert('Special characters are not allowed in Last Name');
		clast.focus();
		return;
		}
		if ( !isValidString( clast.value, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ))
		{
		      
	           alert("Credit Card Holder Last Name can only contain Alphabets");
	           clast.focus();            
	           return;
		}
	
		if(ctype.value == 'sel')
		{
			window.alert('Select Credit Card Type');
			ctype.focus();
			return;
		}
		if(cnumber.value == '')
		{
			window.alert('Enter Credit Card Number');
			cnumber.focus();
			return;
		}
		else if(ctype.value == '3')
		{
			if(cnumber.value.length !=15 || isInteger(cnumber.value) == false)
			{
				window.alert("Invalid value in credit card number.\nPlease remove {A-Z or a-z or Special Character like \"/\-+\'}\nAmerican Express Accept 15 digits credit card number.");
				cnumber.focus();
				return;
			}
		}
		else if(ctype.value != '3')
		{
			if(cnumber.value.length != 16 || isInteger(cnumber.value) == false)
			{
				window.alert("Invalid value in credit card number.\nPlease remove {A-Z or a-z or Special Character like \"/\-+\'}\nAll credit card brand accept 16 digits credit card number excluding \"American Express\".");
				cnumber.focus();
				return;
			}
		}
		
		if(cmonth.value == 0)
		{
			window.alert('Select Expiry Month');
			cnumber.focus();
			return;
		}
		if(cyear.value ==0)
		{
			window.alert('Select Expiry Year');
			cnumber.focus();
			return;
		}
//		CurrentDate=new Date();
//		if(cyear.value==CurrentDate.getYear() && cmonth.value<CurrentDate.getMonth())
//		{
//			window.alert('Please Select Correct Month');
//			cmonth.focus();
//			return;
//		}

		if(cverification.value == '')
		{
			window.alert('Enter Credit Card Verification Number');
			cverification.focus();
			return;
		}
		else if(ctype.value == '3')
		{
			if(cverification.value.length != 4 || isInteger(cverification.value) == false)
			{
				window.alert('Enter a valid Credit Card Verification Number');
				cverification.focus();
				return;
			}
		}
		else if(ctype.value != '3')
		{
			if(cverification.value.length != 3 || isInteger(cverification.value) == false)
			{
				window.alert('Enter a valid Credit Card Verification Number');
				cverification.focus();
				return;
			}
		}
	}	
	document.forms['frmRegistration'].submit();
}

function isInteger(str)
{
	var a=0;
	while(a<str.length)
	{
		if( str.charAt(a)< '0' || str.charAt(a) > '9' )
			return false;
		a++;
	}
	return true;
}

function CreditCardSubmit()
{
	var button = MWJ_findObj('editsave');
	var type,number,verification;
	var first = MWJ_findObj('firstName');
	var last = MWJ_findObj('lastName');
	var type = MWJ_findObj('cardtype');
	var number = MWJ_findObj('cardnumber');
	var verification = MWJ_findObj('verification');
	var month = MWJ_findObj('expmonth');
	var year = MWJ_findObj('expyear');
	//alert(button.value);
	if(button.value == 'Edit')
	{
		button.value = 'Save';
		button = MWJ_findObj('continuereset');
		button.value = 'Reset';
		first.disabled = last.disabled = type.disabled = number.disabled = verification.disabled = month.disabled = year.disabled = false;
		return;
	}
	//window.alert('Register');
	if(trim(first.value) == '')
	{
		window.alert('Enter First Name');
		first.focus();
		return;
	}
	if(!isValidString(first.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in First Name');
		first.focus();
		return;
	}
	if(trim(last.value) == '')
	{
		window.alert('Enter Last Name');
		last.focus();
		return;
	}
	if(!isValidString(last.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in Last Name');
		last.focus();
		return;
	}
	if(type.value == 'sel')
	{
		window.alert('Select Credit Card Type');
		type.focus();
		return;
	}
	if(trim(number.value) == '')
	{
		window.alert('Enter Credit Card Number');
		number.focus();
		return;
	}
	// ::::: Credit Card Type :::::
	// 1) Master Card
	// 2) Visa Card
	// 3) American Express
	// 4) Discover
	else if(type.value == '3')
	{
		if(number.value.length != 15 || isInteger(number.value) == false)
		{
			window.alert("Invalid value in credit card number.\nPlease remove {A-Z or a-z or Special Character like \" / \ - + \'}\nAmerican Express Accept 15 digits credit card number.");
			number.focus();
			return;
		}
	}
	else if(type.value != '3')
	{
		if(number.value.length != 16 || isInteger(number.value) == false)
		{
			window.alert("Invalid value in credit card number.\nPlease remove {A-Z or a-z or Special Character like \"/\-+\'}\nAll credit card brand accept 16 digits credit card number excluding \"American Express\".");
			number.focus();
			return;
		}
	}

	if(month.value == 0)
	{
		window.alert('Please Select Expiry Month');
		month.focus();
		return;
	}
	if(year.value ==0)
	{
		window.alert('Please Select Expiry Year');
		year.focus();
		return;
	}
//	CurrentDate=new Date();
//	if(year.value==CurrentDate.getYear() && month.value<CurrentDate.getMonth())
//	{
//		window.alert('Please Select Correct Month');
//		month.focus();
//		return;
//	}	
	if(trim(verification.value) == '')
	{
		window.alert('Enter Credit Card Verification Number');
		verification.focus();
		return;
	}
	else if(type.value == '3')
	{
		if(verification.value.length != 4 || isInteger(verification.value) == false)
		{
			window.alert('Enter a valid Credit Card Verification Number');
			verification.focus();
			return;
		}
	}
	else if(type.value != '3')
	{
		if(verification.value.length != 3 || isInteger(verification.value) == false)
		{
			window.alert('Enter a valid Credit Card Verification Number');
			verification.focus();
			return;
		}
	}

	document.forms['frmCreditCardInformation'].submit();
}

function ShippingAddressSubmit()
{
	var first,last,same;
	same = MWJ_findObj('issame');
	
	if(same.checked)
	{
		document.forms['frmShippingAddress'].submit();
		return;
	}
	//alert("asdfasd");
	first = MWJ_findObj('firstName');
	if(first.value == '')
	{
		window.alert('Enter First Name');
		first.focus();
		return;
	}
	if(!isValidString(first.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in First Name');
		first.focus();
		return;
	}
	last = MWJ_findObj('lastName');
	if(last.value == '')
	{
		window.alert('Enter Last Name');
		last.focus();
		return;
	}
	if(!isValidString(last.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in Last Name');
		last.focus();
		return;
	}
	var addr1 = MWJ_findObj('address1');
	if(addr1.value == '')
	{
		window.alert('Enter first line of Address');
		addr1.focus();
		return;
	}
	if(!isValidString(addr1.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in first line of Address');
		addr1.focus();
		return;
	}
	var addr1 = MWJ_findObj('address2');
	if(!isValidString(addr1.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in second line of Address');
		addr1.focus();
		return;
	}
	var city = MWJ_findObj('city');
	if(city.value == '')
	{
		window.alert('Enter City');
		city.focus();
		return;
	}
	if(!isValidString(city.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in City');
		city.focus();
		return;
	}
	var state = MWJ_findObj('state');
	if(state.value == 'sel')
	{
		window.alert('Enter State');
		state.focus();
		return;
	}
	var zip = MWJ_findObj('zipCode');
	if(zip.value == '')
	{
		window.alert('Enter Zip Code');
		zip.focus();
		return;
	}
	else if(zip.value.length != 5)
	{
		window.alert('Enter a valid Zip Code');
		zip.focus();
		return;
	}
	var country = MWJ_findObj('country');
	if(country.value == 'sel')
	{
		window.alert('Enter Country');
		country.focus();
		return;
	}
	
	country.value == '1'
	if(country.value != '1')
	{
		window.alert('Shipping Only in US');
		country.focus();
		return;
	}
	
	var phone = MWJ_findObj('phone');
	if(phone.value == '')
	{
		window.alert('Enter Phone');
		phone.focus();
		return;
	}
	if(!isValidString(phone.value))
	{
		window.alert('Special characters such as \',\\ are not allowed in Phone');
		phone.focus();
		return;
	}
	
	document.forms['frmShippingAddress'].submit();
}


function ResetCreditCard()
{
	var button = MWJ_findObj('continuereset');
	if(button.value == 'Continue')
	{
		var type,number,verification;
		var first = MWJ_findObj('firstName');
		var last = MWJ_findObj('lastName');
		type = MWJ_findObj('cardtype');
		number = MWJ_findObj('cardnumber');
		verification = MWJ_findObj('verification');
		var month = MWJ_findObj('expmonth');
		var year = MWJ_findObj('expyear');
		first.disabled = last.disabled = type.disabled = number.disabled = verification.disabled = month.disabled = year.disabled = false;
		document.forms['frmCreditCardInformation'].submit();
		return;
	}
	else
		document.forms['frmCreditCardInformation'].reset();
}

function ShipAddress()
{
	var same = MWJ_findObj('issame');
	var first,last,addr1,addr2,city,state,country,zip,phone;
	first = MWJ_findObj('firstName');
	last = MWJ_findObj('lastName');
	addr1 = MWJ_findObj('address1');
	addr2 = MWJ_findObj('address2');
	city = MWJ_findObj('city');
	zip = MWJ_findObj('zipCode');
	country = MWJ_findObj('country');
	phone = MWJ_findObj('phone');
	state = MWJ_findObj('state');
	if(same.checked && first.disabled == false)
	{
		//window.alert('test');
		first.disabled = true;
		ResetShippingForm();
		first.disabled = last.disabled = addr1.disabled = addr2.disabled = city.disabled = zip.disabled = country.disabled = phone.disabled = state.disabled = true;
	}
	else
	{	//window.alert('test2');
		first.value = last.value = addr1.value = addr2.value = city.value = zip.value = phone.value = '';
		country.value = state.value = 'sel';
		first.disabled = last.disabled = addr1.disabled = addr2.disabled = city.disabled = zip.disabled = country.disabled = phone.disabled = state.disabled = false;	
	}
}

function ResetShipForm(objCheckbox, sValue)
{
	var same = MWJ_findObj('issame');
	var first,last,addr1,addr2,city,state,country,zip,phone;
	
	first = MWJ_findObj('firstName');
	last = MWJ_findObj('lastName');
	addr1 = MWJ_findObj('address1');
	addr2 = MWJ_findObj('address2');
	city = MWJ_findObj('city');
	zip = MWJ_findObj('zipCode');
	country = MWJ_findObj('country');
	phone = MWJ_findObj('phone');
	state = MWJ_findObj('state');
	
	if(objCheckbox.checked == true  && first.disabled == false)
	{
		first.disabled = true;
		window.document.frmShippingAddress.reset();
		window.document.frmShippingAddress.state.value = sValue;
		first.disabled = last.disabled = addr1.disabled = addr2.disabled = city.disabled = zip.disabled = country.disabled = phone.disabled = state.disabled = true;
	}
	else
	{
		ShipAddress();
	}
}


var dfirst,dlast,daddr1,daddr2,dcity,dstate,dcountry,dzip,dphone;
	
function ResetShippingForm(sValue)
{
//    alert(sValue);
//	var first,last,addr1,addr2,city,state,country,zip,phone;
//	first = MWJ_findObj('firstName');
//	last = MWJ_findObj('lastName');
//	addr1 = MWJ_findObj('address1');
//	addr2 = MWJ_findObj('address2');
//	city = MWJ_findObj('city');
//	zip = MWJ_findObj('zipCode');
//	country = MWJ_findObj('country');
//	phone = MWJ_findObj('phone');
//	state = MWJ_findObj('state');
//	first.value = dfirst;
//	last.value = dlast;
//	addr1.value = daddr1;
//	addr2.value = daddr2;
//	city.value = dcity;
//	zip.value = dzip;
//	country.value = dcountry;
//	phone.value = dphone;
//	state.value = dstate ;
//	CountrySelect();

	window.document.frmShippingAddress.reset();
	window.document.frmShippingAddress.state.value = sValue;
}

function SaveShippingValues()
{
	var first,last,addr1,addr2,city,state,country,zip,phone;
	first = MWJ_findObj('firstName');
	last = MWJ_findObj('lastName');
	addr1 = MWJ_findObj('address1');
	addr2 = MWJ_findObj('address2');
	city = MWJ_findObj('city');
	zip = MWJ_findObj('zipCode');
	country = MWJ_findObj('country');
	phone = MWJ_findObj('phone');
	state = MWJ_findObj('state');
	dfirst = first.value;
	dlast = last.value;
	daddr1 = addr1.value;
	daddr2 = addr2.value;
	dcity = city.value;
	dzip = zip.value;
	dcountry = country.value;
	dphone = phone.value;
	dstate = state.value;
	//window.alert(dfirst);
}

function CountrySelect()
{
	var country,state;
	country = MWJ_findObj('country');
	state = MWJ_findObj('state');
	if(country.value == '1' || country.value == 'sel')
	{
		state.disabled = false;
		if(country.value == '1')
			state.value = 'sel';
	}
	else
	{
		state.value = '66';
		state.disabled = true;		
	}
//	window.alert(state);
}

function trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

/**
* Created 14th Deceber
* by Abddul Samad
* Check Email address 
* @return boolean
**/

function EmailCheck(email){
		
		if(email.value==''){
			alert("Enter Email Address");
            email.focus();            
            return false;
		}
		if ( !this.isCharsInBag( email.value, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._@-" ))
		{
		      
            alert("Invalid Email Address");
            email.focus();            
            return false;
		}
	
	if(email.value != '')
	   {
		var str=email.value;	
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var sdot=str.indexOf(dot,ldot+1);

		if (str.indexOf(at)==-1){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		if (str.substring(ldot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.substring(sdot+1)==''){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
			alert("Invalid Email Address");
            email.focus();            
		    return false;
		 }
	}//end of else
	return true;
}


/*
* @return Number
*/

function isCharsInBag (s, bag)
{
    var i;
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return(false);
    }
    return true;
}




/**
* @return 
*/
  