
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

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) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	//alert(dtCh)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("הזן תאריך חודש תקני")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("הזן תאריך יום תקני")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("הזן תאריך שנה תקני")
		return false
	}
return true
}

/*function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }*/


function validateEmail(email) {
	var matches = email.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	return (matches != null && email == matches[0]);
}
function strTrim(str){
  str=str.replace(/(^\s*)|(\s*$)/g, "");
  if (str.length==0){
    return false;
  }
  return true;
}  
function validateTelepnone(Number){
    var stripped = Number.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
   if (isNaN(parseInt(stripped))){ 
     return false;
   }	 
   return true;
} 
 
function checkForm(){



 // Full_Name;Job_Title;Company;Industry;Country;Email;Phone_Mobile;WebSite;Address_street;Address_city;Zip_code;How_did_you_hear_about_Cnario;message

   if( !strTrim(document.all['First_Name'].value)) {
   alert('Please, fill in First Name');
	document.all['First_Name'].focus();
    return false;
  }
	  if( !strTrim(document.all['Last_Name'].value)) {
   alert('Please, fill in Last Name');
	document.all['Last_Name'].focus();
    return false;
  }
  if( !strTrim(document.all['Job_Title'].value)) {
  alert('Please, fill in Job Title');
	document.all['Job_Title'].focus();
    return false;
  }
  if( !strTrim(document.all['Company'].value)) {
    alert('Please, fill in Company');
	document.all['Company'].focus();
    return false;
  }

	if( !strTrim(document.all['Country'].value)) {
    alert('Please Choose a Country');
	document.all['Country'].focus();
    return false;
  }
	if( !validateEmail(document.all['Email'].value)) {
    alert('Please, fill in Email');
	document.all['Email'].focus();
    return false;
  }


  return true;
}


function checkFormbp(){

//First_Name;Last_Name;Company;Position;Phone_Number;Fax_Number;Email;Website;Country;Address_city;State_Province;Zip_Postal;Address;Partnership_Type;How_did_you_hear_about_Cnario;use_C-nario;Comments;
// Full_Name;Job_Title;Company;Industry;Country;Email;Phone_Mobile;WebSite;Address_street;Address_city;Zip_code;How_did_you_hear_about_Cnario;message
 
   if( !strTrim(document.all['First_Name'].value)) {
   alert('Please, fill in First Name');
	document.all['First_Name'].focus();
    return false;
  }
	  if( !strTrim(document.all['Last_Name'].value)) {
   alert('Please, fill in Last Name');
	document.all['Last_Name'].focus();
    return false;
  }
  if( !strTrim(document.all['Company'].value)) {
  alert('Please, fill in Company Name');
	document.all['Company'].focus();
    return false;
  }
  if( !strTrim(document.all['Title'].value)) {
    alert('Please, fill in Title');
	document.all['Title'].focus();
    return false;
  }


	if( !validateEmail(document.all['Email'].value)) {
    alert('Please, fill in Email');
	document.all['Email'].focus();
    return false;
  }
	if( !strTrim(document.all['Country'].value)) {
    alert('Please Choose a Country');
	document.all['Country'].focus();
    return false;
  } 
		if( !strTrim(document.all['Address_city'].value)) {
    alert('Please Choose a City');
	document.all['Address_city'].focus();
    return false;
  }
	
  return true;
}

function SendContactForm(){

//First_Name;Last_Name;Company;Position;Phone_Number;Fax_Number;Email;Website;Country;Address_city;State_Province;Zip_Postal;Address;Partnership_Type;How_did_you_hear_about_Cnario;use_C-nario;Comments;
// Full_Name;Job_Title;Company;Industry;Country;Email;Phone_Mobile;WebSite;Address_street;Address_city;Zip_code;How_did_you_hear_about_Cnario;message
 if( !strTrim(document.all['RecipientName'].value)) {
   alert('Please, fill in Recipient Name');
	document.all['RecipientName'].focus();
    return false;
  }
 
 	if( !validateEmail(document.all['to'].value)) {
    alert('Please, fill in Recipient Email');
	document.all['to'].focus();
    return false;
  }
 
   
	  if( !strTrim(document.all['FromName'].value)) {
   alert('Please, fill in your Name');
	document.all['FromName'].focus();
    return false;
  }
 	if( !validateEmail(document.all['email'].value)) {
    alert('Please, fill in your Email');
	document.all['email'].focus();
    return false;
  }


 return true;
}
function checkFormsalesf(){

//First_Name;Last_Name;Company;Position;Phone_Number;Fax_Number;Email;Website;Country;Address_city;State_Province;Zip_Postal;Address;Partnership_Type;How_did_you_hear_about_Cnario;use_C-nario;Comments;
// Full_Name;Job_Title;Company;Industry;Country;Email;Phone_Mobile;WebSite;Address_street;Address_city;Zip_code;How_did_you_hear_about_Cnario;message
 
   if( !strTrim(document.all['first_name'].value)) {
   alert('Please, fill in First Name');
	document.all['first_name'].focus();
    return false;
  }
	  if( !strTrim(document.all['last_name'].value)) {
   alert('Please, fill in Last Name');
	document.all['last_name'].focus();
    return false;
  }
  
	if( !validateEmail(document.all['email'].value)) {
    alert('Please, fill in Email');
	document.all['email'].focus();
    return false;
  }
	
	if( !strTrim(document.all['company'].value)) {
  alert('Please, fill in Company Name');
	document.all['company'].focus();
    return false;
  }
  	if( !strTrim(document.all['city'].value)) {
    alert('Please Choose a City');
	document.all['city'].focus();
    return false;
  }
	
	if( !strTrim(document.all['title'].value)) {
    alert('Please, fill in Title');
	document.all['title'].focus();
    return false;
  }


	
	if( !strTrim(document.all['country'].value)) {
    alert('Please Choose a Country');
	document.all['country'].focus();
    return false;
  } 
	
	
  return true;
}
