// JavaScript Document
/**
 * DHTML email validation script. Courtesy of vivekbhat.9k.com
 */
function clearname(id)
{
if(document.getElementById(id).value=='Name')
{
document.getElementById(id).value="";
}
}
function putname(id)
{
if(document.getElementById(id).value=='')
{
document.getElementById(id).value="Name";
}

}

function clearmobno(id)
{

if(document.getElementById(id).value=='Mobile No')
{
document.getElementById(id).value="";
}
}
function putmobileno(id)
{
if(document.getElementById(id).value=='')
{
document.getElementById(id).value="Mobile No";
}

}
function clearemail(id)
{

if(document.getElementById(id).value=='Email')
{
document.getElementById(id).value="";
}
}
function putemail(id)
{
if(document.getElementById(id).value=='')
{
document.getElementById(id).value="Email";
}

}
function clearprovidecomment(id)
{

if(document.getElementById(id).value=='Provide Comment')
{
document.getElementById(id).value="";
}
}
function putprovidecomment(id)
{
if(document.getElementById(id).value=='')
{
document.getElementById(id).value="Provide Comment";
}

}
var passwordLength = 8;
var addressLength = 300;
var mainObjectiveLength = 300;
var informationLength = 300;
var summaryLength = 300;
var noteLength = 300;
var searchLength = 5;
var checkFlag = false;

function ismaxlength(obj,mlength){
//var mlength=300;
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}


 


function checkKey() 
{ 
	var key = event.keyCode; 
	if (key == 13) { event.returnValue=false; } 
}

function onkeyPress(e)
{
	var key = window.event ? e.keyCode : e.which;
	if (key == 13 || key == 0 || key == 27)
	StartClick();
	e.cancelBubble = true;
	e.returnValue = false;
	return false;
}

function IsSpace(txtField,len,message)
{
	sText = txtField.value;
	str = sText.substr(0,len);
	var charpos = str.indexOf(" ");
	if(charpos >= 0)
	{
		alert(message + "\n [Error character position " + eval(charpos+1)+"]");
		txtField.focus();
		return false;
	}
	return true;
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function IsBlank(txtField,message)
{	
	var txtValue = txtField.value;	
	txtValue = trimAll(txtValue);
	if( (txtValue == "") || (txtValue == null) )
	{		
		alert(message);
		txtField.focus();
		return false;
	}
	txtField.value = trimAll(txtValue);
	return true;
}

function minLength(txtField,len,message)
{
	if( txtField.value.length < len)
	{
		alert(message);
		txtField.focus();
		return false;
	}
	return true;
}

function maxLength(txtField,len,message)
{
	if( txtField.value.length > len)
	{
		alert(message);
		txtField.focus();
		return false;
	}
	return true;
}

function checkQuote(txtField,message)
{
	var sText = txtField.value;
	var quote = false;
	if(sText.indexOf("'") >= 0)
	{
		var charCount = sText.indexOf("'");
		for ( ; charCount < sText.length ; charCount++ )
		{
			if(sText.substring(charCount, charCount+1) == "'")
			{
				if(sText.substring(charCount+1, charCount+2) == "'")
					quote = true;
				else
					quote = false;
			}
			
			if(quote)
			{
				alert(message);
				txtField.focus();
				return false;
			}
		}
	}
	return true;
}

function IsSpecialChar(txtField,message)
{
	sText = txtField.value;
	var charpos = sText.search("[^A-Za-z. ']");
	if(sText.length > 0 &&  charpos >= 0)
	{
		alert(message + "\n [Error character position " + eval(charpos+1) + "]");
		txtField.focus();
		return false;
	}
	return true;
}

function matchFields(txtField1,txtField2,message)
{
	if(txtField1.value != txtField2.value)
	{
		alert(message);
		txtField1.focus();
		return false;
	}
	else
		return true;
}

function isChecked(chkBox,message)
{
	var chkboxCount;
	if(chkBox[0] != null)
	{
		for( chkboxCount = 0; chkboxCount < chkBox.length; chkboxCount++)
		{
			if(chkBox[chkboxCount].checked)
				return true;
		}
	}
	else
	{
		if(chkBox.checked)
			return true;
	}
	alert(message);
	return false;
}

function isCheckedOne(chkBox,message)
{
	var chkboxCount,flag=false;
	if(chkBox[0] != null)
	{
		for( chkboxCount = 0; chkboxCount < chkBox.length; chkboxCount++)
		{
			if(chkBox[chkboxCount].checked)
			{
				if(!flag)
					flag=true;
				else
				{
					alert(message);
					return false;
				}
			}
		}
	}
	return true;
}

function unCheckAll(chkParentBox,chkBox)
{

var chkboxCount;
	if(chkBox[0] != null)
	{
		for( chkboxCount = 0; chkboxCount < chkBox.length; chkboxCount++)
		
		{
			chkBox[chkboxCount].checked = false;
		}
		chkParentBox.checked = false;
	}
	else
	{
		chkBox.checked = false;
	}
	chkParentBox.checked = false;
}

function checkAll(chkParentBox,chkBox)
{
	var chkboxCount, flip = chkParentBox.checked;
	if(chkBox[0] != null)
	{
		for( chkboxCount = 0; chkboxCount < chkBox.length; chkboxCount++)
		{
			chkBox[chkboxCount].checked = flip;
		}
	}
	else
	{
		chkBox.checked = flip;
	}
	return true;
}

function IsSelected(lstselect,message)	// check that atleast one item is selected
{
	if( lstselect.value == "" || lstselect.value == null )
	{
		alert(message);
		lstselect.focus();
		return false;
	}
	else
		return true;
}

function echeck(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var message = "Please type e-mail address in the following format: yourname@example.com.";
	if (str.indexOf(at)==-1)
	{
              return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
            return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
            return false;
	}

	if (str.indexOf(at,(lat+1))!=-1)
	{
            return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
             return false;
	}

	if (str.indexOf(dot,(lat+2))==-1)
	{
               return false;
	}
		
	if (str.indexOf(" ")!=-1)
	{
               return false;
	}

	return true;
}

function validateEmail(txtEmail)
{

	var emailID = txtEmail.value;
	
	if ( (emailID == null) || (emailID == "") )
	{
		alert("Please type your email id.");
		txtEmail.focus();
		return false;
	}
	if ( echeck(emailID) == false )
	{
		alert("Please type e-mail address in the following format: yourname@example.com.");
                txtEmail.focus();
		return false;
	}
	return true;
}

function validatePhoneNumber(txtPhone,message)
{
	var TheNumber = txtPhone.value; // xxxxx-xxx-xxxx
	var charpos = TheNumber.search("[^+0-9 ]");
	if( charpos >= 0 )
	{
		alert(message);
		txtPhone.focus();
		return false;
	} // End if statement

	var digitCounter=0, i=0;
	for( i=0; i<TheNumber.length; i++)
	{
		var digit = TheNumber.charAt(i);
		if((digit >= "0") && (digit <= "9"))
			digitCounter++;
	}
	
	if( digitCounter != 10 )
	{
		alert("Please type valid phone number (+xxxxxxxxxx)");
		
		txtPhone.focus();
		return false;
	}

	if(TheNumber.indexOf("+")!= -1)
	{
		if(TheNumber.lastIndexOf("+") > 0)
		{
			alert("Please type valid phone number (+xxxxxxxxxx)");
			txtPhone.focus();
			return false;
		}
	}
	return true;
}

function validateMobileNumber(txtPhone,message)
{
	var TheNumber = txtPhone.value; // xxxxx-xxx-xxxx
	var charpos = TheNumber.search("[^+0-9 ]");
	if( charpos >= 0 )
	{
		alert(message);
        txtPhone.focus();
		return false;
	} // End if statement

	var digitCounter=0, i=0;
	for( i=0; i<TheNumber.length; i++)
	{
		var digit = TheNumber.charAt(i);
		if((digit >= "0") && (digit <= "9"))
			digitCounter++;
	}
	
	if( digitCounter != 10 )
	{
		var errorId = document.getElementById(id);
		alert("Please type valid mobile number (+xxxxxxxxxx)");
		
		txtPhone.focus();
		return false;
	}

	if(TheNumber.indexOf("+")!= -1)
	{
		if(TheNumber.lastIndexOf("+") > 0)
		{
			alert("Please type valid mobile number (+xxxxxxxxxx)");
			txtPhone.focus();
			return false;
		}
	}
	return true;
}

function validateZipCode(txtZipCode,id,message)
{
	var TheNumber = txtZipCode.value;

	var charpos = TheNumber.search("[^0-9]");
	if( charpos >= 0 )
	{
		var errorId = document.getElementById(id);
		hideAllErrors();
		errorId.innerHTML = '<img src="images/vista-error-icon_4309.jpg" height="20px" width="20px" alt="" />&nbsp;'+message;
		errorId.style.display = "inline";
		txtZipCode.focus();
		return false;
	} // End if statement

	if(TheNumber.length != 6)
	{
		var errorId = document.getElementById(id);
		hideAllErrors();
		errorId.innerHTML = '<img src="images/vista-error-icon_4309.jpg" height="20px" width="20px" alt="" />&nbsp;'+"Please type valid zip code (xxxxxx)";
		errorId.style.display = "inline";
		txtZipCode.focus();
		return false;
	}

	return true;
}

function urlValidator(url,id,message){
	var urlText = url.value;
	if(urlText.toString().match(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/)){
		return true;
	}else{
		alert('a1')
		var errorId = document.getElementById(id);
		hideAllErrors();
		errorId.innerHTML = '<img src="images/vista-error-icon_4309.jpg" height="20px" width="20px" alt="" />&nbsp;'+message;
		errorId.style.display = "inline";
		url.focus();
		return false;
	}
}

function ajaxFunction(){

	var ajaxRequest;  // The variable that makes Ajax possible!


		// Opera 8.0+, Firefox, Safari
	ajaxRequest = GetXmlHttpObject();
	if (ajaxRequest==null)
          {
          alert ("Your browser does not support AJAX!");
          return;
          }
          var txtName = document.getElementById('txtName').value;
          var txtStdCode = document.getElementById('txtStdCode').value;
	var txtPhone = txtStdCode+document.getElementById('txtPhone').value;
	var txtEmail = document.getElementById('txtEmail').value;
        var txtEnquiry = document.getElementById('txtEnquiry').value;
	var queryString = "txtName=" + txtName + "&txtPhone=" + txtPhone + "&txtEmail=" + txtEmail+ "&txtEnquiry=" + txtEnquiry;
	ajaxRequest.open("POST", "ajaxConsult.jsp", true);
        ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	ajaxRequest.send(queryString);
       
}
        function GetXmlHttpObject()
            {
            if (window.XMLHttpRequest)
              {
              // code for IE7+, Firefox, Chrome, Opera, Safari
              return new XMLHttpRequest();
              }
            if (window.ActiveXObject)
              {
              // code for IE6, IE5
              return new ActiveXObject("Microsoft.XMLHTTP");
              }
            return null;
            }
	// Create a function that will receive data sent from the server
	function stateChanged()
        {
        if (ajaxRequest.readyState==4)
          {
          document.getElementById("txtName").innerHTML=xmlhttp.responseText;
          }
        }