/*===========================================================================*/
// 20100509 AK added DecodeEMail, DecodeEMailString, obfuscate
// 20100223 AK added several validation routines
// 20100222 AK dropped in everything from mockupsite common.js, deleted older duplicate functions
// 20100127 AK new file
/*===========================================================================*/

// start mockupsite common.js code

/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
// Contents for menus
var menu1=new Array()
menu1[0]='<a href="whatis_whowehelp.aspx" class="cMenu1">Who We Help</a>'
menu1[1]='<a href="whatis_history.aspx" class="cMenu1">History</a>'
menu1[2]='<a href="whatis_faq.aspx" class="cMenu1">FAQ</a>'
menu1[3]='<a href="whatis_locations.aspx" class="cMenu1">Locations / Contact</a>'
menu1[4]='<div class="cMenu1bottom">&nbsp;</div>'
var menu2=new Array()
menu2[0]='<a href="join_welcome.aspx" class="cMenu2">Welcome</a>'
menu2[1]='<a href="join_volunteer.aspx" class="cMenu2">Be a Safe Family Volunteer</a>'
menu2[2]='<a href="join_church.aspx" class="cMenu2">Be a Safe Family Church</a>'
menu2[3]='<a href="join_guidelines.aspx" class="cMenu2">Safe Family Guidelines</a>'
menu2[4]='<div class="cMenu2bottom">&nbsp;</div>'
var menuwidth='300px' //default menu width
var menubgcolor='#FFFFFF'  //menu bgcolor
var disappeardelay=30  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
	dropmenuobj.widthobj=dropmenuobj.style
	dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
	obj.visibility=visible
else if (e.type=="click")
	obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
	var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
	dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
else {
	var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}

function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
	if (ie4||ns6)
		dropmenuobj.style.visibility="hidden"
	}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}
// ==============================================
function offMenuDelay(){
if (ie4||ns6)
delayhide=setTimeout("offMenu()",disappeardelay)
}
// ==============================================
function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// end mockupsite common.js code

//=====================================================================

function copyChange(elementName, intLimit) {
	var objControl = null;
	var intLength = 0;

	objControl = new getObj(elementName).obj;
	intLength = objControl.value.length;

	objControl = new getObj(elementName + 'AvailChars').obj;
	objControl.innerHTML = intLimit - intLength;
};

//=====================================================================

function doStyle(obj, sStyle) {
	obj.className=sStyle;
};

//=====================================================================

function trim(str) {
	// replace leading spaces, trailing spaces, and that pesky xml safe space (xa0 here) with nothing for further parsing
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '').replace(/\xa0/g, '');
};

//=====================================================================

function isEmpty(s) {
	return ((s == null) || (s.length == 0));
};

//=====================================================================

function addMessage(str) {
	if (message != '') {
		message += '\n';	
	};
	message += str;
};

//=====================================================================

function getObj(vstrControlID) {
	try {
		if (document.getElementById) {
			this.obj = document.getElementById(vstrControlID);
			this.style = document.getElementById(vstrControlID).style;
		}
		else if (document.all) {
			this.obj = document.all[vstrControlID];
			this.style = document.all[vstrControlID].style;
		}
		else if (document.layers) {
			this.obj = document.layers[vstrControlID];
			this.style = document.layers[vstrControlID];
		};
	}
	catch (exception) {
		alert(exception);
		alert(vstrControlID);
		return;
	};
};

//=====================================================================
//=====================================================================
//=====================================================================
//=====================================================================

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//=====================================================================

//=====================================================================
// POPUP WINDOWS
var objNamedWindow;

function windowOpener(url, name) {
	var args;
	switch (name) {
		case "windowTAF" :
			args="height=575,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=550";
			break;
		case "windowFORUM" :
			args="height=600,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=800";
			break;
		case "windowPURCHASE" :
			args="height=600,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=1000";
			break;
		case "windowVIDEO" :
			args="height=375,left=200,location=no,resizable=no,scrollbars=no,status=no,toolbar=no,top=200,width=580";
			break;
			
		default :
			args="height=575,left=50,location=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,top=50,width=550";
	}
	if (typeof(objNamedWindow) != "object"){
		objNamedWindow = window.open(url,name,args);
	} else {
		if (!objNamedWindow.closed){
			//objNamedWindow.focus(); // cheaper when no data changes
			objNamedWindow.location.href = url;
		} else {
			objNamedWindow = window.open(url,name,args);
		}
	}
    objNamedWindow.focus();
}

function windowCloser(objWin) {
	if (typeof(objWin) == "object"){
		objWin.close();
	}
}
//e.g. in caller:
//onClick='windowOpener("Detail.aspx?Id=<?>","windowX");'
//onUnload='windowCloser(objNamedWindow);'
// & in pop up:
function doCloseMe() {
	window.close();
}
//=====================================================================

function setFocusOnLoad(vstrControlID) {
	var blnSet = false;

	if (vstrControlID != null) {
		var objControl = new getObj(vstrControlID).obj;
		if (objControl != null) {
			objControl.focus();
			blnSet = true;
		};
	};
	
	if (!(blnSet)) {
 		//Step 1. Exit function if there is not any form
		if (document.forms.length ==0) {
			return;
		};

  		//Step 2. filter out the form element, only allow the following type get through
  		//	text							textarea
		//	checkbox						select
		//	radio							password
		//	Filter out the element which is disabled or readonly
		//	If the client browser is IE, then filter out the visible object only (CSS attribute)
		//	finally, Set focus on the first object then exit the function

		try {
			for (var j=0; j<document.forms.length;j++){
				for (var i=0; i<document.forms[j].elements.length; i++ ){
					var o=document.forms[j].elements[i]
					if (
						(o.type=='checkbox')
						||(o.type=='file')
						||(o.type=='password')
						||(o.type=='radio')
						||(o.type=='select-multiple')
						||(o.type=='select-one')
						||(o.type=='text')
						||(o.type=='textarea')
					) {
						if ((o.readOnly!=true) && (o.disabled!=true)) {
							if ((o.style.visibility != 'hidden') && (o.style.display != 'none')) {
								o.focus();
								return;
							}; //end of ie.hidden 
						}; //end of readOnly
					}; //detect type
				}; //loop throught the element
			}; //end of form loop
		}
		catch (exception) {
			return;
		};
	};
};


//=====================================================================

var DDL_NOT_CHOSEN = '0';

//=====================================================================

function isZipcode(s) {
	var reZipcode = new RegExp(/^\d{5}([\-]\d{4})?$/);
	if (reZipcode.test(s)) {
		return true;
	};
	return false;
};

//=====================================================================

function isPhoneNumber(s) {
	//rePhoneNumber = new RegExp(/^[\(]?(\d{0,3})[\)]?[\s]?[\-]?(\d{3})[\s]?[\-]?(\d{4})[\s]?[x]?(\d*)$/);
	rePhoneNumber = new RegExp(/^(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}[\s]?[x]?\d*$/);
	
	if (!rePhoneNumber.test(s)) {
		return false;
	} else {
		return true;
	};
};

//=====================================================================

function isEMail(s) {
	var reEMail  = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
	if (reEMail.test(s)) {
		return true;
	};
	return false;
};

//=====================================================================
 
 function isIntegerInRange (s, low, high) {

	if (isEmpty(s)) {
		if (isIntegerInRange.arguments.length == 1) {
			return false;
		} else {
			return (isIntegerInRange.arguments[1] == true);
		};
	};

	// Catch non-integer strings to avoid creating a NaN below,
	// which isn't available on JavaScript 1.0 for Windows.
	if (!isInteger(s, false)) {
		return false;
	};

	// Now, explicitly change the type to integer via parseInt
	// so that the comparison code below will work both on
	// JavaScript 1.2 (which typechecks in equality comparisons)
	// and JavaScript 1.1 and before (which doesn't).
	var num = parseInt (s);
	return ((num >= low) && (num <= high));
};

//=====================================================================

function isInteger(s) {
	return (s.toString().search(/^-?[0-9]+$/) == 0);
};

//=====================================================================

function isCalendarDate(s) {
	var reCalendarDate = new RegExp(/^\d{1,2}\/\d{1,2}\/\d{4}$/);
	if (reCalendarDate.test(s)) {
		return true;
	};
	return false;
};

//=====================================================================

function DecodeEMail(vobjControl) {
	var objControl = new getObj(vobjControl).obj;
	var encodedEMail = objControl.innerHTML; // .value for TextBox, .innerHTML for Label

	// The encodedEMail parameter is a string that contains the encoded data.
	// Each character in the encodedEMail parameter has been converted into 
	// a two digit number (hex / base16). This function converts the
	// series of numbers back into the normal form and returns the 
	// decoded string to the client

	// holds the decoded string
	var decodedEMail = "";

	// go through and decode the full input server encoded string
	for (i=0; i < encodedEMail.length;)
	{
		// holds each letter (2 digits)
		var letter = "";
		letter = encodedEMail.charAt(i) + encodedEMail.charAt(i+1)

		// build the real decoded value
		decodedEMail += String.fromCharCode(parseInt(letter,16));
		i += 2;
	};

	//return the new decoded string to allow it to be rendered to screen
	objControl.innerHTML = decodedEMail; // .value for TextBox, .innerHTML for Label
	//return decodedEMail;
};

//=====================================================================

function DecodeEMailString(vstr) {

	// The vstr parameter is a string that contains the encoded data.
	// Each character in the vstr parameter has been converted into 
	// a two digit number (hex / base16). This function converts the
	// series of numbers back into the normal form and returns the 
	// decoded string to the client

	// holds the decoded string
	var decodedEMail = "";

	// go through and decode the full input server encoded string
	for (i=0; i < vstr.length;)
	{
		// holds each letter (2 digits)
		var letter = "";
		letter = vstr.charAt(i) + vstr.charAt(i+1)

		// build the real decoded value
		decodedEMail += String.fromCharCode(parseInt(letter,16));
		i += 2;
	};

	//return the new decoded string to allow it to be rendered to screen
	return decodedEMail;
};

//=====================================================================

function obfuscate(sDom, sUser){
	return("mail"+"to:"+sUser+"@"+sDom.replace(/%23/g,"."));
};

//=====================================================================
