var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

var ns4 = (document.layers); 
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

// toggle visibility

function toggle( targetId ){
  if (document.getElementById){
        target = document.getElementById( targetId );
           if (target.style.display == "none"){
              target.style.display = "";
           } else {
              target.style.display = "none";
           }
     }
}


function Attach(id)
{
	var obj
	if(ns4) obj = document.layers[id];
	else if(ie4) obj = document.all[id];
	else if(ie5 || ns6) obj = document.getElementById(id);
	return obj
}

function AddFavorite(pid, object)
{
	var add_url = 'http://dev2.indianmatrimonials.com:9888/index.cfm?method=favorite.remoteAdd&profile_id='+pid+'&object='+object;
	//var add_url = 'http://127.0.0.1/wcapps_v5/wwwroot/index.cfm?method=favorite.remoteAdd&profile_id='+pid+'&object='+object;
	LoadXmlDoc(add_url);
}

function ToggleCheckboxes(field)
{
	var i = 0;
	var form_obj = field.form;
	while (form_obj[i].type == 'checkbox') {
		if (form_obj[i].name != 'checkall') {
			form_obj[i].checked = field.checked;
		}
		i++;
	}
}

var req;

function LoadXmlDoc(url) {
	
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = ProcessRequestChange;
		req.open('GET', url, true, 'wcdev', 'v017IQzX#!');
		req.send(null);
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = ProcessRequestChange;
			req.open("GET", url, true, "", "");
			req.send();
		}
	}
}

function ProcessRequestChange() {

	//alert(req.readySate);
	
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK" 
		if (req.status == 200) {
			
			//alert('200 OK');
			//alert(req.documentElement);
			response = req.responseXML.documentElement;
			message = response.getElementsByTagName('message')[0].firstChild.data;
			inner_html = response.getElementsByTagName('inner_html')[0].firstChild.data;
			object_id = response.getElementsByTagName('object_id')[0].firstChild.data;
			
			tmp = Attach('ajax_box');
			tmp.className = 'error_box';
			tmp.innerHTML = message;
		
			t2 = Attach(object_id);
			t2.innerHTML = inner_html;
			
	
		} else {
			alert("There was a problem retrieving the XML data:\n" +
			req.statusText);
		}
	}
}

function redirect(){
	document.forms[0].submit();
}


function backButtonOverride()
{
  // Work around a Safari bug
  // that sometimes produces a blank page
  setTimeout("backButtonOverrideBody()", 1);

}

function backButtonOverrideBody()
{
  // Works if we backed up to get here
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  // Every quarter-second, try again. The only
  // guaranteed method for Opera, Firefox,
  // and Safari, which don't always call
  // onLoad but *do* resume any timers when
  // returning to a page
  setTimeout("backButtonOverrideBody()", 500);
}
/* This script is written by Eric (webcrawl@usa.net)
For full source code, installation instructions,
100's more JavaScripts and Terms of Use, visit
dynamicdrive.com */
function PrintPage() {
   if (navigator.appName == "Netscape") {
       window.print();
   } else {
       try {
           var webBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </OBJECT>';
           document.body.insertAdjacentHTML('beforeEnd', webBrowser);
           WebBrowser1.ExecWB(6,2);
           //Use a 1 vs. a 2 for a prompting dialog box
           WebBrowser1.outerHTML = "";
       } catch(e) {
           window.location.reload();
           // Or the button will never work again!
           // This fixes a bug in IE5.x
       }
   }
}


function keyDownHandler() {
	if(event.keyCode==13) submitForm();
}


function anyOrNone (checkbox) {

	if (checkbox.id != checkbox.name + "0") {
		$(checkbox.name + "0").checked = false;
		}
	else if (checkbox.checked) {
		foundLimit = false;
		i = 1;
		while (i < 10) {
			try {
				$(checkbox.name + i).checked = false;
				}
			catch(err) {
				foundLimit = true;
				}
			i = i + 1;
			}		
		}
	}

var invalidFieldExists = false;	

function checkRequired () {
	/*******************
	You use this function to check to see if required elements on a form have been filled in.
	
	How do you know what elements?  There is an array called reqArray, and you add the element information to it like so...
	
	<script>
		if (!reqArray) var reqArray = new Array(); //Make sure array exists
		var rArray = new Array(); //Create new array to append to parent array
		rArray[0] = "#attributes.name#"; // ID of element to be checked
		rArray[1] = ""; // If the value is equal to this, then it is considered not filled in, and will be flagged
		rArray[2] = "#attributes.name#_div"; //optional...if you don't want to make the element red, or it's not possible, you can specify what you do want to be made red
		reqArray[reqArray.length] = rArray;	//add element array to parent array
	</script>
	
	Returns true or false, and will change the background color of the element to get the user's attention
	
	*******************/
	retval = 1;
	
	for (i = 0; i < reqArray.length; i++) {
		if ($(reqArray[i][0]).value == reqArray[i][1]) {
			retval = 0;
			if (reqArray[i][2]) {	
				$(reqArray[i][2]).style.background = "#ffa6a6";
				}
			else {
				$(reqArray[i][0]).style.background = "#ffa6a6";			
				}
			}
		else {
			if (reqArray[i][2]) {	
				$(reqArray[i][2]).style.background = "";
				}
			else {
				$(reqArray[i][0]).style.background = "";			
				}
			}		
	

		if (invalidFieldExists) {
			retval = 0;
			}
		}
	
	return retval;
	}	

	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	
	
	function isDate(dtStr){
		/*******************
		Validates dates, allowing empty strings to pass
		*******************/
		
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(0,pos1)
		var strDay=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		if (pos1==-1 || pos2==-1){
			//alert("The date format should be : mm/dd/yyyy")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			//alert("Please enter a valid month")
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			//alert("Please enter a valid day")
			
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			//alert("Please enter a valid date")
			return false
		}
		
		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++){   
	        var c = s.charAt(i);
	        if (bag.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}
	
	function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
	    // EXCEPT for centurial years which are not also divisible by 400.
	    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
			} 
		return this
		}
		
	function isInteger(val){
		if (isBlank(val)){return true;}
		for(var i=0;i<val.length;i++){
			if(!isDigit(val.charAt(i))){return false;}
			}
		return true;
		}	
		
	function isBlank(val){
		if(val==null){return true;}
		for(var i=0;i<val.length;i++) {
			if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
			}
		return true;
		}
	function isEmail(val)
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(val)) return true;
		else return false;
	}
		
	function isDigit(num) {
		if (num.length>1){return false;}
		var string="1234567890";
		if (string.indexOf(num)!=-1){return true;}
		return false;
		}
		
	function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear){
		if(!isDate(p_Date1)){return "invalid date: '" + p_Date1 + "'";}
		if(!isDate(p_Date2)){return "invalid date: '" + p_Date2 + "'";}
		var dt1 = new Date(p_Date1);
		var dt2 = new Date(p_Date2);
	
		// get ms between dates (UTC) and make into "difference" date
		var iDiffMS = dt2.valueOf() - dt1.valueOf();
		var dtDiff = new Date(iDiffMS);
	
		// calc various diffs
		var nYears  = dt2.getUTCFullYear() - dt1.getUTCFullYear();
		var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
		var nQuarters = parseInt(nMonths/3);	//<<-- different than VBScript, which watches rollover not completion
		
		var nMilliseconds = iDiffMS;
		var nSeconds = parseInt(iDiffMS/1000);
		var nMinutes = parseInt(nSeconds/60);
		var nHours = parseInt(nMinutes/60);
		var nDays  = parseInt(nHours/24);
		var nWeeks = parseInt(nDays/7);
	
	
		// return requested difference
		var iDiff = 0;		
		switch(p_Interval.toLowerCase()){
			case "yyyy": return nYears;
			case "q": return nQuarters;
			case "m": return nMonths;
			case "y": 		// day of year
			case "d": return nDays;
			case "w": return nDays;
			case "ww":return nWeeks;		// week of year	// <-- inaccurate, WW should count calendar weeks (# of sundays) between
			case "h": return nHours;
			case "n": return nMinutes;
			case "s": return nSeconds;
			case "ms":return nMilliseconds;	// millisecond	// <-- extension for JS, NOT available in VBScript
			default: return "invalid interval: '" + p_Interval + "'";
		}
}			
/***********************************************************************/


