jQuery(document).ready(function(){

$("#myform").submit( function() {
   return validForm(window.document.getElementById("mycontactform"));
 } );
});

function validForm(obj) {

for ( var i=0; i<window.document.getElementsByTagName("label").length; i++ ) {
		element_label = window.document.getElementsByTagName("label")[i];
		txt_label = element_label.firstChild.nodeValue;
		
		if ( document.all ) { 
			element_label_for_id = element_label.getAttribute("htmlFor");
		} else { 
			element_label_for_id = element_label.getAttribute("for");
		}
		if (element_label_for_id!="") {
				//alert(element_label_for_id);
				element_label_for_value = window.document.getElementById(element_label_for_id).value;
				if (js_is_empty(element_label_for_value)) {
					alert(error1+" \""+txt_label.replaceAll(" :","")+"\" "+error2);
					window.document.getElementById(element_label_for_id).className='warning';
					window.document.getElementById(element_label_for_id).focus();					
					return false;
				} else {
					window.document.getElementById(element_label_for_id).className='text';
				}
				if(element_label_for_id=="contact_email" && !check_email(window.document.getElementById(element_label_for_id))) {
							window.document.getElementById(element_label_for_id).className='warning';
							window.document.getElementById(element_label_for_id).focus();			
							return false;
				}					
		}	

}													



	


} 

	function check_email(obj) {
		var re_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!re_email.test(obj.value)) {
			alert(error3);
			return false;
		} else {
			return true;
		}
	}
	
	
function js_trim(str) {
			str=str.replace(/^\s+/g,"");
			str=str.replace(/\s+$/g,"");
			return str;			
}
	
function js_is_empty(str) {
		return ((js_trim(str).length==0));
}
	
	$(document).ready(function(){

		$("#mycontactform").submit(function() {
																						return validForm(window.document.getElementById("mycontactform"));
																					}
															 );//
	});


String.prototype.replaceAll = function( 
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
 

// Keep looping while an instance of the target string
// still exists in the string.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strText = strText.replace( strTarget, strSubString )
 

// Get the index of any next matching substring.
intIndexOfMatch = strText.indexOf( strTarget );
}
 

// Return the updated string with ALL the target strings
// replaced out with the new substring.
return( strText );
}

