var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
   if ((version >= 5.5) && (version < 7) && (document.body.filters))
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
}

function isValidEmail(str) {
   return str.match(/^([\w\-]+\.)*[\w\-]+\@([\w\-]+\.)+\w{2,3}$/)
}
//footer section, validate form
function validate_easy_contact_form(){
	var errors = 0;
	$("#easy_name_error").html("");
	$("#easy_email_error").html("");
	if ($("#easy_name").val() == "" || $("#easy_name").val() == "Type your Name here...") {
		$("#easy_name_error").html("Name required!");
		errors ++;
	}
	if ($("#easy_email").val() == "" || $("#easy_email").val() == "...and your e-mail here" || !isValidEmail($("#easy_email").val())) {
		$("#easy_email_error").html("Valid email required!");
		errors ++;
	}
	if (errors == 0)
		return true;
	else
		return false;
}

//main contact form validation
function processContactForm(){
	FormReference = document.contactform;
	
	$("#fname").css("border", "1px solid #A5ACB2");
	$("#lname").css("border", "1px solid #A5ACB2");
	$("#email").css("border", "1px solid #A5ACB2");
	$("#phone").css("border", "1px solid #A5ACB2");
	$("#phone_error").html("");
	$("#email_error").html("");
	$("#lname_error").html("");
	$("#fname_error").html("");

	var valid = true;
	// Checking if all fileds marked with (*) where filled
	if( FormReference.phone.value.length == 0 ){
		$("#phone").css("border", "1px solid #FF4A00");
		$("#phone_error").html("required");
		$("#phone").focus();
		valid = false;
	}
	if( !FormReference.email.value.match(/^([\w\-]+\.)*[\w\-]+\@([\w\-]+\.)+\w{2,3}$/) ){
		$("#email").css("border", "1px solid #FF4A00");
		$("#email_error").html("required");
		$("#email").focus();
		valid = false;
	}
	if( FormReference.email.value.length == 0 ){
		$("#email").css("border", "1px solid #FF4A00");
		$("#email_error").html("required");
		$("#email").focus();
		valid = false;
	}
	if( FormReference.lname.value.length == 0 ){
		$("#lname").css("border", "1px solid #FF4A00");
		$("#lname_error").html("required");
		$("#lname").focus();
		valid = false;
	}
	if( FormReference.fname.value.length == 0 ){
		$("#fname").css("border", "1px solid #FF4A00");
		$("#fname_error").html("required");
		$("#fname").focus();
		valid = false;
	}

	if (valid == false)
	{
		//document.location.href = "contact_us.php#form-begins";
		return false;
	}
	else
	{
		FormReference.submit();
		return true;
	}
}

