// JavaScript Document

Function.prototype.defaults = function() 	
{ 	
  var _f = this; 	
  var _a = Array(_f.length-arguments.length).concat( 	
    arguments.length-1?Array.apply(null, arguments): 	
    [arguments[0]]); 	
  return function() 	
  { 	
    return _f.apply(_f, (arguments.length-1 ? 	
      Array.apply(null, arguments) : [arguments[0]]).concat( 	
        _a.slice(arguments.length, _a.length))); 	
  } 	
} 


function check_Mail(mail)
{
	 if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))) 
	 {
		return false;
	} else
	{	return true;
	}
}

function check_Selected(id)
	{	
		d = document.getElementById(id);
		if(d.options[d.selectedIndex].value == -1) 
		{
			alert("Please choose an option from the dropdown menu.");
			d.focus();
			return false;
		}
		return true;
	}


var container_Show = function(obj, force_Show, force_Hide)
{
	if(force_Hide)
	{
		document.getElementById(obj).style.display = "none";
		return true;
	}
	if(force_Show)
	{
		document.getElementById(obj).style.display = "block";
		return true;
	}
	
	
	if(document.getElementById(obj).style.display == "none")
	{
		document.getElementById(obj).style.display = "block";
	}
	else 
	{
		document.getElementById(obj).style.display = "none";
	}
	
	
	return true;
	
}.defaults(false, false); 

function get_Element(id)
{
	return document.getElementById(id);
}

function do_Confirm(str)
{
	if(	window.confirm(str) ) return true;
	else return false;
}


/*Free Quote Field Validator*/

function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('Name');
	var email = document.getElementById('Email');
	var phone = document.getElementById('Phone');
	var comment = document.getElementById('Comment');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(firstname, "Please enter your name")){
		if(notEmpty(phone, "Please enter a contact phone")){
			if(notEmpty(comment, "Please enter comment")){
				if(emailValidator(email, "Please enter a valid email address")){
							return true;
				}
			}
		}
	}
	
	
	return false;
	
}
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

