///////////////////// validation function for form  start from here///////////////////////////////////


// username - 4-10 chars, uc, lc, and underscore only.
function checkName (strng) {
if (strng == "")
{
alert("Please enter the first name\n");
return false;
}
var illegalChars = /[^a-zA-Z0-9_" "]/; // allow letters, numbers, and underscores space
if (illegalChars.test(strng))
{
alert("Name field contains illegal characters\n");
return false;
} 
return true;
} 

function checkUsername2 (strng) {
if (strng == "")
{
alert("Please enter the last name\n");
return false;
}
var illegalChars = /[^a-zA-Z0-9_" "]/; // allow letters, numbers, and underscores space
if (illegalChars.test(strng))
{
alert("Name field contains illegal characters\n");
return false;
} 
return true;
}




function checkEmail (strng) 
{
if (strng == "")
{
alert("Please enter an email address\n");
return false;
}

var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) { 
alert("Please enter a valid email address\n");
return false;
}
else {
//test email for illegal characters
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (strng.match(illegalChars)) {
alert("The email address contains illegal characters\n");
return false;
}
}
return true;
}


// phone number - strip out delimiters and check for 10 digits

function checkMobile (strng) {
if (strng == "") {
alert("Please enter 10 digit phone number\n");
return false;
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
alert("The phone number should be numeric");
return false;;
}
if (!(stripped.length == 10)) {
alert("Please enter 10 digit mobile number \n");
return false;
} 
return true;
}



// non-empty textbox
function street(strng) {
if (strng.length == 0) {
alert("Please enter the address\n");
return false;
}
return true;	  
}

function street1(strng) {
if (strng.length == 0) {
alert("Please enter the Landmark\n");
return false;
}
return true;	  
}

function city1(strng) {
if (strng.length == 0) {
alert("Please enter the city\n");
return false;
}
return true;
}

// valid selector from dropdown list

function checkDropdown(choice) {
if (choice == 0) {
alert("Please select the state\n");
return false;
} 
return true;
}  

// phone number - strip out delimiters and check for 10 digits

function checkzip (strng) {
if (strng == "") {
alert("Please enter pin code\n");
return false;
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
alert("Please enter correct pin code\n");
return false;

}
if (!(stripped.length == 5)) {
alert("Please enter correct pin code\n");
return false;
} 
return true;
}


function checkcc (strng) {
if (strng == "") {
alert("Please enter credit card number\n");
return false;
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
alert("Please enter correct credit card number\n");
return false;

}
return true;
}


function security_code(strng) {
if (strng.length == 0) {
alert("Please enter security code\n");
return false;
}
return true;
}

///////////////////// validation function for form  end  here///////////////////////////////////
function validateSubmit()
{  
	
	
	if(!checkName(document.getElementById('name').value))
	{ 
	document.getElementById('name').focus();
    return false;
	}
	if(!street(document.getElementById('address').value))
	{ 
	document.getElementById('address').focus();
    return false;
	}
	if(!checkEmail(document.getElementById('email').value))
	{ 
	document.getElementById('email').focus();
    return false;
	}
	if(!checkMobile(document.getElementById('mobile').value))
	{ 
	document.getElementById('mobile').focus();
    return false;
	}
	if(!checkDescriptions(document.getElementById('descriptions').value))
	{ 
	document.getElementById('descriptions').focus();
    return false;
	}
	
    if(document.getElementById('item1c').checked == false && document.getElementById('item2c').checked == false && document.getElementById('item3c').checked == false && document.getElementById('item4c').checked == false && document.getElementById('item5c').checked == false && document.getElementById('item6c').checked == false)
	{ 
	document.getElementById('chkstatus').value = 0;

	alert("Please select atleast one item");

    return false;
	}	


    if(document.getElementById('ccm').checked == false && document.getElementById('cod').checked == false)
	{ 
	document.getElementById('chkpay').value = 0;

	alert("Please select atleast one Payment option");

    return false;
	}	



    if(!checkUsername(document.getElementById('contact').value))
	{ 
	document.getElementById('contact').focus();
    return false;
	}
	
	if(!checkPhone1(document.getElementById('mobile').value))
	{ 
	document.getElementById('mobile').focus();
    return false;
	}
	if(!street(document.getElementById('address').value))
	{ 
	document.getElementById('address').focus();
    return false;
	}
	if(!city1(document.getElementById('cityc1').value))
	{ 
	document.getElementById('cityc1').focus();
    return false;
	}
   	if(!checkzip(document.getElementById('pinc1').value))
	{ 
	document.getElementById('pinc1').focus();
    return false;
	}

	if(!street1(document.getElementById('closestc1').value))
	{ 
	document.getElementById('closestc1').focus();
    return false;
	}








	//document.getElementById('shoping').submit();
 	return true; 
	
	//alert("jjj");
}	
/////////////////function for change the filed tab/////////////////////////////////
function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}






function hidefield()
{   
    if(chk_form_fill()== true)
	{
      if(document.getElementById('same').checked)
	  {   
      // alert("checked");
	   document.getElementById('contact').value=document.getElementById('name').value;
	   document.getElementById('mobilec').value=document.getElementById('mobile').value;
	   document.getElementById('city').value=document.getElementById('city').value;
	   document.getElementById('pin').value=document.getElementById('pin').value;
	  

	    
		  
	  }else
	  {
	   document.getElementById('contact').value="";
	   document.getElementById('mobile').value="";
	   document.getElementById('address').value="";
	   document.getElementById('city').value="";
	   document.getElementById('pin').value="";

	   document.getElementById('closest').value="";
	 

		 //document.getElementById('billing').style.display='block'; 
	 }
     //return (key != 13);
	}
	 else
	{
		document.getElementById('same').checked = 0;
	}
	 
}




function chk_form_fill()
{

if(!checkUsername(document.getElementById('name').value))
	{ 
	document.getElementById('name').focus();
    return false;
	}
	if(!street(document.getElementById('address').value))
	{ 
	document.getElementById('address').focus();
    return false;
	}
	if(!checkEmail(document.getElementById('email').value))
	{ 
	document.getElementById('email').focus();
    return false;
	}
	if(!checkPhone1(document.getElementById('mobile').value))
	{ 
	document.getElementById('mobile').focus();
    return false;
	}
	
	if(!city1(document.getElementById('city').value))
	{ 
	document.getElementById('city').focus();
    return false;
	}

	
    
 	return true; 
}


function today()
{
	var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()

    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes()
    minutes=((minutes < 10) ? "0" : "") + minutes
    var seconds = currentTime.getSeconds()

document.getElementById('ddate').value = day + "-" + month + "-" + year+" "+hours + ":" + minutes + ":" + seconds;
//document.write(month + "/" + day + "/" + year)

}

function assginchk()
{
	
document.getElementById('chkstatus').value = 1;
//document.write(month + "/" + day + "/" + year)

}

function assginpay()
{
	
document.getElementById('chkpay').value = 1;
//document.write(month + "/" + day + "/" + year)

}