// JavaScript Document


/**
*	Function : validate Contact us form
*
*	@param : field_name - value
*	
**/
function validate_contact_us()
{
	
	var first_name = document.contact_us.first_name.value;
	var title = document.contact_us.title.value;
	var email = document.contact_us.email.value;
	var phone = document.contact_us.phone.value;
		
	//var first_nameRegxp = /^([a-zA-Z\s]+)$/;
	var first_nameRegxp = /^([a-zA-Z\.\'\s]+)$/;
	var titleRegxp = /^([a-zA-Z0-9-:,.&amp;()\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]+)$/;
		
	
	if ( first_name.match(first_nameRegxp) == null ) {	 // First Name
		alert("Please enter valid First Name. \nOnly a-z A-Z space allowed.");	
		document.contact_us.first_name.focus();
		return false;
	}
	
	/*if ( title.match(titleRegxp) == null ) {        // Job Title
		alert("Please enter valid Job Title \nOnly a-zA-Z0-9-:,.&amp; () space allowed.");	
		document.contact_us.title.focus();
		return false;
	}*/
	
	if ( email.match(emailRegxp) == null ) {               // Email
		alert("Please enter valid Email Address");	
		document.contact_us.email.focus();
		return false;
	}
	
	if ( phone.match(phoneRegxp) == null ) {          // Phone
		alert("Please enter valid Phone Number \nOnly 0-9 - + / space allowed.");	
		document.contact_us.phone.focus();
		return false;
	}
  }
  
  
/**
*	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";
}



/**
*	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 string.");	
		document.qs.q.focus();
		return false;
	}
	if( q.length < 3 || q.length > 20 ){
		alert("Search string must be minimum of 3 characters and maximum of 20 characters.");	
		document.qs.q.focus();
		return false;
	}
}

/**
 *
 * Function : This function is used to trim the text (white spaces) from the LEFT and RIGHT side of the text.
 * 
 */
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

/**
*	Function : to Validate Forward to Friend form
*
*	@param : field_name - value
*	
**/
function validate_friendForm()
{
	//var friend_email = document.fwdtofrdform.friend_email.value;
	var friend_email = document.getElementById('friend_email').value;

	var from_email = document.fwdtofrdform.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 Email Address.");	
		document.fwdtofrdform.friend_email.focus();
		return false;
	}
	var emails = friend_email.split(",");
	var isValid = false;
	for(var i = 0; i < emails.length; i++)
	{
	    var email = emails[i].trim();
		if (email.match(emailRegxp) == null ) 
		{
			isValid = true;
			break;
		}
	}
	if(isValid ) 
	{
		alert("To: Please enter valid Email Address");
		document.fwdtofrdform.friend_email.focus();
		return false;
	
	}
	if ( from_email.match(emailRegxp) == null ) {        // From Email
		alert("From: Please enter valid Email Address");	
		document.fwdtofrdform.from_email.focus();
		return false;
	}
 }

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

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



