// JavaScript Document


/**
*	Function : validate Contact us form
*
*	@param : field_name - value
*	
**/
function validate_request_quote()
{
	
	var agency 	= document.request_quote.agency;
	var fname  		= document.request_quote.fname;
	var lname  		= document.request_quote.lname;
	var email 		= document.request_quote.email;
	var phone 		= document.request_quote.phone;
	var comments 	= document.request_quote.comments;
	var secury_code	= document.request_quote.captcha_input;
		
	var agencyRegxp = /^([a-zA-Z0-9-:,.&amp;()\s]+)$/;
	//var nameRegxp = /^([a-zA-Z0-9\.\s]+)$/;
	var nameRegxp  = /^([a-zA-Z\.\'\s]+)$/; 
	var emailRegxp = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
	//var phoneRegxp =/\(?\d{3,6}\)?[0-9 -]{6,10}(?: ?#\d{3,6})?/;
	var phoneRegxp = /^([0-9+\-\/\s]+)$/;

	//var fullname = name.value.indexOf(" ");
		
	if ( agency.value == "" ) {	 // Agency
		alert("Please Enter Your Agency Name.");	
		document.request_quote.agency.focus();
		return false;
	}
	
	if ( agency.value.match(agencyRegxp) == null ) {        // Agency
		alert("Please enter valid Agency Name. Only alpha-numeric words and space accepted.");	
		document.request_quote.agency.focus();
		return false;
	}
	
	if ( fname.value == "" ) {	 // agency
		alert("Please Enter Your First Name.");	
		document.request_quote.fname.focus();
		return false;
	}
	
	if ( fname.value.match(nameRegxp) == null ) {	 // Name
		alert("Please enter valid First Name. Only alpha-numeric words and space accepted.");	
		document.request_quote.fname.focus();
		return false;
	}
	
	if ( lname.value == "" ) {	 // agency
		alert("Please Enter Your Last Name.");	
		document.request_quote.lname.focus();
		return false;
	}
	
	if ( lname.value.match(nameRegxp) == null ) {	 // Name
		alert("Please enter valid Last Name. Only alpha-numeric words and space accepted.");	
		document.request_quote.lname.focus();
		return false;
	}

	/*if( fullname.value == '-1'){
		alert("Please enter both valid First Name and Last Name.");	
		document.request_quote.name.focus();
		return false;
	}*/
	
	if ( email.value == "" ) {	 // Email
		alert("Please Enter Your E-mail Address.");	
		document.request_quote.email.focus();
		return false;
	}
	
	if ( email.value.match(emailRegxp) == null ) {               // Email
		alert("Please Enter Valid E-mail Address.");	
		document.request_quote.email.focus();
		return false;
	}
	
	if ( phone.value == "" ) {	 // Phone
		alert("Please Enter Your Phone Number.");	
		document.request_quote.phone.focus();
		return false;
	}
	else {
		if (ValidatePhone(phone)==false){
			return false	
		}
		
	}
	
	if ( comments.value == "" ) {          // Comment
		alert("Please Enter Your Comments.");	
		document.request_quote.comments.focus();
		return false;
	}
	
	if ( secury_code.value == '' ) {          // Secury Code
		alert("Please Enter The Characters As Displayed In The Image.");	
		document.request_quote.captcha_input.focus();
		return false;
	}
	
	return true;
		
  }
  
  
/**
*	Function : to open Div
*
*	@param : field_name - value
*	
**/
function open_div () {
	  document.getElementById('contact_div').style.display='';
}
  
  
// To check international phone nos 
function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}



/**
*	Function : to Reset the Form
*
*	@param : field_name - value
*	
**/
function resettip(){
		document.getElementById('reset').title="Reset:to reset the form";
}



/**
*	Function : to Validate Search Module
*
*	@param : field_name - value
*	
**/
function valid_search(){
	var q = document.qs.q.value;
	
	if ( q == '' ) {	 // Search text
		alert("Please Enter Search Keyword.");	
		document.qs.q.focus();
		return false;
	}
	if( q.length < 3 || q.length > 20 ){
		alert("Search keyword must be minimum of 3 characters and maximum of 20 characters.");	
		document.qs.q.focus();
		return false;
	}
}


/**
*	Function : to Validate Forward to Friend form
*
*	@param : field_name - value
*	
**/
function validate_friendForm()
{
	var friend_email = document.emailToFrind.friend_email.value;
	var from_email = document.emailToFrind.from_email.value;
	
	var emailRegxp = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
		
	if ( friend_email == "" ) {	 // To email
		alert("To: Please Enter Valid E-mail Address.");	
		document.emailToFrind.friend_email.focus();
		return false;
	}
	
	if ( from_email.match(emailRegxp) == null ) {        // From Email
		alert("From: Please Enter Valid E-mail Address.");	
		document.emailToFrind.from_email.focus();
		return false;
	}
	return true;
  }

/**
*	Function : for Search module
*
*	@param : field_name - value
*	
**/
function clearTxt(frmObj) {

	var search_txt = frmObj.q;
	
	if(search_txt.value == 'Keyword'){
		search_txt.value = '';
	}
}


/**
*	Function : validate Contact us form
*
*	@param : field_name - value
*	
**/
function validate_careerForm(frmObj)
{
	var name  	= frmObj.name.value;
	var email 	= frmObj.email.value;
	var resume 	= frmObj.resume.value;
		
	var nameRegxp = /^([a-zA-Z\s]+)$/;
	var emailRegxp = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
	var fileextension = new Array(11) ;
		fileextension[0] = "doc"; 
		fileextension[1] = "docx"; 
		fileextension[2] = "pdf";
	// Name
	if ( name.match(nameRegxp) == null ) {	 
		alert("Please Enter Your Name.");	
		frmObj.name.focus();
		return false;
	}
	// Email
	if ( email.match(emailRegxp) == null ) {               
		alert("Please Enter Valid E-mail Address.");	
		frmObj.email.focus();
		return false;
	}
	// File Upload
	if(resume.value == "") {
		alert( "Please Upload Your Resume." );
		frmObj.resume.focus();
		return false;
	} else if (resume.value != "" && !validateFileUpload(resume, fileextension)){
		alert("Please submit a Microsoft Word or PDF version of your resume.\nSelect only .doc, .docx, .pdf file.") ;
		frmObj.focus();
		return false;
	}
	return true;
		
  }


function validateFileUpload(strValue, fileextension)
{
		var path = new String(strValue)
		fileExt  = path.substr(path.lastIndexOf(".")+1);
		fileExt  = fileExt.toLowerCase();
		
		var x = 0;
		chk = "false";

		for (x=0; x<11; x++) { 
			if(fileextension[x] == fileExt) {
				chk = "true";
				break;
			}
		} 
		
		if ( chk == "false" ) {
			 return false ;
		}
		else {  
			return true ; 
		}
}


function validate_careerForm2()
{
	var name  	= document.careerForm2.name.value;
	var email 	= document.careerForm2.email.value;
	var resume 	= document.careerForm2.resume.value;
		
	var nameRegxp = /^([a-zA-Z\s]+)$/;
	var emailRegxp = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
	var fileextension = new Array(11) ;
		fileextension[0] = "doc"; 
		fileextension[1] = "docx"; 
		fileextension[2] = "pdf";
	// Name
	if ( name.match(nameRegxp) == null ) {	 
		alert("Please Enter Your Name.");	
		document.careerForm2.name.focus();
		return false;
	}
	// Email
	if ( email.match(emailRegxp) == null ) {               
		alert("Please Enter Valid E-mail Address.");	
		document.careerForm2.email.focus();
		return false;
	}
	// File Upload
	if(resume.value == "") {
		alert( "Please Upload Your Resume." );
		document.careerForm2.resume.focus();
		return false;
	} else if (resume.value != "" && !validateFileUpload(resume, fileextension)){
		alert("Please submit a Microsoft Word or PDF version of your resume.\nSelect only .doc, .docx, .pdf file.") ;
		document.careerForm2.resume.focus();
		return false;
	}

	return true;
		
  }

  // JavaScript Document

function CreateBookmarkLink()
 {

	var title = "ZEON SOLUTIONS Home"; 
	var url = window.location;
	if (window.sidebar)
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} 
	else if( window.external )
	{ // IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print) 
	{ // Opera Hotlist
		return true; 
	}
 }
 
 
function validate_downloadFrm()
{
	var email = document.frmDownload.email;
	var phone = document.frmDownload.phone;
	var agency = document.frmDownload.agency;
	var name = document.frmDownload.name;
	 
	//var nameRegxp  = /^([a-zA-Z\s]+)$/; 
	var nameRegxp  = /^([a-zA-Z\.\'\s]+)$/; 
	var companyRegxp = /^([a-zA-Z0-9-:,.&amp;()\s]+)$/;
	var phoneRegxp = /^([0-9+\-\/\s]+)$/;
	var emailRegxp = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
	
	if( (name.value == "") && (agency.value == "") && (phone.value == "") && (email.value == "") )
	{
		alert(" Please enter your Full Name.\n Please enter your Agency Name.\n Please Enter Your Contact Number.\n Please Enter Your Email Address. ");
		document.frmDownload.name.focus();
		return false;
	}
		
	if ( name.value == "" ) {	 // To name
		alert("Please enter your Full Name.");	
		document.frmDownload.name.focus();
		return false;
	}	
	if ( name.value.match(nameRegxp) == null ) {               
		alert("Please enter valid Full Name.");	
		document.frmDownload.name.focus();
		return false;
	}
	
	if ( agency.value == "" ) {	 // To comapny
		alert("Please enter your Agency Name.");	
		document.frmDownload.agency.focus();
		return false;
	}
	
	if ( phone.value == "" ) {	 // Phone
		alert("Please Enter Your Phone Number.");	
		document.frmDownload.phone.focus();
		return false;
	}
	else {
		if (ValidatePhone(phone)==false){
			return false	
		}
		
	}
	
	if ( email.value == "" ) {	 // To email
		alert("Please use correct e-mail format 'username@domain'.");	
		document.frmDownload.email.focus();
		return false;
	}	
	if ( emailCheck(email.value) == false ) {    
		document.frmDownload.email.focus();
		return false;
	}
	return true;
}


function emailCheck (emailStr) {

	var checkTLD=1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	
	var emailPat=/^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	
	var validChars="\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom=validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
	
	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */
	
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	   }
	}
	
	// See if "user" is valid 
	
	if (user.match(userPat)==null) {
	
	// user is not valid
	
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	
	// this is an IP address
	
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	   }
	}
	return true;
	}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	   }
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
	alert("Please use correct e-mail format 'username@domain'.");
	return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}
/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// 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 = 10;

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
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)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
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhone(Phone){
	//var Phone=document.request_quote.phone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }


