// JavaScript Document
function popup(url){
	var win = window.open(url,"sadsd","location=no,status=no, scrollbars=1,width=550,height=400")
}

function init(){
	fillDate();
}

function validateField(formName, textField, restrict){
		var tBox 	  = eval("document."+formName+"." + textField);
		var textValue = LTrim(tBox.value);
		switch (restrict){
			case 'number':
				if(!isNaN(textValue) && textValue != ""){
					return true;
				}else{
					tBox.focus();
					return false;
				}
				break;
			
			case 'email':
				var re = /^[_a-z0-9A-Z-]+(\.[_a-z0-9A-Z-]+)*@[a-z0-9A-Z-]+(\.[a-z0-9A-Z-]+)*(\.[a-zA-Z]{2,8})$/;
				//++++++++++/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
				if(!textValue.match(re)){
					tBox.focus();
					return false;
				}else{
					return true;
				}
				break;
				
			case 'null':
				if(textValue == "" || textValue =="XX"){
					tBox.focus();
					return false;
				}else{
					return true;
				}
				break;
		}
		
}

function resetForm(){
	form1.reset();
	fillDate();
}

function fillDate(){
	var dateObj = new Date();
	var date    = dateObj.getDate();
	var month 	= dateObj.getMonth()+1;
	var year 	= dateObj.getYear();
	
	document.form1.move_day.value   = refine(date);
	document.form1.move_month.value = refine(month);
	document.form1.move_year.value  = year;
}

function refine(num){
	if(num<10){
		num = "0"+num;
	}
	return num;
}

function LTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

/*
function validate2(formName){
	var selectedForm  = eval("document."+formName);
	
	//Format :
	//validateField(Form name, Textfield Name, ['number' or 'email' or 'null'] )
	if(!validateField(formName, 'user_type', 'null')){
		alert("Please specify whether you are an existing user or not");
		return false;
	}
	
	if(!validateField(formName, 'num_email', 'null')){
		alert("Please fill Number from Email");
		return false;
	}
	
	if(!validateField(formName, 'tot_price', 'number')){
		alert("Please enter the Total Price");
		return false;
	}
	
	if(!validateField(formName, 'cust_name', 'null')){
		alert("Please enter Name");
		return false;
	}
	
	if(!validateField(formName, 'cust_addr', 'null')){
		alert("Please specify the Address.");
		return false;
	}
	
	if(!validateField(formName, 'cust_city', 'null')){
		alert("Please specify City.");
		return false;
	}	
	
	if(!validateField(formName, 'cust_zip', 'null')){
		alert("Please specify Zipcode.");
		return false;
	}		
	
	if(!validateField(formName, 'cust_email', 'email')){
		alert("Please enter a valid Email.");
		return false;
	}
	
	if(!validateField(formName, 'pick_name', 'null')){
		alert("Please specify the Name");
		return false;
	}
	
	if(!validateField(formName, 'pick_addr', 'null')){
		alert("Please specify the Address");
		return false;
	}	
	
	if(!validateField(formName, 'pick_city', 'null')){
		alert("Please specify the City");
		return false;
	}
	
	if(!validateField(formName, 'pick_zip', 'null')){
		alert("Please specify the Zipcode");
		return false;
	}
	
	if(!validateField(formName, 'pick_home', 'null')){
		alert("Please specify the Phone number");
		return false;
	}
	
	if(!validateField(formName, 'delv_name', 'null')){
		alert("Please specify the Name");
		return false;
	}	
	
	if(!validateField(formName, 'delv_addr', 'null')){
		alert("Please specify the Address");
		return false;
	}	
	
	if(!validateField(formName, 'delv_city', 'null')){
		alert("Please specify the City");
		return false;
	}	
		
	if(!validateField(formName, 'delv_zip', 'null')){
		alert("Please specify the Zipcode");
		return false;
	}	
		
	if(!validateField(formName, 'delv_home', 'null')){
		alert("Please specify the Phone number");
		return false;
	}			
		
	if(!validateField(formName, 'veh_year', 'null')){
		alert("Please specify the Year");
		return false;
	}		
		
	if(!validateField(formName, 'veh_make', 'null')){
		alert("Please specify the Make");
		return false;
	}		
		
	if(!validateField(formName, 'veh_color', 'null')){
		alert("Please specify the Color");
		return false;
	}
	
	if(!selectedForm.agree[0].checked){
		alert("You must agree the Terms And Conditions.");
		return false;
	}
	
	return true;
}

*/


/*
function validate(formName){
	var selectedForm  = eval("document."+formName);

	//Format :
	//validateField(Form name, Textfield Name, ['number' or 'email' or 'null'] )
	
	if(!validateField(formName, 'first_name', 'null')){
		alert("Please fill First Name");
		return false;
	}
	
	if(!validateField(formName, 'last_name', 'null')){
		alert("Please fill Last Name");
		return false;
	}
	
	if(!validateField(formName, 'email', 'email')){
		alert("Please enter a valid E-mail ID");
		return false;
	}
	
	if(!validateField(formName, 'phone', 'null')){
		alert("Please specify Phone Number");
		return false;
	}
	
	if(!validateField(formName, 'move_month', 'null')){
		alert("Please specify the Estimated move month");
		return false;
	}
	
	if(!validateField(formName, 'move_day', 'null')){
		alert("Please specify the Estimated move date");
		return false;
	}
	
	if(!validateField(formName, 'move_year', 'null')){
		alert("Please specify the Estimated move year");
		return false;
	}	
	
	if(!validateField(formName, 'veh_year', 'null')){
		alert("Please specify the Year");
		return false;
	}
	
	if(!validateField(formName, 'veh_model', 'null')){
		alert("Please specify the Model");
		return false;
	}

	return true;
}*/
