// JavaScript Document
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

/**
 * Javascript Phone Number Validation (IE4+) & (NN4+)
The JavaScript has the following main functions:

Function checkInternationalPhone is used to verify if the given value is a possible valid international phone number : This function first removes all non-digit characters which are allowed in phone numbers. These delimiters are declared in the lines (found in the beginning of the code) :

var phoneNumberDelimiters = "()- " 
var validWorldPhoneChars = phoneNumberDelimiters + "+"

Now that all valid delimiters are removed we just check if the remaining value is an integer and that it has at least a certain number of digits (given by the variable 'minDigitsInIPhoneNumber').

Function ValidateForm is used to make sure that the phone number field is not blank and that it is a valid phone number on form submission
 */
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 7;
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function checkInternationalPhone(strPhone)
{
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

/**
 * Javascript E-mail Address Validation (IE4+) & (NN4+)
The JavaScript has two functions:
Function echeck is used to verify if the given value is a possible valid email address. This function thus simply makes sure the email address has one (@), atleast one (.). It also makes sure that there are no spaces, extra '@'s or a (.) just before or after the @. It also makes sure that there is atleast one (.) after the @.

Function ValidateForm is used to make sure that the email field is not blank and that it is a valid email address on form submission. 
*/
function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)
	{
	   alert("Invalid E-mail ID")
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	   alert("Invalid E-mail ID")
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		alert("Invalid E-mail ID")
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(" ")!=-1)
	{
		alert("Invalid E-mail ID")
		return false
	}
	return true					
}

/**
 * Javascript Show Modal Dialog Window
*/
function xShowModalDialog( sURL, vArguments, sFeatures )
{
	dFeatures = 'dialogHeight: 450px; dialogWidth: 450px; edge: Raised; center: Yes; help: Yes; resizable: No; status: off;';//default features
	modalWin = "";
	if (sURL==null||sURL=='')
	{
		alert ("Invalid URL input.");
		return false;
	}
	if (vArguments==null||vArguments=='')
	{
		vArguments='';
	}
	if (sFeatures==null||sFeatures=='')
	{
		sFeatures=dFeatures;
	}
	if (window.navigator.appVersion.indexOf("MSIE")!=-1)
	{
		var pval=window.showModalDialog ( sURL, vArguments, sFeatures );
		resubmit(pval);
		return false;
	}
	else
	{
		sFeatures = sFeatures.replace(/ /gi,'');
		aFeatures = sFeatures.split(";");
		sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,scrollbars=1,";
		for ( x in aFeatures )
		{
			aTmp = aFeatures[x].split(":");
			sKey = aTmp[0].toLowerCase();
			sVal = aTmp[1];
			switch (sKey)
			{
				case "dialogheight":
									sWinFeat += "height="+sVal+",";
									pHeight = sVal;
									break;
				case "dialogwidth":
									sWinFeat += "width="+sVal+",";
									pWidth = sVal;
									break;
				case "dialogtop":
									sWinFeat += "screenY="+sVal+",";
									break;
				case "dialogleft":
									sWinFeat += "screenX="+sVal+",";
									break;
				case "resizable":
									sWinFeat += "resizable="+sVal+",";
									break;
				case "status":
									sWinFeat += "status="+sVal+",";
									break;
				case "center":
									if ( sVal.toLowerCase() == "yes" )
									{
										sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+",";
										sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+",";
									}
									break;
			}
		}
		modalWin=window.open(String(sURL),"",sWinFeat);
		if (vArguments!=null&&vArguments!='')
		{
			modalWin.dialogArguments=vArguments;
		}
	}
}
function checkFocus()
{
	if (window.navigator.appVersion.indexOf("MSIE")==-1)
	{
		if (modalWin!=null && !modalWin.closed)
		{
			self.blur();
			modalWin.focus();
		}
	}
}
function resubmit(val)
{
	return true;
}

/** .................using Ajax implement........................ */
var xmlHttp
function pState(pval)
{ 	
	if(pval.length==0)
	{
		document.getElementById("pStateTD").innerHTML=""
		document.getElementById("pCityTD").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="AjxState.asp"
	url=url+"?cnt="+pval
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function pStateSearch(pval)
{ 	
	if(pval.length==0)
	{
		document.getElementById("pStateTD").innerHTML=""
		document.getElementById("pCityTD").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="AjxStateSearch.asp"
	url=url+"?cnt="+pval
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function stateChanged() 
{  
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		myString = new String(xmlHttp.responseText)
		rExp = /<br>/gi;
		document.getElementById("pStateTD").innerHTML=myString.substr(0,myString.search(rExp))
		document.getElementById("pCityTD").innerHTML=myString.substr(myString.search(rExp)+4)
	} 
} 
function pCity(pval)
{ 	
	if(pval.length==0)
	{
		document.getElementById("pCityTD").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="AjxCity.asp"
	url=url+"?st="+pval
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=cityChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function pCitySearch(pval)
{ 	
	if(pval.length==0)
	{
		document.getElementById("pCityTD").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="AjxCitySearch.asp"
	url=url+"?st="+pval
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=cityChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function cityChanged() 
{  
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("pCityTD").innerHTML=xmlHttp.responseText 
	} 
} 
function pCityJT(pval)
{ 	
	if(pval.length==0)
	{
		document.getElementById("pJainTemplesTD").innerHTML=""
		document.getElementById("pCityTD").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="AjxCityJT.asp"
	url=url+"?st="+pval
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=cityChangedJT
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function cityChangedJT() 
{  
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		myString = new String(xmlHttp.responseText)
		rExp = /<br>/gi;
		document.getElementById("pCityTD").innerHTML=myString.substr(0,myString.search(rExp))
		document.getElementById("pJainTemplesTD").innerHTML=myString.substr(myString.search(rExp)+4)
	} 
} 
function pJainTemples(pval)
{ 	
	if(pval.length==0)
	{
		document.getElementById("pJainTemplesTD").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="AjxJainTemples.asp"
	url=url+"?ct="+pval
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=JainTemplesChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function JainTemplesChanged() 
{  
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("pJainTemplesTD").innerHTML=xmlHttp.responseText 
	} 
} 
function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
// End  ajax Code
/**
Javascript Add to favorie or book mark the link or url of the page.
We store URL of sites by using my favorite or book mark feature. The URL of the site will be added to our favorite or bookmark links. We will use JavaScript function to do this. On clicking the link browser will open the window for conformation and adding the link to the list. Here is the function and below that the link to add the this site to your favorite list.
**/
function bookmark(purl,pfrmname,ptomname)
{
	bookmarkurl=purl;
	bookmarktitle="saathi.us: Saathi for your life. " + ptomname + "'s Profile"
	if (document.all)
	{
		window.external.AddFavorite(bookmarkurl,bookmarktitle)
		pAddFavourite(pfrmname,ptomname)
	}
}

function redirectTo(url){
	window.location.href=url
}

function goToPage(page){
document.form1.currentpage.value=page
document.form1.submit();
}
function goToSelPage(page,pval){
document.form1.currentpage.value=page;
document.form1.action=pval;
document.form1.submit();
}
function deleteRecord(){
	con=confirm("Are you sure want to delete selected record(s)?")
	if (con){
		document.form1.status.value="delete"
		document.form1.submit()
	}
	else{
	return false;
	}
}
function pSelAll(pcnt)
{	
	if (document.form1.pdel.checked == true)
	{
		for(var i=0; i<pcnt;i++)
		{   
			abc="delete"+i;
			//alert(document.getElementById(abc));
			document.getElementById(abc).checked = true;
		}
	}
	else
	{
		for(var i=0; i<pcnt;i++)
		{   
			abc="delete"+i;
			document.getElementById(abc).checked = false
		}
	}
}
function setpdel(pcnt)
{	
	if(document.form1.pdel.checked==true)
	{	
		for(var i=0; i<pcnt;i++)
		{   
			abc="delete"+i;
			//alert(document.getElementById(abc));
			if(document.getElementById(abc).checked == false)
			{	
				//alert(true);
				document.form1.pdel.checked=false
				return;
			}
		}	
	}
}
function isEmpty(txtbox,msgStr)
{
	if (txtbox == null)
	{
		alert("Object not found !");
		return false;
	}
	if(txtbox.value == "" )
	{
		if (msgStr != "") alert("'"+ msgStr + "' field is blank.\nPlease enter a value for '"+ msgStr + "' field !");
		txtbox.focus();
		return true;
	}
	return false;
}
function radioSelected(radioGrp,msg)
{
	for (var i=0;i <radioGrp.length;i++)
	{
		if (radioGrp[i].checked == true) return true;
	}
	if (msg != "")alert ("Please select a value for '" + msg +"' !");
	return false;
}
function PShowLocation(pval)
{	
	var othername= "Location";
	var otherfield = document.getElementById(othername); 
	if (pval=="0")
	{ 
	    otherfield.style.display = 'block';  
	}
	else
	{
		otherfield.style.display = 'none';  
	}
}