
//----------------------------------------------------------------------------------
//enables a textbox to trigger submit on enter key
//----------------------------------------------------------------------------------
function doClick(objTextBox, e, objSubmitId, strDefaultText)
{
    if (objTextBox.value == '' || objTextBox.value == strDefaultText) return;
    
    var key;
     if(window.event) { key = window.event.keyCode; } //IE
     else { key = e.which; } //firefox

    if (key == 13) {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(objSubmitId);
        if (btn != null) { //If we find the button click it
            btn.click(); key = 0;
        }
    }
}

//----------------------------------------------------------------------------------
//linked textboxes eg phone, social security, etc
//----------------------------------------------------------------------------------
function LinkedTextBoxMoveNext(currControl, nextControlId) {
    currControl.value = currControl.value.replace(/[^0-9]/, "")
    if (currControl.value.length == eval(currControl.getAttribute("maxlength")))
        document.getElementById(nextControlId).focus();
}

//if no error message, it returns false else it alerts
function LinkedTextBoxValidate(controlIds, errorMessage, targetAction, ActionId, paramsAndControlIds) {
    try {
        var amp = "&";
        var paramToAppend = new String();
    
        //parameter and string validation
        if (typeof (paramsAndControlIds) != 'undefined' && paramsAndControlIds != '') {
        
            //format: qsprm1=elmIdOrName1=errMsg1|qsprm2=elmIdOrName2=errMsg2|...
            var params = paramsAndControlIds.split("|");
            
            for (var i = 0; i < params.length; i++) {
                var arr = params[i].split("=");
                var obj = document.getElementsByName(arr[1]);                
                var txt = new String();
                if (!obj) obj = document.getElementById(arr[1]);

                if (obj) {
                    var typ = obj.type; if (typeof(typ) == 'undefined' && (obj[0])) typ = obj[0].type;
                    switch (typ) {
                        case "radio":
                            if (obj.length > 0) {
                                for (var x = 0; x < obj.length; x++) {
                                    if (obj[x].checked) { txt = obj[x].value; break }
                                }
                            }
                            else {
                                if (obj.checked) { txt = obj.value; }
                            }
                            break;
                    }                    
                    //check for selected/entered text
                    if (txt.length > 0) { paramToAppend += amp + arr[0] + "=" + txt; }
                    else { alert(arr[2]); return false; }
                }                
            }
        }
    
        //text box validation
        var textBoxes = controlIds.split(",");
        var objvalues = "";

        for (var i = 0; i < textBoxes.length; i++) {
            var textBox = document.getElementById(textBoxes[i]);
            var textValue = textBox.value;
            if (textValue.length != eval(textBox.getAttribute("maxlength"))) {
                if (errorMessage != "" && typeof (errorMessage) != "undefined")
                { alert(errorMessage); }
                return false;
            }
            else {
                objvalues += textValue;
            }
        }

        //all is well execte action
        if (!isNaN(ActionId) && targetAction != "" && typeof (targetAction) != "undefined") {
            switch (parseInt(ActionId)) {
                case 1: //redirect to target
                    window.location.href = targetAction + objvalues + paramToAppend;
                    break;
                case 2: //populate target with values
                    document.getElementById(targetAction).value = objvalues;
                    break;
                default:
                    //alert("No action was specified for the value \"" + targetAction + "\"");
                    //return false;
                    break;
            }
        }
    }
    catch(e) {
        alert(e.message);
    }
    
    return true;
}

//----------------------------------------------------------------------------------
//float content on page
//----------------------------------------------------------------------------------
var activeDiv = null;
function showFloatContent(pActiveDivId, pTop, pLeft, pChild) {

    if (isNaN(pLeft)) pLeft = -100
    if (isNaN(pTop)) pTop = 20

    //hide old active div
    hideFloatContent();

    //show new active div
    activeDiv = document.getElementById(pActiveDivId)

    if (activeDiv) {
        var jqueryObj = $('#' + pActiveDivId);
        if (typeof (pChild) == 'undefined' || pChild == '')
            var prtPos = jqueryObj.parent().position();
        else
            var prtPos = jqueryObj.siblings(pChild).position();

        jqueryObj.css({ "position": "absolute", "top": prtPos.top + pTop + "px", "left": prtPos.left + pLeft + "px" }).fadeIn();
        activeDiv.style.display = "block";
    }
}

function hideFloatContent() {
    if (activeDiv) {
        $(activeDiv).fadeOut(100);
        //activeDiv.style.display = "none";
    }
}

//----------------------------------------------------------------------------------
//add a trim function to the string object
//----------------------------------------------------------------------------------
String.prototype.trim = function () {return this.replace(/^\s*|\s*$/,"");}

//----------------------------------------------------------------------------------
//client side email validator for Custom Validator Control
//----------------------------------------------------------------------------------
function isValidEmail(email)
{
    try 
    {
        var emailReg = "^[\\w-_\.+]*[\\w-_\.]\@([\\w]+\\.)+[\\w]+[\\w]$";
        var regex = new RegExp(emailReg);
        return regex.test(email.trim());
    }
    catch(e)
    {
        alert("Email validation failed!: " + e.message);
        return false;
    }
}
  
function validateEmail(sender, args)
{
    var emails = args.Value.split(",");
    var isvalid = true;
    
    for (var i = 0; i < emails.length; i++) {
        if (!isValidEmail(emails[i])) {isvalid = false; break;}
    }
    
    args.IsValid = isvalid;
    return;
}
       
//----------------------------------------------------------------------------------
//copies content of a text element to the clipboard
//----------------------------------------------------------------------------------
function copyClipBoardData(strTextData)
{
    try
    {
        if (window.clipboardData)
        { 
            window.clipboardData.setData("Text", strTextData);
        }
        else if (window.netscape)
        {
            if (window.clipboardData)
            {
                window.clipboardData.setData("Text", strTextData);
            }
            else if (window.netscape)
            { 
               netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
               
               var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
               
               if (!clip) return;
               
               var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
               
               if (!trans) return;
               
               trans.addDataFlavor('text/unicode');
               
               var str = new Object();
               var len = new Object();
               var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
               var copytext = strTextData;
                                          
               str.data = copytext;
               trans.setTransferData("text/unicode", str, copytext.length * 2);
               
               var clipid = Components.interfaces.nsIClipboard;
               
               if (!clip) return false;
               
               clip.setData(trans,null,clipid.kGlobalClipboard);
               
               return false;
            }
       }
    }
    catch(e)
    {
        return false;
    }
}

        
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;
}

var LastToolTipBoxID = null;
function MM_ShowHideToolTipBox(id) {
    if(LastToolTipBoxID != null)
        MM_showHideLayers(LastToolTipBoxID,'','hide');
    LastToolTipBoxID = id;
    MM_showHideLayers(LastToolTipBoxID,'','show');
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

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;
}

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; ia.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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;
}

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];}}
}

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 PreventSubmitOnEnterPress(objName) 
{
	if (event.keyCode == 13)
	{
		event.cancelBubble = true;
		event.returnValue = false;
		//alert(objName);
		//document.all.getElementById(objName).submit();
		
		return false;
    }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var win = window.open(theURL,winName,features);
  win.focus();
}




// search javascript functions

function clearText(controlID, defaultText) {
	if (document.getElementById(controlID).value == defaultText) {
		document.getElementById(controlID).value = "";
	}
}

function resetText(controlID, defaultText) {
	if (document.getElementById(controlID).value == "") {
		document.getElementById(controlID).value = defaultText;
	}
}




// outdial cancel confirmation

function getAbsolutePath() {
	var v_rval;
	var v_file = window.location.pathname;
	
	var i_fpsn = v_file.indexOf("/", 0);
	var i_lpsn = v_file.indexOf("/", i_fpsn + 1);
	
	if (i_fpsn < 0) {
		v_rval = "";
	} else {
		if (i_lpsn < 0) {
			v_rval = "";
		} else {
			v_rval = v_file.substring(0, i_lpsn);
		}
	}
	
	return v_rval;
}

function confirmApptCancel(pApptID, pName, pExtID, pDate) {
	var pth = encodeURIComponent(window.location.href);
	if (confirm('Are you sure you would like to cancel your appointment on ' + pDate + ' with ' + pName + ' .ext ' + pExtID + '?')) {
		// redirect to cancel page
		window.location.href = '/appointment/cancel.aspx?apptid=' + pApptID + '&redirpath=' + pth;
	}
	
	return false;
}

function confirmCancel(pName, pExtID, pAppPath) {
	var ans = confirm('Are you sure you want to cancel your Callback from ' + pName + ' ext. ' + pExtID + '?');
	var pth = encodeURIComponent(window.location.href);
	
	if (ans) {
	    //window.location.href = getAbsolutePath() + '/outdial/cancel.aspx';
	    pAppPath = (typeof (pAppPath) == "undefined") ? "" : pAppPath;
	    window.location.href = pAppPath+'/outdial/cancel.aspx?extid='+pExtID+'&redirpath='+pth;
	}
	
	return false;
}

function confirmCancelWithRedirect(pName, pExtID, pRedirectExtID) {
	var ans = confirm('Are you sure you want to cancel your Callback from ' + pName + ' ext. ' + pExtID + '?');
	var pth = encodeURIComponent(window.location.href);
	
	if (ans) {
		//window.location.href = getAbsolutePath() + '/outdial/cancel.aspx';
		window.location.href = '/outdial/cancel.aspx?redirextid=' + pRedirectExtID + '&extid=' + pExtID + '&redirpath=' + pth;
	}
	
	return false;
}


// get cookie from client machine
function getCookie(pCookieName) {
	var str = "";
	var pos = document.cookie.indexOf(pCookieName + "=");
	
	if (pos != -1) {
		// starting position
		var s = pos + pCookieName.length + 1;
		// ending position
		var e = document.cookie.indexOf(";", s);
		
		if (e == -1) {
			e = document.cookie.length;
		}
		
		str = document.cookie.substring(s, e);
		str = unescape(str);
	}
	
	return str;
}

// set cookie onto client machine
function setCookie(pCookieName, pCookieValue, pDaysTilExpire) 
{
    if (pDaysTilExpire == null) {
	    //expires after session
		document.cookie = pCookieName + "=" + pCookieValue + "; path=/";
    } 
    else {
        //expires in {pDaysTilExpire} days
		var dtm = new Date();
		dtm.setDate(dtm.getDate() + pDaysTilExpire);		
		document.cookie = pCookieName + "=" + pCookieValue + "; path=/; expires=" + dtm;
	}
}


// timezone
function setTimezoneCookie() {
	if (getTimezoneCookie() == "") {
		var dtm = new Date();
		var off = (dtm.getTimezoneOffset() * -1) / 60; // off = hour difference from UTC

		// set cookie for one day
		setCookie("ClientOffSet", off, null);
		//setCookie("TimeZoneOffset", off, 1);
	}
}

function getTimezoneCookie() {
    return getCookie("ClientOffSet");
}

//function getWelcomePageCookie() {
//	return getCookie("otw");
//}


// if not already, set the timezone when the page is loaded
AddEvent(window, "load", setTimezoneCookie);

//if (window.attachEvent) {
//	// for IE
//	window.attachEvent("onload", setTimezoneCookie);
//} else {

//	if (window.addEventListener) {
//		// for Mozilla, Firefox, Safari
//		window.addEventListener("load", setTimezoneCookie, false);
//	}

//}

function AddEvent(obj, evt, fxn) {
	if (obj.attachEvent) {
		// for ie
		obj.attachEvent('on' + evt, fxn);
	} else if (obj.addEventListener) {
		// for mozilla, firefox, safari
		obj.addEventListener(evt, fxn, false);
	}
}

// on /appointment/verify.aspx, disable phone input if outdial radio is not selected
function DisablePhoneInput(pOutdial) {
	var arr = document.forms[0].elements;
	
	for (var i = 0; i < arr.length; i++) {
		if (arr[i].type == "text") {
			if (arr[i].name.indexOf("txtPhone") != -1) {
				arr[i].disabled = !pOutdial;
			}
		}
	}
}










//-- generic dhtml functions --//

function HideElement(id) {
	ChangeDisplay(id, 'none');
}

function ShowElement(id) {
	ChangeDisplay(id, 'block');
}


function TurnOnElement(id) {
	ChangeClass(id, 'on');
}

function TurnOffElement(id) {
	ChangeClass(id, 'off');
}


function ChangeDisplay(id, styleValue) {
    try {
        document.getElementById(id).style.display = styleValue;
    }
    catch (e) { }
}

function ChangeClass(id, classValue) {
	var e = document.getElementById(id);
	if (e) 
	if (e.className != 'hidden') {
		e.className = classValue;
	}
}




//-- psychic page dhtml functions --//

function tabChange(tab) {
	TurnOffElement('t-bio');
	TurnOffElement('t-schedule');
	TurnOffElement('t-appointments');
	TurnOffElement('t-waitlist');
	TurnOffElement('t-testimonials');
	
	TurnOnElement(tab);
	try {
	    if (window.setActiveTab) {
	        var cnt = tab.split('-')
	        if (cnt.length == 2) setActiveTab('a-' + cnt[1]);
	    }
	}
	catch (e) { }
}

function contentChange(content) {
	HideElement('c-bio');
	HideElement('c-schedule');
	HideElement('c-appointments');
	HideElement('c-waitlist');
	HideElement('c-testimonials');

	ShowElement(content);
}

//function tabChange(tab) {
//	/*
//	document.getElementById('t-schedule').className = 'off';
//	document.getElementById('t-appointments').className = 'off';
//	document.getElementById('t-waitlist').className = 'off';
//	document.getElementById('t-testimonials').className = 'off';
//	document.getElementById(tab).className = 'on'; // turns on single tab
//	*/tabCheck('t-bio', 'off');
//	tabCheck('t-schedule', 'off');
//	tabCheck('t-appointments', 'off');
//	tabCheck('t-waitlist', 'off');
//	tabCheck('t-testimonials', 'off');
//	tabCheck(tab, 'on');
//}

//function contentChange(content) {
//	document.getElementById('c-bio').style.display = 'none';
//	document.getElementById('c-schedule').style.display = 'none';
//	document.getElementById('c-appointments').style.display = 'none';
//	document.getElementById('c-waitlist').style.display = 'none';
//	document.getElementById('c-testimonials').style.display = 'none';
//	document.getElementById(content).style.display = 'block'; // displays single block of content
//}

//function tabCheck(tabName, newClass) {
//	var e = document.getElementById(tabName);
//	
//	if (e.className != 'hidden') {
//		e.className = newClass;
//	}
//}



//-- horoscope page dhtml functions --//

//function horoTabChange(tab) {
//	TurnOffElement('t-overview');
//	TurnOffElement('t-love');
//	TurnOffElement('t-about');
//	
//	TurnOnElement(tab);
//}

//function horoContentChange(content) {
//	HideElement('c-overview');
//	HideElement('c-love');
//	HideElement('c-about');
//	HideElement('astroBox');
//	
//	ShowElement(content);
//}

//function setDefaultHoroPage() {
//	horoTabChange('t-overview');
//	horoContentChange('c-overview');
//}
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]+"'");
}

/*  Disabling text boxes */
function disableAndClear(obj, bln) {
    obj.disabled = bln;
    obj.backGroundColor = bln == true ? "#e1e1e1" : "#ffffff";
    obj.value = bln == true ? '' : obj.value;
}

/* Setting UniqueProperties for Radio Button */
function SetUniqueRadioButton(nameregex, current)
{
    var re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
       elm = document.forms[0].elements[i];
      if(elm.type == 'radio') {
      if(re.test(elm.name))
        elm.checked = false;
      }
   }
   current.checked = true;
}
function getInnerContent(tag, data) {
    var sIndex = data.toLowerCase().indexOf('<' + tag.toLowerCase() + '>') + tag.length + 2;
    var eIndex = data.toLowerCase().indexOf('</' + tag.toLowerCase() + '>');
    return (data.substring(sIndex, eIndex));
}

//lil.jax (lean ajax) where jquery is overkill see "scripts/lil.jax.js" for expanded script
if (!window.lil) { lil = {}; }; if (!lil.jax) { lil.jax = {}; }; if (!window.$_) { $_ = function(el) { if (typeof el == 'string') { el = document.getElementById(el); } return el; } }; lil.jax.killcache = 'nocache';
lil.jax.xhr = function() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { return false; } };
lil.jax.get = function(url, func) { var xhr = lil.jax.xhr(); if (lil.jax.killcache) { var cache = lil.jax.killcache + '=' + new Date().getTime(); url += url.indexOf('?') == -1 ? '?' : '&' + cache; }; xhr.open('GET', url, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { func(xhr.responseText); }; }; xhr.send(); };
lil.jax.pop = function(url, el) { var el = $_(el); var func = function(response) { el.innerHTML = response; }; lil.jax.get(url, func); };