
 function blockNumbers(e)
{
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	}
	else if(e.which) {
		// netscape
		key = e.which;
	}
	else {
		// no event, so pass through
		return true;
	}

	keychar = String.fromCharCode(key);
	
	if ( (key>=48 &&  key<=57) || (key==46) || (key==44)|| (key==45) || (key==34) || (key==39) || (key==32) || (key == 8) || (key == 43) || (key == 41) || (key == 40))
	{
		return true;
	}
	else
	{
		return false;
	}
}

googlewin.onclose=function(){ //Run custom code when window is being closed (return false to cancel action):
return window.confirm("Close window 1?")
	}


 function checkemail(str){
	 
// var str = document.validation.emailcheck.value
 var filter=/^.+@.+\..{2,3}$/

 if (filter.test(str))
    testresults=0;
 else {
	testresults =1;
		
}
 return (testresults)
}

function check_vipform(){
	var first = $('#txt_first').val();
	var last  = $('#txt_last').val();
	var addr  = $('#txt_address').val();
	var email  = $('#txt_email').val();
	var city  = $('#txt_city').val();
	var zip  = $('#txt_zip').val();
	var state = $('#sel_state').val();
	var phone =	$('#txt_phone').val();
	var trade_year = $('#sel_year').val();
	var trade_make = $('#sel_make').val();
	var trade_model = $('#sel_model').val();
	var how_to_hear = $('#sel_hear').val();
	var hear_others = $('#hear_others').val();
	var comments = $('#comments').val();
	var free_trade = $('#free_trade').val();
	var int_preown = $('#int_preown').val();
	var model_int = $('#model_int').val();
	var vip_pricing = $('#vip_pricing').val();
	var friend_to_mark = $('#friend_to_mark').val();
	var credit_check = $('#credit_check').val();
	var vehi_other = $('#vehi_other').val();
	
	if(trim(first)==""){		
		alert("Please Enter your First Name");
		$('#txt_first').val('');
		$('#txt_first').focus();	
	} else if(trim(last)==""){
		alert("Please Enter your Last Name");
		$('#txt_last').val('');
		$('#txt_last').focus();			
	} else if(trim(email)==""){
		alert("Please Enter your Email");
		$('#txt_email').val('');
		$('#txt_email').focus();	
		
	}
	else if(checkemail(trim(email))==1){
		alert("Please Enter Valid Email");
		$('#txt_email').focus();	
		
	}else if(trim(addr)==""){
		alert("Please Enter your Address");
		$('#txt_address').val('');
		$('#txt_address').focus();	
		
	} else if(trim(city)==""){
		alert("Please enter your city");
		$('#txt_city').val('');
		$('#txt_city').focus();	
		
	} else if(trim(state)==0){
		alert("Please Select State");
		$('#sel_state').focus();			
	} else if(trim(zip)==""){
		alert("Please Enter Zipcode");
		$('#txt_zip').val('');
		$('#txt_zip').focus();	
		
	} else if(trim(phone)==""){
		alert("Please Enter the Phone number");
		$('#txt_phone').val('');
		$('#txt_phone').focus();	
		
	} else if(trim(trade_year)==0){
		alert("Please Select Year");
		$('#sel_year').focus();	
	
	}
	else if(trim(trade_make)==0){
		alert("Please Select Make");
		$('#sel_make').focus();	
		
	}
	else if(trim(trade_model)==0){
		alert("Please Select the Model");
		$('#sel_model').focus();	
	}
	else {
		
		var Submit = 'vipfrm_add';
		var PageName = 'MainClass';
		
		$.post("application/main_action.php",{PageName:''+PageName+'',Submit:''+Submit+'',first:''+first+'',last:''+last+'',email:''+email+'',addr:''+addr+'',state:''+state+'',city:''+city+'',zip:''+zip+'',phone:''+phone+'',trade_year:''+trade_year+'',trade_make:''+trade_make+'',trade_model:''+trade_model+'',how_to_hear:''+how_to_hear+'',hear_others:''+hear_others+'',comments:''+comments+'',free_trade:''+free_trade+'',int_preown:''+int_preown+'',model_int:''+model_int+'',vip_pricing:''+vip_pricing+'',friend_to_mark:''+friend_to_mark+'',credit_check:''+credit_check+'',vehi_other:''+vehi_other+''},function(getResult){

		var result_data = getResult;
		result_data = result_data.replace(/^[\s]+/g,"");
		result_data = result_data.split("~~");
		var rec_id = result_data[1];
		if(result_data[0] ==0){		
		//document.getElementById('vip_button').innerHTML='<div style="float:left; width:206px; padding-top:4px; height:50px;"><img src="images/new_submit_btn.png" width="206" height="50"  /></div>';
			
				
	//		var url = 'certificate.php?rec_id='+rec_id;
			
		//var googlewin=dhtmlwindow.open("googlebox", "iframe", url, "JJCHEVY", "width=1020px,height=500px,resize=1,scrolling=1,center=1", "recal")
			alert("Thank you for registering with TOYOTA VIP Club. You will be receiving the details by email.");
		}
		else
		{
			alert("This Email is already Exist");
		$('#txt_email').focus();
		
	}
		});


	}

}


function list_make(year_id){
		var Submit = 'make_list';
		var PageName = 'MainClass';
		$.post("application/main_action.php",{PageName:''+PageName+'',Submit:''+Submit+'',year_id:''+year_id+''},function(getResult){
		var result_data = getResult;
		result_data = result_data.replace(/^[\s]+/g,"");
		if(result_data!=""){
			//document.getElementById('sel_make').innerHTML = result_data;
			$('#select_make').html(getResult);
		}
		});
}


function list_model(make_id){
		var Submit = 'model_list';
		var PageName = 'MainClass';
		$.post("application/main_action.php",{PageName:''+PageName+'',Submit:''+Submit+'',make_id:''+make_id+''},function(getResult){
		var result_data = getResult;
		result_data = result_data.replace(/^[\s]+/g,"");
		if(result_data!=""){
			//document.getElementById('sel_model').innerHTML = result_data;
			$('#select_model').html(result_data);
		}
		});
}


function showSpecial(special_id){
		var Submit = 'special_list';
		var PageName = 'MainClass';
		$.post("application/main_action.php",{PageName:''+PageName+'',Submit:''+Submit+'',special_id:''+special_id+''},function(getResult){
		var result_data = getResult;
		result_data = result_data.replace(/^[\s]+/g,"");
		if(result_data!=""){
			document.getElementById('special_content').innerHTML = result_data;
		}
		});

}

function show ()
{
var hear_id = document.getElementById("sel_hear").value;
if(hear_id == 14 )
{
document.getElementById("divother").style.visibility='visible';
}
else
{
document.getElementById("divother").style.visibility='hidden';
}
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
