
function valid_contact() {

	var frm = document.contact;
	var mail=document.contact.contact_email.value;

	if (!IsValid(frm.contact_name.value,'Name')) { 

		frm.contact_name.focus(); return false; 

	}
	if (!IsValid(frm.contact_phone.value,'Phone')) { 

		frm.contact_phone.focus(); return false; 

	}

	if (!IsValid(frm.contact_email.value,'E-mail')) { 

		frm.contact_email.focus(); return false; 

	}
	if(mail!=''){
		var s=document.contact.contact_email.value;
		var i = 1,Length = s.length,result;
		if(s==""){
				alert("Email Address should not be Empty");
				document.contact.contact_email.focus();
			return false;
		}
		while((i<Length) && (s.charAt(i) != '@')) i++;
			if ((i == Length) || (s.charAt(i) != '@')){
				alert("Invalid Email Address");
				document.contact.contact_email.focus();
				return false;
			}
		i+=2;
		while((i<Length) && (s.charAt(i) != '.')) i++;
			if ((i == Length) || (s.charAt(i) != '.')){
				alert("Invalid Email Address");
				document.contact.contact_email.focus();
				return false;
			}
			if (i+1 >= Length){
				alert("Invalid Email Address");
				document.contact.contact_email.focus();
				return false;
			}
			
	}
	
	if (!IsValid(frm.contact_description.value,'Description')) { 

		frm.contact_description.focus(); return false; 

	}
	
	if (!IsValid(frm.security_code.value,'Verification code')) { 

		frm.security_code.focus(); return false; 

	}

	

}



function valid_quote() {

	var frm = document.quote;
	var mail=document.quote.qoute_email.value;

	if (!IsValid(frm.qoute_name.value,'Name')) { 

		frm.qoute_name.focus(); return false; 

	}
	if (!IsValid(frm.qoute_phone.value,'Phone')) { 

		frm.qoute_phone.focus(); return false; 

	}

	if (!IsValid(frm.qoute_email.value,'E-mail')) { 

		frm.qoute_email.focus(); return false; 

	}
	if(mail!=''){
		var s=document.quote.qoute_email.value;
		var i = 1,Length = s.length,result;
		if(s==""){
				alert("Email Address should not be Empty");
				document.quote.email.focus();
			return false;
		}
		while((i<Length) && (s.charAt(i) != '@')) i++;
			if ((i == Length) || (s.charAt(i) != '@')){
				alert("Invalid Email Address");
				document.quote.qoute_email.focus();
				return false;
			}
		i+=2;
		while((i<Length) && (s.charAt(i) != '.')) i++;
			if ((i == Length) || (s.charAt(i) != '.')){
				alert("Invalid Email Address");
				document.quote.qoute_email.focus();
				return false;
			}
			if (i+1 >= Length){
				alert("Invalid Email Address");
				document.quote.qoute_email.focus();
				return false;
			}
			
	}
	
	if (!IsValid(frm.qoute_description.value,'Description')) { 

		frm.qoute_description.focus(); return false; 

	}
	
	if (!IsValid(frm.security_code.value,'Verification code')) { 

		frm.security_code.focus(); return false; 

	}

	

}



function loadcountryimage(countrycode) {

	var countrycode = countrycode.toLowerCase();

	document.getElementById('countryflag').src = global_path+'images/flags/'+countrycode+'.gif'

}



function validate_security_code(security_code) {

	var success = function(t){validate_security_codeComplete(t);}	

	var failure = function(t){editFailed(t);}

	var url = global_path+"ajax.php";

	var pars = 'hdAction=Validate_security_code&security_code=' + security_code; 	

	var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});		

	document.getElementById("ErrorSpan").style.display = 'block';

	document.getElementById("ErrorSpan").innerHTML = '<img src="'+global_path+'images/dots-white.gif">';

	

}



function validate_security_codeComplete(t) {

	var txt = t.responseText;

	document.getElementById("ErrorSpan").style.display = 'block';

	document.getElementById("ErrorSpan").innerHTML = txt;

}



function EnterKeyPressed(e) {

	var characterCode = ''; // literal character code will be stored in this variable



	if(e && e.which){ //if which property of event object is supported (NN4)

		e = e

		characterCode = e.which //character code is contained in NN4's which property

	}	else	{

		e = event

		characterCode = e.keyCode //character code is contained in IE's keyCode property

	}

	

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)

		switch(action) {

			case 'memberlogin': 

				validatememberlogindetails();

				break;

		}

		return false;

	} else {

		return true;

	}	

}



function validate_new_visitor(this_form)

{

	with(this_form)

	{

		if(!IsEmpty(vname.value))

		{

			alert("Please enter your Name");

			vname.focus();

			return false;

		}

		if(!IsEmpty(email.value))

		{

			alert("Please enter your Email");

			email.focus();

			return false;

		}

		else if(!isEmailAddr(email.value,"Email"))

		{

			email.focus();

			return false;

		}

		if(!IsEmpty(phone.value))

		{

			alert("Please enter your Phone Number");

			phone.focus();

			return false;

		}

		

		if(country.value == "0")

		{

			alert("Please enter your Country");

			country.focus();

			return false;

		}

		

		submitform("new_visitor","add_new_visitor");

	}

}







/*______________________________________Common Functions___________________________________________________*/

function editFailed(t) {

	alert('ajax function failed'+t.responseText);

}





function IsEmpty(Val) {

    if(trim(Val)=="")

    {

        return false;

    }

    return true;	

}



function IsValid(Val,Label)

{

    if(trim(Val)=="")

    {

        alert(Label+" Should Not be Empty");

        return false;

    }

    return true;

}



var trim = function(Val)

{

    while(''+Val.charAt(0)==' ')

    Val=Val.substring(1,Val.length);

    return Val;

}



function IsNumber(sText,Label)

{

   var ValidChars = "0123456789-";

   var IsNumber=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsNumber == true; i++)     

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsNumber = false;

      }

   }

   if(!IsNumber)

       alert(Label+ " Must Be numeric")

   return IsNumber;

}





var IsVaildNumber = function(sText)

{

   var ValidChars = "0123456789-";

   var IsNumber=true;

   var Char;

   if(sText=="") 

   {

       IsNumber = false;

    }else{

       for (i = 0; i < sText.length && IsNumber == true; i++)     

       { 

          Char = sText.charAt(i); 

          if(ValidChars.indexOf(Char) == -1) 

          {

             IsNumber = false;

          }

       }

    }

    return IsNumber;

}

function IsAmount(sText)

{

   var ValidChars = "0123456789.";

   var IsAmount=true;

   var Char;

   if(sText=="") return false

   for (i = 0; i < sText.length && IsAmount == true; i++)     

   { 

         Char = sText.charAt(i); 

         if (ValidChars.indexOf(Char) == -1) 

         {

             IsAmount = false;

         }

   }

   return IsAmount;

}



function IsValidAmount(sText,Label)

{

    if(!IsAmount(sText))

    {

        alert("Invalid "+Label+".. "+Label+" Must Have Numeric Values")

        return false;

    }

    AmtArray = sText.split(".")

    if(AmtArray.length>2)

    {

        alert("Invalid "+Label+".. "+Label+" Must have single Period for Float")

        return false;

    }

    if(AmtArray.length>1)

    {

        FloatAmt = AmtArray[1];

        if(FloatAmt.length>2)

        {

            alert("Invalid "+Label+"..  Float Value must have two Digits")

            return false;

        }

    }

    return true

}



function isEmailAddr(email,Label) {

    

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){

return (true)

}

alert("Invalid "+Label+" Address! Please re-enter.")

return (false)

}





function IsValid(Val,Label)

{

    if(trim(Val)=="")

    {

        alert(Label+" Should Not be Empty");

        return false;

    }

    return true;

}



var trim = function(Val)

{

    while(''+Val.charAt(0)==' ')

    Val=Val.substring(1,Val.length);

    return Val;

}



function IsAlpha(sText,Label)

{

   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

   var IsValid=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsValid == true; i++) 

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsValid = false;

      }

   }

   if(!IsValid)

       alert("Invalid Characters found in "+Label);

   return IsValid;

}



function IsAlphaNumeric(sText,Label)

{

   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-";

   var IsValid=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsValid == true; i++) 

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsValid = false;

      }

   }

   if(!IsValid)

       alert("Invalid Characters found in "+Label);

   return IsValid;

}



function IsValidUserName(sText,Label)

{

   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_";

   var IsValid=true;

   var Char;

   if(sText=="") {alert(Label+ " Should not be Empty");return false}

   for (i = 0; i < sText.length && IsValid == true; i++) 

   { 

      Char = sText.charAt(i); 

      if(ValidChars.indexOf(Char) == -1) 

      {

         IsValid = false;

      }

   }

   if(!IsValid)

       alert("Invalid Characters found in "+Label);

   return IsValid;

}



function checkEnterValidateExistingSponsersUsername(e,sponsername){ //e is event object passed from function invocation

	var characterCode = ''; // literal character code will be stored in this variable



	if(e && e.which){ //if which property of event object is supported (NN4)

		e = e

		characterCode = e.which //character code is contained in NN4's which property

	}	else	{

		e = event

		characterCode = e.keyCode //character code is contained in IE's keyCode property

	}

	

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)

		if (sponsername.length < 4) return false;

		ValidateExistingSponsersUsername(sponsername); //submit the form

		return false;

	} else {

		return true;

	}

}



/*

 * Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or

 * they're the same, taking only the dates, not the time into account.

 * In other words, different times on the same date returns equal.

 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal

 */



function compareDatesOnly(date1, date2) {

	var year1 = date1.getYear();

	var year2 = date2.getYear();

	var month1 = date1.getMonth();

	var month2 = date2.getMonth();

	var day1 = date1.getDate();

	var day2 = date2.getDate();



	if (year1 > year2) {

		return -1;

	}

	if (year2 > year1) {

		return 1;

	}



	//years are equal

	if (month1 > month2) {

		return -1;

	}

	if (month2 > month1) {

		return 1;

	}



	//years and months are equal

	if (day1 > day2) {

		return -1;

	}

	if (day2 > day1) {

		return 1;

	}



	//days are equal

	return 0;



	/* Can't do this because of timezone issues

	var days1 = Math.floor(date1.getTime()/Date.DAY);

	var days2 = Math.floor(date2.getTime()/Date.DAY);

	return (days1 - days2);

	*/

}



function isNumber(val) {	

	var re = /^[0-9-'.'-',']*$/;

	if (!re.test(val)) return false; else return true;

}



function OpenAddSupport_queryWindow(ticketid) {

	AddNew_popupwindow=dhtmlmodal.open('AddNewSupportQueryWindow', 'ajax', 'index.php?op=supportView&action=newQuery&ticketId='+ticketid, '', 'width=580px,height=370px,center=1,resize=0,scrolling=1'); 	

}



function validatesupport_frm1(objform)

{

	alert("hi");

   /* var valid=true;

	var st1=document.new_queryticket.query_message.value;

	if(st1=='')

	{

	  alert("Message Should Not Empty");

	  document.new_queryticket.query_message.focus();

	  valid=false;

	}

	return valid;*/

 }

function LoadTinyEditor() {

	tinyMCE.init({

	// General options

	mode : "textareas",

	theme : "simple",

	 

	// Example content CSS (should be your site CSS)

	content_css : "css/example.css",

	 

	// Drop lists for link/image/media/template dialogs

	template_external_list_url : "js/template_list.js",

	external_link_list_url : "js/link_list.js",

	external_image_list_url : "js/image_list.js",

	media_external_list_url : "js/media_list.js",

	 

	// Replace values for the template plugin

	template_replace_values : {

	username : "Some User",

	staffid : "991234"

	}

	});

	

}



function validate_queryWindow() {

	var frm = document.new_queryticket;	

	if (!IsValid(tinyMCE.get('query_message').getContent(),'Message')) { tinyMCE.get('query_message').focus(); return false; }	

}



function validate_adminreplay()

{

  	if (!IsValid(tinyMCE.get('query_message').getContent(),'Message')) { tinyMCE.get('query_message').focus(); return false; }

}

function validate_representative_voucher() {

	var frm = document.rep_frm;	
	if (!IsValid(frm.email.value,'Email')) { 
		frm.email.focus(); 
		return false;
		}	else {
			if (!isEmailAddr(frm.email.value,'Email')) { frm.email.focus(); return false;}	
		}
	if (!IsValid(frm.confirn_email.value,'Confirmation Email')) { 
		frm.confirn_email.focus(); 
		return false;
		}	else {
		if (!isEmailAddr(frm.confirn_email.value,'Email')) { 
			frm.confirn_email.focus(); return false;
		}	else { 
			if (frm.confirn_email.value != frm.email.value) { alert('Email and Confirmation Email Should be same.'); frm.confirn_email.focus();  return false; }

		}

	 }
    if (!IsValid(frm.firstName.value,'First Name')) { frm.firstName.focus(); return false; }
    if (!IsValid(frm.lastName.value,'Last Name')) { frm.lastName.focus(); return false; }
	if (!IsValid(frm.amount.value,'Amount')) { frm.amount.focus(); return false;}

//	frm.submit();	

}




