<!--//

// Checks and verify Email
function emailCheck(str){
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	// check if string contains @sign
	if (str.indexOf(at)==-1){
	   return false
	}
	// check if @sign not at beginning of string
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	// check if period not at beginning of string
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}

	 return true					
}// end function emailCheck

function inventory_expand(id){
	if ($('#blind_' + id).is(":hidden")){
		$('#blind_' + id).slideDown('slow');
		$('#sign_' + id).html('-');
	}else{
		$('#blind_' + id).slideUp('slow');
		$('#sign_' + id).html('+');
	}
}

function search_newused(id){
	var myForm = document.getElementById(id);
	var defaultChecked = '';
	for (var i = 0; i < myForm.newused.length; i++ ){
		if (myForm.newused[i].checked == true){
			defaultChecked = myForm.newused[i].value; 
		}
	}
	
	if (defaultChecked == '1'){
		myForm.action = '/inventory/new';
	}
	else if(defaultChecked == '0'){
		myForm.action = '/inventory/preowned';
	}
	else{
		myForm.action = '/inventory/all';
	}
	myForm.submit();
}

function advance_filter(filterType, filterValue,model,newUsed){
	$.post('/includes/ajax', {
		filter:			filterType,
		filtervalue:	filterValue,
		model:			model,
		newUsed:		newUsed,
		method_type: 	'search_filter',
		module:			'inventory'
	}, function(data){
		if (data != '') {
			if (data.result == 'true') {
				var display_count = document.getElementById('change_recordcount');
				document.getElementById('replace_search_data').innerHTML = data.output;
				display_count.innerHTML = data.count;
				
			}
		}
	}, 'json');
		
}

function detail_search(id){
	var myForm = document.getElementById(id);
	var defaultChecked = '';
	
	for (var i = 0; i < myForm.newused.length; i++ ){
		if (myForm.newused[i].selected == true){
			defaultChecked = myForm.newused[i].value; 
		}
	}
	
	if (defaultChecked == '1'){
		myForm.action = '/inventory/new';
	}
	else if(defaultChecked == '0'){
		myForm.action = '/inventory/preowned';
	}
	else{
		myForm.action = '/inventory/all';
	}
	myForm.submit();
}
function form_check(id, request){
	var myForm = document.getElementById(id);
	var error = '';
	if (myForm.first_name.value == ''){
		error += "- First Name\n";
	}
	if (myForm.last_name.value == ''){
		error += " - Last Name\n";
	}
	if (myForm.address.value == ''){
		error += " - Address\n";
	}
	if (myForm.city.value == ''){
		error += " - City\n";
	}
	if (myForm.state.value == ''){
		error += " - State\n";
	}
	if (myForm.zip.value == ''){
		error += " - Zipcode\n";
	}
	if (emailCheck(myForm.email.value) == false){
		error += " - Email is invalid\n";
	}
	
	if (error == '') {
		$.post('/includes/ajax', {
			captcha: 			myForm.captcha_code.value,
			first_name: 		myForm.first_name.value,
			last_name: 			myForm.last_name.value,
			address:			myForm.address.value,
			city:				myForm.city.value,
			state:				myForm.state.value,
			zipcode:			myForm.zip.value,
			email:				myForm.email.value,
			day_phone:			myForm.day_phone.value,
			comments:			myForm.comments.value,
			coach_id:			myForm.coach_id.value,
			method_type:	 	request,
			module: 			'email'
		}, function(data){
			if (data != '') {
				if (data.result == 'true') {
					document.getElementById('replace_form_text').innerHTML = '<p class="submit_sucess">Thank you for your inquiry.<br /> A representative will contact you soon.<br /> <a href="">back to form</a></p>';
				}
				else {
					alert('Capcha Code is incorrect');
				}
			}
		}, 'json');
	}else {// end no error
		alert("Please fill out the require fields\n\n" + error);	
	}
	
	
}
function load_image(imageName){
	var imageOjb = document.getElementById('image_swap');
	imageOjb.src = '/assets/images/coach_photos/'+imageName;
}
//-->