function swapimg(obj){var brokenstring=obj.src.split('/');var brokenimgstring=brokenstring[(brokenstring.length-1)].split('.');var newpath = '';for(i= 0; i < (brokenstring.length-1);i++){if(newpath == ''){newpath = brokenstring[i];}else{newpath = newpath+'/'+brokenstring[i];}}var lastimgnamepart = brokenimgstring[(brokenimgstring.length-2)];if(lastimgnamepart.indexOf('_rollover') == -1){var rollover = '_rollover';var brokenrolloverpartimgstring=brokenimgstring[(brokenimgstring.length-2)];}else{var brokenrolloverpartimgstring=brokenimgstring[(brokenimgstring.length-2)].split('_');brokenrolloverpartimgstring = brokenrolloverpartimgstring[0];var rollover = '';}var newimgstr = '';for(i= 0; i < brokenimgstring.length;i++){if((brokenimgstring.length-2) == i){if(newimgstr == ''){newimgstr = brokenrolloverpartimgstring+rollover;}else{newimgstr = newimgstr+'.'+brokenrolloverpartimgstring+rollover;				}}else{if(i == 0){newimgstr = brokenimgstring[i];}else{newimgstr = newimgstr+'.'+brokenimgstring[i];}}}obj.src = newpath+'/'+newimgstr;}

$(document).ready(function(){
													 
	if($("#directions").attr("id")){//alleen als map nodig is om js error te voorkomen op andere pagina's
		initialize();//gmaps		
	}

	$("#cu_name").attr({ value: "Name"});
	$("#cu_company").attr({ value: "Company"});
	$("#cu_subject").attr({ value: "Subject"});
	$("#cu_email").attr({ value: "E-mail"});
	$("#cu_msg").attr({ value: "Message"});
	
	$("#fromAddress").attr({ value: "Street"});
	$("#fromcity").attr({ value: "City"});
	
	
	//home/contact
	$("#cu_btn").click(function(){ submitContact();});
	
	
	$("#cu_name").focus(function(){ clearfrstime(this, 'Name');});
	$("#cu_name").blur(function(){ clearfrstime(this, 'Name');});

	$("#cu_company").focus(function(){ clearfrstime(this, 'Company');});
	$("#cu_company").blur(function(){ clearfrstime(this, 'Company');});

	$("#cu_subject").focus(function(){ clearfrstime(this, 'Subject');});
	$("#cu_subject").blur(function(){ clearfrstime(this, 'Subject');});

	$("#cu_email").focus(function(){ clearfrstime(this, 'E-mail');});
	$("#cu_email").blur(function(){ clearfrstime(this, 'E-mail');});
	
	$("#cu_msg").focus(function(){ clearfrstime(this, 'Message');});
	$("#cu_msg").blur(function(){ clearfrstime(this, 'Message');});

	$("#fromAddress").focus(function(){ clearfrstime(this, 'Street');});
	$("#fromAddress").blur(function(){ clearfrstime(this, 'Street');});
	
	$("#fromcity").focus(function(){ clearfrstime(this, 'City');});
	$("#fromcity").blur(function(){ clearfrstime(this, 'City');});
	
	//rfq
	
	$("#rfq_name").blur(function(){ clearfrstime(this, 'Name');});
	$("#rfq_company").blur(function(){ clearfrstime(this, 'Company');});
	$("#rfq_phone").blur(function(){ clearfrstime(this, 'Phone');});
	$("#rfq_email").blur(function(){ clearfrstime(this, 'E-mail');});
	$("#rfq_partnr").blur(function(){ clearfrstime(this, 'Part nr');});
	$("#rfq_qty").blur(function(){ clearfrstime(this, 'Quantity');});
	$("#rfq_con").blur(function(){ clearfrstime(this, 'Condition');});
	$("#rfq_desc").blur(function(){ clearfrstime(this, 'Description');});
	$("#rqf_remaks").blur(function(){ clearfrstime(this, 'Remarks');});


	$("#rfq_name").focus(function(){ clearfrstime(this, 'Name');});
	$("#rfq_company").focus(function(){ clearfrstime(this, 'Company');});
	$("#rfq_phone").focus(function(){ clearfrstime(this, 'Phone');});
	$("#rfq_email").focus(function(){ clearfrstime(this, 'E-mail');});
	$("#rfq_partnr").focus(function(){ clearfrstime(this, 'Part nr');});
	$("#rfq_qty").focus(function(){ clearfrstime(this, 'Quantity');});
	$("#rfq_con").focus(function(){ clearfrstime(this, 'Condition');});
	$("#rfq_desc").focus(function(){ clearfrstime(this, 'Description');});
	$("#rqf_remaks").focus(function(){ clearfrstime(this, 'Remarks');});

	initContactForm();//init
	initRFQForm();//init
});


function submitContact(){

	var error = false;
	//checkform
	if($("#cu_name").attr("value") == 'Name'){
		 $("#cu_name").addClass("frmrequired");
		 error = true;
	}
	if($("#cu_company").attr("value") == 'Company'){ 
		$("#cu_company").addClass("frmrequired");
		 error = true;
	}
	if($("#cu_subject").attr("value") == 'Subject'){
		$("#cu_subject").addClass("frmrequired");
		 error = true;
	}
	if($("#cu_email").attr("value") == 'E-mail'){
		$("#cu_email").addClass("frmrequired");
		error = true;
	}
	if($("#cu_msg").attr("value") == 'Message'){
		$("#cu_msg").addClass("frmrequired");
		error = true;
	}

	if(error == true) return false;

	$.blockUI({ message: '<h3>Een moment aub...</h3>' });

	var queryString = $('#contactfrm').formSerialize();


	$.ajax({type: "POST",
				 url: "./index.php/contact/sendmail",
				 data: queryString,
		beforeSend: function(){ $.blockUI({ message: '<h1>Proccessing...</h1>'}); }, //show loading just when link is clicked  
//		complete: function(){ $.unblockUI();}, //stop showing loading when the process is complete  
		success: function(html){
			if(html == true){
				$.blockUI({ message: "<h1>Send successfully...</h1>" }); 
				
				$('#submitbtnArea').html('Send successfully...');
				
				initContactForm();
			}else{
				$.blockUI({ message: '<h1>'+html+'</h1>' });
			}
		
			setTimeout($.unblockUI, 2000);
		
		}//END success
	}); //end $.ajax
}


function submitrfq(){
	
	var error = false;
	//checkform
	if($("#cu_name").attr("value") == 'Name'){
		 $("#cu_name").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_name").attr("value") == 'Name'){
		 $("#rfq_name").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_company").attr("value") == 'Company'){
		 $("#rfq_company").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_phone").attr("value") == 'Phone'){
		 $("#rfq_phone").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_email").attr("value") == 'E-mail'){
		 $("#rfq_email").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_partnr").attr("value") == 'Part nr'){
		 $("#rfq_partnr").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_qty").attr("value") == 'Quantity'){
		 $("#rfq_qty").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_con").attr("value") == 'Condition'){
		 $("#rfq_con").addClass("frmrequired");
		 error = true;
	}
	if($("#rfq_desc").attr("value") == 'Description'){
		 $("#rfq_desc").addClass("frmrequired");
		 error = true;
	}
	if($("#rqf_remaks").attr("value") == 'Remarks'){
		 $("#rqf_remaks").addClass("frmrequired");
		 error = true;
	}
	
	if(error == true) return false;
	
	$.blockUI({ message: '<h3>Een moment aub...</h3>'});

	var queryString = $('#rfqfrm').formSerialize();
	
	$.ajax({type: "POST",
				 url: "./index.php/rfq/sendmail",
				 data: queryString,
		beforeSend: function(){ $.blockUI({ message: '<h1>Proccessing...</h1>'}); }, //show loading just when link is clicked  
//		complete: function(){ $.unblockUI();}, //stop showing loading when the process is complete  
		success: function(html){
			if(html == true){
				$.blockUI({ message: "<h1>Send successfully...</h1>" }); 
				$('#submitbtnArea').html('Send successfully...');
				initRFQForm();
			}else{
				$.blockUI({ message: '<h1>'+html+'</h1>' });
			}
			setTimeout($.unblockUI, 2000);
		}//END success
	}); //end $.ajax
}


function initContactForm(){
	$("#cu_name").attr({ value: "Name"});
	$("#cu_company").attr({ value: "Company"});
	$("#cu_subject").attr({ value: "Subject"});
	$("#cu_email").attr({ value: "E-mail"});
	$("#cu_msg").attr({ value: "Message"});
}

function initRFQForm(){
	$("#rfq_name").attr({ value: "Name"});	
	$("#rfq_company").attr({ value: "Company"});	
	$("#rfq_phone").attr({ value: "Phone"});	
	$("#rfq_email").attr({ value: "E-mail"});	
	$("#rfq_partnr").attr({ value: "Part nr"});	
	$("#rfq_qty").attr({ value: "Quantity"});	
	$("#rfq_con").attr({ value: "Condition"});	
	$("#rfq_desc").attr({ value: "Description"});	
	$("#rqf_remaks").attr({ value: "Remarks"});
}


function clearfrstime(obj, defaulttxt){

	//remove required class
	$("#"+obj.id).removeClass('frmrequired');

	if($("#"+obj.id).attr("value") == defaulttxt){
		$("#"+obj.id).attr({ value: ""});
	}else if($("#"+obj.id).attr("value") == ''){
		$("#"+obj.id).attr({ value: defaulttxt});
	}
}

