function validateEmail(email)
{
	// This function is used to validate a given e-mail 
	// address for the proper syntax
	
	if (email == ""){
		return false;
	}
	badStuff = ";:/,' \"\\";
	for (i=0; i<badStuff.length; i++){
		badCheck = badStuff.charAt(i)
		if (email.indexOf(badCheck,0) != -1){
			return false;
		}
	}
	posOfAtSign = email.indexOf("@",1)
	if (posOfAtSign == -1){
		return false;
	}
	if (email.indexOf("@",posOfAtSign+1) != -1){
		return false;
	}
	posOfPeriod = email.indexOf(".", posOfAtSign)
	if (posOfPeriod == -1){
		return false;
	}
	if (posOfPeriod+2 > email.length){
		return false;
	}
	return true
}

function checkfields(){
if (document.getElementById("addcreditinfo").checked==true){ 
	document.getElementById("card_holder_name").disabled=false; 	
	document.getElementById("cc_type").disabled=false; 
	document.getElementById("card_num").disabled=false; 
	document.getElementById("month").disabled=false; 
	document.getElementById("year").disabled=false; 
	document.getElementById("card_code").disabled=false;
}
else
{
	document.getElementById("card_holder_name").disabled=true; 	
	document.getElementById("cc_type").disabled=true; 
	document.getElementById("card_num").disabled=true; 
	document.getElementById("month").disabled=true; 
	document.getElementById("year").disabled=true; 
	document.getElementById("card_code").disabled=true;
}
}

function checkform_frmcreate_account(){
if (document.getElementById("email").value==""){ 
	alert("Please enter your email.");
	document.getElementById("email").select(); 
	return false;
	}
	else
	{
		var email = document.getElementById("email").value;
		if(!(validateEmail(email)))
		{
			alert("Please enter correct email id.")
			document.getElementById("email").select(); 
			return false;
		}
	}	
if (document.getElementById("password").value==""){ 
	alert("Please enter your Password.");
	document.getElementById("password").select(); 
	return false;
	}	
if (document.getElementById("confirmation").value==""){ 
	alert("Please enter your Password Confirmation.");
	document.getElementById("confirmation").select(); 
	return false;
	}
if (document.getElementById("addcreditinfo").checked==true){ 
	if (document.getElementById("card_holder_name").value==""){ 
		alert("Please enter your card holder name.");
		document.getElementById("card_holder_name").select(); 
		return false;
	}
	if (document.getElementById("cc_type").value==""){ 
		alert("Please select your card type.");
		document.getElementById("cc_type").focus(); 
		return false;
	}
	if (document.getElementById("card_num").value==""){ 
		alert("Please enter your card number.");
		document.getElementById("card_num").select(); 
		return false;
	}
	if (document.getElementById("month").value==""){ 
		alert("Please select your credit card exp. month.");
		document.getElementById("month").focus(); 
		return false;
	}	
	if (document.getElementById("year").value==""){ 
		alert("Please select your credit card exp. year.");
		document.getElementById("year").focus(); 
		return false;
	}	
	if (document.getElementById("card_code").value==""){ 
		alert("Please enter your credit card CVV code.");
		document.getElementById("card_code").select(); 
		return false;
	}	
}
if (document.getElementById("firstname").value==""){ 
	alert("Please enter your first name.");
	document.getElementById("firstname").select(); 
	return false;
	}
if (document.getElementById("lastname").value==""){ 
	alert("Please enter your last name.");
	document.getElementById("lastname").select(); 
	return false;
	}	
/*if (document.getElementById("dob").value==""){ 
	alert("Please enter your Date of Birth.");
	document.getElementById("dob").select(); 
	return false;
	}	*/

if (document.getElementById("street_address").value==""){ 
	alert("Please enter your street address.");
	document.getElementById("street_address").select(); 
	return false;
	}	
if (document.getElementById("city").value==""){ 
	alert("Please enter your City.");
	document.getElementById("city").select(); 
	return false;
	}
if (document.getElementById("state").value==""){ 
	alert("Please enter your State.");
	document.getElementById("state").select(); 
	return false;
	}
	else
	{
	if(document.getElementById("state").value=="51")
	{
	if (document.getElementById("txt_otherState").value==""){ 
	alert("Please enter your state.");
	document.getElementById("txt_otherState").select(); 
	return false;
	}
	}
	}
if (document.getElementById("postcode").value==""){ 
	alert("Please enter your Zip code.");
	document.getElementById("postcode").select(); 
	return false;
	}	
if (document.getElementById("phone").value==""){ 
	alert("Please enter your Phone.");
	document.getElementById("phone").select(); 
	return false;
	}	
/*if (document.getElementById("fax").value==""){ 
	alert("Please enter your Fax.");
	document.getElementById("fax").select(); 
	return false;
	}	
*/	
if(document.getElementById("same_address").checked == false)
{
if (document.getElementById("firstname_sh").value==""){ 
	alert("Please enter your Shipping first name.");
	document.getElementById("firstname_sh").select(); 
	return false;
	}
if (document.getElementById("lastname_sh").value==""){ 
	alert("Please enter your Shipping last name.");
	document.getElementById("lastname_sh").select(); 
	return false;
	}	
if (document.getElementById("street_address_sh").value==""){ 
	alert("Please enter your Shipping street address.");
	document.getElementById("street_address_sh").select(); 
	return false;
	}	
	if (document.getElementById("city_sh").value==""){ 
		alert("Please enter your Shipping City.");
		document.getElementById("city_sh").select(); 
		return false;
		}	
	if (document.getElementById("state_sh").value==""){ 
		alert("Please enter your Shipping State.");
		document.getElementById("state_sh").select(); 
		return false;
		}
		else
		{
		if(document.getElementById("state_sh").value=="51")
		{
		if (document.getElementById("txt_otherState_sh").value==""){ 
		alert("Please enter your shipping state.");
		document.getElementById("txt_otherState_sh").select(); 
		return false;
		}
		}
		}	
	if (document.getElementById("postcode_sh").value==""){ 
		alert("Please enter your Shipping Zip code.");
		document.getElementById("postcode_sh").select(); 
		return false;
		}	
	if (document.getElementById("phone_sh").value==""){ 
		alert("Please enter your Shipping Phone.");
		document.getElementById("phone_sh").select(); 
		return false;
		}	
/*	if (document.getElementById("fax_sh").value==""){ 
		alert("Please enter your Shipping Fax.");
		document.getElementById("fax_sh").select(); 
		return false;
		} */
	}

}
 
function check_info(){
if (document.getElementById("firstname").value==""){ 
	alert("Please enter your first name.");
	document.getElementById("firstname").select(); 
	return false;
	}
if (document.getElementById("lastname").value==""){ 
	alert("Please enter your last name.");
	document.getElementById("lastname").select(); 
	return false;
	}	
if (document.getElementById("street_address").value==""){ 
	alert("Please enter your street address.");
	document.getElementById("street_address").select(); 
	return false;
	}	
if (document.getElementById("city").value==""){ 
	alert("Please enter your City.");
	document.getElementById("city").select(); 
	return false;
	}	
if (document.getElementById("state").value==""){ 
	alert("Please enter your State.");
	document.getElementById("state").select(); 
	return false;
	}
	else
	{
	if(document.getElementById("state").value=="51")
	{
	if (document.getElementById("txt_OtherState").value==""){ 
	alert("Please enter your State.");
	document.getElementById("txt_OtherState").select(); 
	return false;
	}	
	}
	}	
if (document.getElementById("postcode").value==""){ 
	alert("Please enter your Zip code.");
	document.getElementById("postcode").select(); 
	return false;
	}	
if (document.getElementById("phone").value==""){ 
	alert("Please enter your Phone.");
	document.getElementById("phone").select(); 
	return false;
	}	
/*if (document.getElementById("fax").value==""){ 
	alert("Please enter your Fax.");
	document.getElementById("fax").select(); 
	return false;
	}	*/
} 

function check_cc_info(){
if (document.getElementById("card_holder_name").value==""){ 
		alert("Please enter your card holder name.");
		document.getElementById("card_holder_name").select(); 
		return false;
	}
	if (document.getElementById("cc_type").value==""){ 
		alert("Please select your card type.");
		document.getElementById("cc_type").focus(); 
		return false;
	}	
	if (document.getElementById("card_num").value==""){ 
		alert("Please enter your card number.");
		document.getElementById("card_num").select(); 
		return false;
	}
	if (document.getElementById("month").value==""){ 
		alert("Please select your credit card exp. month.");
		document.getElementById("month").select(); 
		return false;
	}	
	if (document.getElementById("year").value==""){ 
		alert("Please select your credit card exp. year.");
		document.getElementById("year").select(); 
		return false;
	}	
	if (document.getElementById("card_code").value==""){ 
		alert("Please enter your credit card CVV code.");
		document.getElementById("card_code").select(); 
		return false;
	}	
}

function checkform_frmpassword(){
if (document.getElementById("email").value==""){ 
	alert("Please enter your email.");
	document.getElementById("email").select(); 
	return false;
	}
	else
	{
		var email = document.getElementById("email").value;
		if(!(validateEmail(email)))
		{
			alert("Please enter correct email id.")
			document.getElementById("email").select(); 
			return false;
		}
	}
}	

function check_login(){
if (document.getElementById("email").value==""){ 
	alert("Please enter your email.");
	document.getElementById("email").select(); 
	return false;
	}
	else
	{
		var email = document.getElementById("email").value;
		if(!(validateEmail(email)))
		{
			alert("Please enter correct email id.")
			document.getElementById("email").select(); 
			return false;
		}
	}
	
if(document.getElementById("pass").value == ""){
	alert("Please enter your password.");
	document.getElementById("pass").select();
	return false;
	}
}	

function check_qty(count){
	for(i=1;i<=count;i++){
		if (document.getElementById(i).value == ""){
			alert("Please dont leave any Quantity field blank..")
			document.getElementById(i).select();
			return false
		}
		else
		{
			temp = "0123456789";
			field_value = document.getElementById(i).value;
			intvaluelen = field_value.length;
			for(j=0;j<intvaluelen;j++)
			{
				var ch = field_value.charAt(j);
				if(temp.indexOf(ch) == -1)
				{
					alert("Please enter a numeric value");
					document.getElementById(i).select();
					return false;
				}
			}
		}
	}
} 

function Fill_ddlhrefSelectBox(url,hiddenElmBgImage,selectElmBgImage){
	var XMLhttpObj = false;
	if(document.getElementById("btnBack"))
	document.getElementById("btnBack").disabled=true;
	if(document.getElementById("btnContinue"))
	document.getElementById("btnContinue").disabled=true;
    if (typeof XMLHttpRequest != 'undefined'){
        XMLhttpObj = new XMLHttpRequest();
    } else if (window.ActiveXObject){
        	try{
            	XMLhttpObj = new ActiveXObject('Msxml2.XMLHTTP');
        	} catch(e) {
            		try{
                		XMLhttpObj = new ActiveXObject('Microsoft.XMLHTTP');
            		} catch(e) {}
        	}
    }
    if (!XMLhttpObj) return;
	
	XMLhttpObj.onreadystatechange = function() {
    	if (XMLhttpObj.readyState == 4) { // when request is complete
            fillSelect(XMLhttpObj.responseText,hiddenElmBgImage,selectElmBgImage);
        }
    };
    url = url+"?sid="+Math.random();
    XMLhttpObj.open('GET', url, true);
    XMLhttpObj.send(null);
}

function fillSelect(optionData,hElmBgImage,sElmBgImage) {
	var elmBGImage = document.getElementById(hElmBgImage);
	//alert(optionData);http
	elmBGImage.innerHTML = optionData;
	if(document.getElementById("btnBack"))
	document.getElementById("btnBack").disabled=false;
	if(document.getElementById("btnContinue"))
	document.getElementById("btnContinue").disabled=false;
	if (document.getElementById("rb_1"))
	{
		elmBGImage.style.height = "5px";
		elmBGImage.style.height = document.getElementById("tblUps").style.height;
		document.getElementById("upsshipping").style.height=elmBGImage.style.height;
		document.getElementById("div_final_charge").innerHTML='$' + document.getElementById("rb_1").value;
		document.getElementById("ship").value=document.getElementById("rb_1").value;
		if (document.getElementById("hdn_ship_method"))
		{
			document.getElementById("ship_method").value=document.getElementById("hdn_ship_method").value;
		}
		else
		{
			document.getElementById("ship_method").value='0';
		}
	}
	else
	{
		document.getElementById("div_final_charge").innerHTML='$0.00';
		document.getElementById("ship").value='0';
	}
    /*var BGImage = document.getElementById(sElmBgImage);
    var elmBGImage = document.getElementById(hElmBgImage);

    // clear out existing options
    while (BGImage.options.length) {
        BGImage.options[0] = null;*/
    }

function charge(chargeval,key)
{
	document.getElementById("div_final_charge").innerHTML='$' + chargeval;
	document.getElementById("ship").value=chargeval;
	document.getElementById("ship_method").value=key;
}

function GetVideoObjectCode(url,hiddenElmBgImage,selectElmBgImage){
	var tempdiv = document.getElementById(hiddenElmBgImage);
	//tempdiv.innerHTML = 'Please wait...';
	var XMLhttpObj = false;
    if (typeof XMLHttpRequest != 'undefined'){
        XMLhttpObj = new XMLHttpRequest();
    } else if (window.ActiveXObject){
        	try{
            	XMLhttpObj = new ActiveXObject('Msxml2.XMLHTTP');
        	} catch(e) {
            		try{
                		XMLhttpObj = new ActiveXObject('Microsoft.XMLHTTP');
            		} catch(e) {}
        	}
    }
    if (!XMLhttpObj) return;
	
	XMLhttpObj.onreadystatechange = function() {
    	if (XMLhttpObj.readyState == 4) { // when request is complete
    		FillVideoDiv(XMLhttpObj.responseText,hiddenElmBgImage,selectElmBgImage);
        }
    };
    url = url+"&sid="+Math.random();
    XMLhttpObj.open('GET', url, true);
    XMLhttpObj.send(null);
}

function FillVideoDiv(optionData,hElmBgImage,sElmBgImage) {
	var elmBGImage = document.getElementById(hElmBgImage);
	elmBGImage.innerHTML = optionData;
	
	
}

    
