function emptyerrspan()
{
	document.getElementById('err_span').innerHTML ="Fields marked with asterisk (*) are mandatory";
}
/*------------------------------------------------------------*/
function validate_sendmail()
{
	
	var emailobj = document.getElementById('mail_txt');
	var phoneobj = document.getElementById('phone_txt');
	if(trimfun(document.getElementById('name_txt').value)=="" || trimfun(document.getElementById('name_txt').value)=="Name") { document.getElementById('err_span').innerHTML = "Name"; document.getElementById('name_txt').focus(); }
		else
		if(trimfun(document.getElementById('mail_txt').value)=="" || trimfun(document.getElementById('mail_txt').value)=="EMail ID") { document.getElementById('err_span').innerHTML = "Email"; document.getElementById('mail_txt').focus(); }		
			else
				if(validateEmail(emailobj,'err_span')==true)
				{
					
				if(trimfun(document.getElementById('sub_txt').value)=="" || trimfun(document.getElementById('sub_txt').value)=="Subject") { document.getElementById('err_span').innerHTML ="Subject"; document.getElementById('sub_txt').focus(); }
					else
						if(trimfun(document.getElementById('msg_txt').value)=="" || trimfun(document.getElementById('msg_txt').value)=="Message") { document.getElementById('err_span').innerHTML ="Message"; document.getElementById('msg_txt').focus(); }
							else								
								{
									document.getElementById('err_span').innerHTML ="";
									sendmail();
								}
				}
	
}
function validate_clientmail()
{
	//name_txt comp_txt mail_txt phone_txt city_txt country_txt
	var emailobj = document.getElementById('mail_txt');
	var phoneobj = document.getElementById('phone_txt');
	
	if(trimfun(document.getElementById('name_txt').value)=="") { document.getElementById('err_span').innerHTML = "Name"; document.getElementById('name_txt').focus(); }
		else
		if(trimfun(document.getElementById('comp_txt').value)=="") { document.getElementById('err_span').innerHTML = "Company Name"; document.getElementById('comp_txt').focus(); }
			else
			if(trimfun(document.getElementById('mail_txt').value)=="") { document.getElementById('err_span').innerHTML = "Email"; document.getElementById('mail_txt').focus(); }		
				else
					if(validateEmail(emailobj,'err_span')==true)
					{						
						if(trimfun(document.getElementById('city_txt').value)=="") { document.getElementById('err_span').innerHTML ="City"; document.getElementById('city_txt').focus(); }
							else
								if(trimfun(document.getElementById('country_txt').value)=="") { document.getElementById('err_span').innerHTML ="Country"; document.getElementById('country_txt').focus(); }
									else								
										{
											
												document.getElementById('err_span').innerHTML ="";
												clientmail();
											
										}
					}
	
}
/*-----------------------------Number Validation----------------------*/
function validate_int(field,alerttxt) 
{
	
	var valid = "0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") 
	{
		document.getElementById(alerttxt).innerHTML="Field should be an Iteger Value";		
		return false;
		field.focus();
		//field.select();
		
		
	}
}
/*--------------------------End of the number validation------------------*/
function clientmail()
{
	//name_txt comp_txt mail_txt phone_txt city_txt country_txt
	var mailto='ashish@careernet.co.in';
	var mailfrom=document.getElementById('mail_txt').value;
	var phone=document.getElementById('phone_txt').value;
	var company=document.getElementById('comp_txt').value;
	var fromname=document.getElementById('name_txt').value;
	var city=document.getElementById('city_txt').value;
	var country=document.getElementById('country_txt').value;
	
	
	var url = "server.php";
	var myRequest = new ajaxObject(url, clientmail_action);
	var POSTDATA="action=clientmail&mailto="+encodeURIComponent(mailto)+"&mailfrom=" + encodeURIComponent(mailfrom)+"&phone="+encodeURIComponent(phone)+"&company="+encodeURIComponent(company)+"&fromname="+encodeURIComponent(fromname)+"&city="+encodeURIComponent(city)+"&country="+encodeURIComponent(country);
	myRequest.update(null, POSTDATA, 'post');
	
}
function sendmail()
{
	var mailto='ashish@careernet.co.in';
	var mailfrom=document.getElementById('mail_txt').value;
	var subject=document.getElementById('sub_txt').value;
	var message=document.getElementById('msg_txt').value;
	var phone=document.getElementById('phone_txt').value;
	var fromname=document.getElementById('name_txt').value;
	if(phone == "" || phone =="Contact No")
		phone="-";
		
	var url = "server.php";
	var myRequest = new ajaxObject(url, sendmail_action);
	var POSTDATA="action=sendmail&mailto="+encodeURIComponent(mailto)+"&mailfrom=" + encodeURIComponent(mailfrom)+"&subject="+encodeURIComponent(subject)+"&message="+encodeURIComponent(message)+"&fromname="+encodeURIComponent(fromname)+"&phone="+encodeURIComponent(phone);
	myRequest.update('err_span', POSTDATA, 'post');
		
}
//------
function clientmail_action(responseText, responseStatus, responseXML, divid)
{	
	if (responseStatus == 200) 
	{
		if(responseText ==1)
		 document.getElementById('err_span').innerHTML='Error Sending Message!';
		 else
		 document.getElementById('clientcontent').innerHTML='<div style=\"background:#eeeeee; padding:10px;\"><b>Thanks for signing up for our services.</b><br /><br />Our representative will contact you shortly to apprise you about the next steps.<br /><br />Looking forward to doing business with you<br /><br />Best regards,<br />HiRePro</div>';
	} 
	else 
	{alert(responseStatus);}		
}
function sendmail_action(responseText, responseStatus, responseXML, divid)
{	
	if (responseStatus == 200) 
	{document.getElementById(divid).innerHTML=responseText;} 
	else 
	{alert(responseStatus);}		
}
//------
function validate_required(field,txt,alerttxt)
{  
	with (field)
	{ 
	if (value==null||value==""||value==txt)
		{document.getElementById(alerttxt).style.border="#0ea0e5";return true}
	else 
		{document.getElementById(alerttxt).style.border="#0ea0e5";return false}
	}
}
//------
//////////////////////////////////////////////////////////////////////
function trimfun(str, chars) {
			return ltrim(rtrim(str, chars), chars);
			}
	
			function ltrim(str, chars) {
			chars = chars || "\\s";
			return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
			}
	
			function rtrim(str, chars) {
			chars = chars || "\\s";
			return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
			}	
			
			
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
////////////////////////////////////////////////////////////////////
function validateEmail(fld,alerttxt) 
{  
    var error="";
    var tfld = trim(fld.value);                 // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
   	if (!emailFilter.test(tfld)) {              //test email for illegal characters
		document.getElementById(alerttxt).innerHTML ="Invalid email address."; document.getElementById('mail_txt').select();
		//alert("Please enter a valid email address.\n");
		return false;
    } else if (fld.value.match(illegalChars)) {
		document.getElementById(alerttxt).innerHTML ="Illegal characters exist"; document.getElementById('mail_txt').select();
		//alert("The email address contains illegal characters.\n");
		return false;
    } else {
		document.getElementById(alerttxt).innerHTML ="";		
		return true;
    }
	
}

/////////////////////////////////////////////////////////////////////
function isURL(argvalue) {

  if (argvalue.indexOf(" ") != -1)
    return false;
  else if (argvalue.indexOf("http://") == -1)
    return false;
  else if (argvalue == "http://")
    return false;
  else if (argvalue.indexOf("http://") > 0)
    return false;

  argvalue = argvalue.substring(7, argvalue.length);
  if (argvalue.indexOf(".") == -1)
    return false;
  else if (argvalue.indexOf(".") == 0)
    return false;
  else if (argvalue.charAt(argvalue.length - 1) == ".")
    return false;

  if (argvalue.indexOf("/") != -1) {
    argvalue = argvalue.substring(0, argvalue.indexOf("/"));
    if (argvalue.charAt(argvalue.length - 1) == ".")
      return false;
  }

  if (argvalue.indexOf(":") != -1) {
    if (argvalue.indexOf(":") == (argvalue.length - 1))
      return false;
    else if (argvalue.charAt(argvalue.indexOf(":") + 1) == ".")
      return false;
    argvalue = argvalue.substring(0, argvalue.indexOf(":"));
    if (argvalue.charAt(argvalue.length - 1) == ".")
      return false;
  }

  return true;

}
