function validate(){
	if ( (!isFirst()) || (!isLast()) || (!isPhone()) || (!isEmail())  || (!isComment()) ){
		return false;
	}
}
function isFirst(){
	var str = document.Site_Feedback_Pakistan.first_name.value;
	// Return false if comments field is blank.
	if (str == ""){
		//alert("Please enter your first name");
		$("#errfn").fadeIn(200);
		document.Site_Feedback_Pakistan.first_name.focus();
		return false;
	}
	return true;
}

function isLast(){
	var str = document.Site_Feedback_Pakistan.last_name.value;
	// Return false if comments field is blank.
	if (str == ""){
		//alert("Please enter your last name");
		$("#errln").fadeIn(200);
		document.Site_Feedback_Pakistan.last_name.focus();
		return false;
	}
	return true;
}


function isPhone(){
	var Phone = document.Site_Feedback_Pakistan.phone.value;
	if (Phone == ""){
		//alert("Please enter your telephone number");
		$("#errphone").fadeIn(200);
		document.Site_Feedback_Pakistan.phone.focus();
		return false;
	}
	if (checkInternationalPhone(Phone)==false){
		//alert("Please enter your telephone number");
		$("#errphone").fadeIn(200);
		document.Site_Feedback_Pakistan.phone.value="";
		document.Site_Feedback_Pakistan.phone.focus();
		return false;
	}
	return true;
 }

function isEmail(){
	var s = document.Site_Feedback_Pakistan.email.value;
	if(!checkEmail(s)) {
		//alert('Please enter a valid email address');
		$("#erremail").fadeIn(200);
		document.Site_Feedback_Pakistan.email.focus();
		return false;
	}
	return true;
}

function isComment(){
	var str = document.Site_Feedback_Pakistan.commentbox.value;
	// Return false if comments field is blank.
	if (str == ""){
		//alert("Please enter your suggestions/queries");
		$("#errcommentbox").fadeIn(200);
		document.Site_Feedback_Pakistan.commentbox.focus();
		return false;
	}
	return true;
}

function FormReset() {
document.Site_Feedback_Pakistan.reset();
} 


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 1;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3;
var strPhone=trim(strPhone);
if(strPhone.indexOf("+")>1) 
return false;
if(strPhone.indexOf("-")!=-1)
var bracket=bracket+1;
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)
return false;
var brchr=strPhone.indexOf("(");
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")
return false;
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)
return false;
var s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}



function checkEmail (s){
	var i = 0;
	var sLength = s.length;
	while(i < sLength){
		if( !((isLetter(s.charAt(i))) || (isDigit(s.charAt(i))) || (s.charAt(i) == "-") || (s.charAt(i) == "_") || (s.charAt(i) == ".") || (s.charAt(i) == "@")))
			return false;
		else
			i++;
	}
	
	for (j=0; j<sLength; j++){
		if (s.charAt(j) == "@") {
			for (k=j+1; k<sLength; k++){
				if(s.charAt(k) == "@") {
					return false;
				}
			}
		}
	}
	
	for (l=0; l<sLength; l++){
		if (s.charAt(l) == ".") {
			var m = l;
			m++;
			if(s.charAt(m) == "." || s.charAt(m) == "") {
				return false;
			}
		}
	}
	
	i = 1;			
	
	while ((i < sLength) && (s.charAt(i) != "@"))
		{ i++  }
	
	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else{ i += 2; }
	
	// look for .
	while ((i < sLength) && (s.charAt(i) != ".")){ i++ }
	
	// there must be at least one character after the .
	if ((i >= sLength - 2) || (s.charAt(i) != ".")) return false;
	else return true;
}

function isLetter (c)	{
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

function isDigit (c){
	return ((c >= "0") && (c <= "9"));
}

function isValidDate(day, month, year)
{
//alert (day +"  "+ month +"  "+ year);
var daysInMonth = DaysArray(month);
var day= day;
var month= month;
var year = year;
if ((month==2 && day>daysInFebruary(year)) || day > daysInMonth){
		alert("Vyberte prosím platné datum")
		return false;
	}
	return true;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	if (n==4 || n==6 || n==9 || n==11) {n = 30; }
	else if (n==2) {n = 29; }
	else{ n=31; }
   return n;
}
