function trimme(str){		//replace white space
	return str.replace(/^\s+|\s+$/g,'');
}

//validate email address
function EmailValid(email){
	var RegExp = /^[\w._-]+@[\w._-]+\.[A-Za-z]{2,6}$/
	if(RegExp.test(email)){
		return true;
	}else{
		return false;
	}
}

//validate phone
function ValidPhone(aphone){
	var RegExp1 = /^[(]{1}[0-9]{1}[0-9]{2}[)]{1}[0-9]{3}-[0-9]{4}$/
	var RegExp2 = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/
	if(RegExp1.test(aphone) || RegExp2.test(aphone)){
		return true;
	}else{
		return false;
	}
}

// validate login form

function login_form_validate(){
	
	var login_name = trimme(document.loginform.username.value);
	var password = trimme(document.loginform.password.value);
	
	if(login_name == ""){	// username filed is null
		
		alert("please enter User Name");
		document.loginform.username.focus();
		return false;
		
	}
	
	if(password == ""){	//password field is null
		
		alert("please enter Password");
		document.loginform.password.focus();
		return false;
		
	}
	
	return true;
}

function keyword_form_validate(){		// user click search keyword find
	
	var keyword = trimme(document.keywordform.find_keyword.value);		//trim white spaces, if there
	
	if(keyword == ""){	// keyword filed is null
		
		alert("please enter Search Keyword (or) Business Name");
		document.keywordform.find_keyword.focus();
		return false;
		
	}
		
	return true;
}

function newsletter_form_validate(){		// user click search keyword find
	var eSignage_http_object = null;
	var email = document.newsletterform.email_id.value;
	
	if(email == ""){	// keyword filed is null
		
		alert("please enter email address");
		document.newsletterform.email_id.focus();
		return false;
		
	}else{
		if(!EmailValid(email)){		//check whether email is valid
			alert("please enter valid email address");
			document.newsletterform.email_id.focus();
			return false;
		}else{
			var url="admin_profile_activate_update.php";	// file name
			var poststr="nl=1&arg1="+email;
			if(typeof eSignage_http_object == 'object') eSignage_http_object = null;
	     	if (window.XMLHttpRequest){              //IE7 and mozilla
       			eSignage_http_object = new XMLHttpRequest();
 		 	}else if(window.ActiveXObject){	// IE <=6
  				eSignage_http_object = new ActiveXObject("Microsoft.XMLHTTP");	// to avoid the cache problem in IE
		 	}else{
				eSignage_http_object = null;	
		 	}
        	if (eSignage_http_object != null){
        		
         		eSignage_http_object.open("POST", url,true); // post method
            	// content type
            	eSignage_http_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  				eSignage_http_object.setRequestHeader("Content-length", poststr.length);
				eSignage_http_object.setRequestHeader("Connection", "close");
				if(navigator.appName == "Microsoft Internet Explorer"){	// IE
					// this fn will be called if web server response state changes from 1-4
        			eSignage_http_object.onreadystatechange = function(){
      					if (eSignage_http_object.readyState == 4 && eSignage_http_object.status == 200) {	//'4'  means we received response from webserver
       						var response = eSignage_http_object.responseText;
        					alert(response); 
        				}
        			}
				}else{	// Firefox,Safari
					eSignage_http_object.onload = function(){
        				if (eSignage_http_object.readyState == 4 && eSignage_http_object.status == 200) {	//'4'  means we received response from webserver
        					var response = eSignage_http_object.responseText;
        					alert(response);  
        				}
       				}
				}	
            	eSignage_http_object.send(poststr);	// send the parameter to web server
			}
		}
	}
	return false;
}

function forgotpasswd(){	// user click 'Forgot Password' link
		
	window.open("forgotpassword.php","", "width=580,height=550,left=30,top=30, scrollbars=yes");
}

function viewprofile(arg1,arg2){	//user click view profile link
			
	//window.open("profile.php?arg1="+arg1+"&arg2="+arg2,"", "width=765,height=650,left=30,top=30, scrollbars=yes");
	window.open("profile.php?arg1="+arg1+"&arg2="+arg2,"_top");
}

function feedback_form_validate(){		//validate feedback form
	
	var contact_name = trimme(document.feedback_form.contact_name.value);
	var contact_phone = trimme(document.feedback_form.contact_phone.value);
	var contact_email = trimme(document.feedback_form.contact_email.value);
	var message = trimme(document.feedback_form.message.value);
	
	if(contact_name == ""){	// username filed is null
		alert("please enter Contact Name");
		document.feedback_form.contact_name.focus();
		return false;
	}
	
	if(contact_phone != ""){
		if(!ValidPhone(contact_phone)){		//check whether phone# is valid
			alert("please enter valid Contact Phone");
			document.feedback_form.contact_phone.focus();
			return false;
		}
	}
	
	if(contact_email == ""){
		alert("please enter Contact Email");
		document.feedback_form.contact_email.focus();
		return false;
	}else{
		if(!EmailValid(contact_email)){		//check whether email is valid
			alert("please enter valid Contact Email");
			document.feedback_form.contact_email.focus();
			return false;
		}
	}
	
	if(message == ""){		//check whether message filed is null
		alert("please enter Message");
		document.feedback_form.message.focus();
		return false;
	}
	
	return true;
}

function contact_form_validate(){		//validate contact us form
	
	var company_name = trimme(document.contact_form.company_name.value);
	var contact_name = trimme(document.contact_form.contact_name.value);
	var contact_phone = trimme(document.contact_form.contact_phone.value);
	var contact_email = trimme(document.contact_form.contact_email.value);
	var message = trimme(document.contact_form.message.value);
	
	if(contact_name == ""){	// username filed is null
		alert("please enter Contact Name");
		document.contact_form.contact_name.focus();
		return false;
	}
	
	if(contact_phone != ""){
		if(!ValidPhone(contact_phone)){		//check whether phone# is valid
			alert("please enter valid Contact Phone");
			document.contact_form.contact_phone.focus();
			return false;
		}
	}
	
	if(contact_email == ""){
		alert("please enter Contact Email");
		document.contact_form.contact_email.focus();
		return false;
	}else{
		if(!EmailValid(contact_email)){		//check whether email is valid
			alert("please enter valid Contact Email");
			document.contact_form.contact_email.focus();
			return false;
		}
	}
	
	if(message == ""){		//check whether message filed is null
		alert("please enter Message");
		document.contact_form.message.focus();
		return false;
	}
	
	return true;
}
