var bolXML25 = null;
var bolXML3 = null;
var bolXML4 = null;
var IsXMLInstalled = false;
var SPDateTime = "";
var strPageID = ""	//This variable is primarily used in sending Email
var delay = 2	//milliseconds
var timeout_state = null;

var httpObj = null;
var myTarget = "Misc/XMLHTTPRequestHandler.aspx"	//Do not chage the path style.

var strDestination = "";
var intSpeed = 50;

var CurDomain = document.location.toString().toLowerCase()
var IsIndia = CurDomain.indexOf("functionhalls.com")!=-1?true:CurDomain.indexOf("functionhalls.com")!=-1?true:CurDomain.indexOf("http://localhost")!=-1?true:false;

//=====================CHECK XML VERSION===================================
function checkXMLVersion(){
	bolXML25 = xmlSniff(2.5)
	bolXML3 = xmlSniff(3)
	bolXML4 = xmlSniff(4)

	//If XML 2.5, 3 or 4 is installed then set flag to true
	if(bolXML25 || bolXML3 || bolXML4){IsXMLInstalled = true;}
	
	//if(!IsXMLInstalled) xmlAlert();
	if(!IsXMLInstalled) document.location.href = "./misc/xmlrequired.aspx";
}

//Check whether MSXML is installed on the client machine
function xmlSniff(argVersion){
	var xml = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><USCurries></USCurries>";
	var x = null;
	argVersion = parseInt(argVersion);
	if(argVersion == 2.5 || argVersion == 3 || argVersion == 4){
		var strObject = "Msxml2.DOMDocument." + argVersion + ".0"
		try{
		    x = new ActiveXObject(strObject); 
		    x.async = false;
		    x.loadXML(xml);
			return true
		}
		catch(e){return false;}
	}
}

function CreateXMLHTTPObject(){
	//HTTP OBJECT TO SEND DATA TO SERVER
	//var httpObj = new ActiveXObject("Microsoft.XMLHTTP");
	if(IsXMLInstalled){
		if(bolXML4){
			httpObj = new ActiveXObject("MSXML2.XMLHTTP.4.0");
			return false;
		}
		
		if(bolXML3){
			httpObj = new ActiveXObject("MSXML2.XMLHTTP.3.0");
			return false;
		}
		
		if(bolXML25){
			httpObj = new ActiveXObject("Microsoft.XMLHTTP");
			return false;
		}
	}
}

//This function sends data to server whitout submitting the whole page
function sendData(sData, sTarget, sType, sDestination){
	
	//exit if required XML component is not installed
	if (!IsXMLInstalled){
		var strAlert = "This web site requires Microsoft XML parser 3.  "
		strAlert += "Please click the Refresh button on your browser to open a window, "
		strAlert += "which can help you to get the required files.  If you see this window after installing "
		strAlert += "the required files, please click the Refresh button on your browser."

		//if(myPopup) ShowPopup(false);
		alert(strAlert)
		return false;
	}
	
	if(httpObj.readyState == 0 || httpObj.readyState == 4){
		strDestination = sDestination;
		httpObj.Open("POST", sTarget, true, "", "");

		//Set the content type
		if(sType == "xml") httpObj.setRequestHeader("Content-Type","text/xml");
		else httpObj.setRequestHeader("Content-Type","text/plain");
		
		//Send the data and start looking for the return data
		httpObj.Send (sData);
		
		receiveData();
	}
}

//This function receives the data from server
function receiveData(){
	if (httpObj.readyState == 4){
		if (strDestination == "SetLoginStatus")
			SetLoginStatus(httpObj.ResponseText)
		else if(strDestination == "SetVoceFileInfo")
			SetVoceFileInfo(httpObj.ResponseText)
		else if(strDestination == "SetSrchInfo")
			SetSrchInfo(httpObj.ResponseText)
	}
    else{
		timeout_state = setTimeout("receiveData()", intSpeed);
	}
}


//Name value collection
var NVC = {NameArray: {}}
function SetNameValue(argName, argValue){
	NVC[argName] = [argValue]
}

function GetNameValue(argName){
	return NVC[argName]
}

function NoRightClick(evnt) {
	var e = evnt || window.event;
	if (e.button == 2 || e.button == 3) setTimeout("OpenAlert()", 5);
}

function OpenAlert(){
	alert("Right click is disabled on this page.");
}

function NoKeyDown(e){
	var isCTRL = event.ctrlKey
	var intKeyCode = event.keyCode
	if(isCTRL && (intKeyCode == 65 || intKeyCode == 70 || intKeyCode == 82 || intKeyCode == 116)){event.returnValue=false; alert("Key strokes disabled on this page.");}
}

function NoSelect(evnt){
	return false;
}
function NoCopy(){
	alert("No Copy on this page.")
	//window.clipboardData.setData("Text", "No Copy.");
}

function GetTimeZoneDate(zone){
	var dt = new Date()

	var dt0 = new Date(dt.getUTCFullYear() + "/" + (dt.getUTCMonth() + 1) + "/" + dt.getUTCDate() + " " + dt.getUTCHours() + ":" + dt.getUTCMinutes() + ":" + dt.getUTCSeconds())
	if(zone=='IST'){
		dt0.setHours(dt0.getHours() + 5)
		dt0.setMinutes(dt0.getMinutes() + 30)
	}
	return dt0;
}

function SetLocalTime(){
	var dt = GetTimeZoneDate('IST')
	document.getElementById("divLocalTime").innerHTML = "<b>Local Time:</b> " + dt.toLocaleTimeString() + '&nbsp;&nbsp;&nbsp;&nbsp;' + dt.getDate() + "/" + (dt.getMonth() + 1) + "/" + dt.getFullYear()
	setTimeout("SetLocalTime()", 5000);
}



/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function GetIndiaToUSDate(argDate){
	var dt = argDate.split("/")
	return dt[1] + "/" + dt[0] + "/" + dt[2]
}

//Takes India format dates and returns the difference (seconds)
//d1 = smaller date
//d2 = greater date
function DateDiff(d1,d2,diff){
	var d1 = new Date(GetIndiaToUSDate(d1))
	var d2 = new Date(GetIndiaToUSDate(d2))
	var d = (d2-d1)
	
	if(diff == 'D'){return (d / (24*60*60*1000))}		//Day
	else if(diff == 'H'){return (d / (60*60*1000))}		//Hours
	else if(diff == 'M'){return (d / (60*1000))}		//Minutes
	else if(diff == 'S'){return (d / (1000))}			//Seconds
}

function GetClientDate(){
	var dt1 = new Date()
	var mo1 = dt1.getMonth() + 1
	var da1 = dt1.getDate()

	if(mo1.toString().length==1)mo1 = "0" + mo1
	if(da1.toString().length==1)da1 = "0" + da1
	var dt2 = mo1 + "/" + da1 + "/" + dt1.getFullYear()		//current date to compare with
	
	return dt2;
}


//Takes India date format and compares two dates
function DateCompareIndia(d1,d2){
	d1 = new Date(GetIndiaToUSDate(d1))
	d2 = new Date(GetIndiaToUSDate(d2))

	if(d1 > d2) return 1;	//Start date is > than end date
	else if(d1 < d2) return 2;	//End date is > than start date
	else return 0;	// Both are same
}

function MsgWndHide(){
	//Some pages may perform certain actions just before the window is closed
	try{
		MsgWndCallback()
	}catch(e){}

	if(document.getElementById("divMsgWnd")){
		var s = document.getElementById("ifMsgWnd").src
		document.getElementById("divMsgWnd").style.display="none"
		document.getElementById("ifMsgWnd").src = "http://FunctionHalls.com/Misc/Blank.aspx" //s.substr(0,s.lastIndexOf("/")) + "/Blank.aspx"
	}
}

function MsgWndShow(s,ti,l,t,w,h,url){
	
	l += document.body.scrollLeft
	t += document.body.scrollTop
	
	if(!url){
		document.getElementById("rowMsgWndBody").style.display="";
		document.getElementById("rowMsgWndFrame").style.display="none";
		document.getElementById("celMsgWndBody").innerHTML=s
		document.getElementById("cleMsgWndHead").innerHTML=ti
		document.getElementById("divMsgWnd").style.left= l
		document.getElementById("divMsgWnd").style.top= t
		document.getElementById("divMsgWnd").style.width = w
	}
	else{
		document.getElementById("rowMsgWndFrame").style.display="";
		document.getElementById("rowMsgWndBody").style.display="none";
		document.getElementById("ifMsgWnd").style.visibility="visible";
		document.getElementById("ifMsgWnd").style.display="";
		document.getElementById("ifMsgWnd").src = url;

		document.getElementById("ifMsgWnd").style.height = h
		document.getElementById("ifMsgWnd").style.width = w

		document.getElementById("cleMsgWndHead").innerHTML=ti
		document.getElementById("divMsgWnd").style.left= l
		document.getElementById("divMsgWnd").style.top= t
		document.getElementById("divMsgWnd").style.height = h
		document.getElementById("divMsgWnd").style.width = 1
	}
	
	document.getElementById("divMsgWnd").style.display="";
}

//doc indicates whether the message window should be docked to the top
function MsgWndShow2(s,ti,l,t,w,h,url,doc){

	var intClientWidth = parseInt(document.body.clientWidth)
	var intClientHeight = parseInt(document.body.clientHeight)

	l += document.body.scrollLeft
	t += document.body.scrollTop
	
	if(!url){
		document.getElementById("rowMsgWndBody").style.display="";
		document.getElementById("rowMsgWndFrame").style.display="none";
		document.getElementById("celMsgWndBody").innerHTML=s
		document.getElementById("cleMsgWndHead").innerHTML=ti
		document.getElementById("divMsgWnd").style.left= ((intClientWidth/2) - (w/2)) - l
		document.getElementById("divMsgWnd").style.top= ((intClientHeight/2) - (h/2)) + t
		document.getElementById("divMsgWnd").style.width = w
		document.getElementById("tblMsgWind").style.width = w
	}
	else{
		document.getElementById("rowMsgWndFrame").style.display="";
		document.getElementById("rowMsgWndBody").style.display="none";
		document.getElementById("ifMsgWnd").style.visibility="visible";
		document.getElementById("ifMsgWnd").style.display="";
		document.getElementById("ifMsgWnd").src = url;

		document.getElementById("ifMsgWnd").style.height = h
		document.getElementById("ifMsgWnd").style.width = w

		document.getElementById("cleMsgWndHead").innerHTML=ti
		document.getElementById("divMsgWnd").style.left= ((intClientWidth/2) - (w/2)) - l
		document.getElementById("divMsgWnd").style.top= ((intClientHeight/2) - (h/2)) + t
		document.getElementById("divMsgWnd").style.height = h
		document.getElementById("divMsgWnd").style.width = w
	}
	
	if(doc){DocMsgWindowToTop()}
	
	document.getElementById("divMsgWnd").style.display="";
}


//This function sets the message window right below the title section of the page
function DocMsgWindowToTop(){
    var y = parseFloat(getAbsolutePosition(document.getElementById("txtWord")).toString().split(",")[1].replace(/\)/g,''))
    y += parseFloat(document.getElementById("txtWord").style.height.toString().replace(/px/g,''))

    if(document.body.scrollTop < y){
        document.getElementById("divMsgWnd").style.top = y + 2
    }
    else{
        document.getElementById("divMsgWnd").style.top = document.body.scrollTop
    }
}

function DimTheScreen(bol){
    if(bol) {document.getElementById("divDarkBackgroundLayer").style.display=""}
    else {document.getElementById("divDarkBackgroundLayer").style.display="none"}
}


function HideDiv(name){
	if(document.getElementById(name)) document.getElementById(name).style.display="none"
}

function ShowRetrieveMsg(){
	var intClientWidth = parseInt(document.body.clientWidth)
	var intClientHeight = parseInt(document.body.clientHeight)
	
	//alert(document.getElementById("divMsg").style.width)
	
	document.getElementById("divMsg").style.left = ((intClientWidth/2) - (300/2)) - 100
	document.getElementById("divMsg").style.top = ((intClientHeight/2) - (100/2))
	document.getElementById("divMsg").style.display="";
}

function ShowMsg(){
	document.getElementById("divMsg").style.display="";
	document.getElementById("divMsg").style.left = 300
	document.getElementById("divMsg").style.top = 300
}



function RequestForQuote(BsnsSubGrupID){
	document.location = strHostRoot + "/Quote/QuoteAdd.aspx?B=" + BsnsSubGrupID
}

function SendSMSToSP(BsnsSubGrupID){
	document.location = strHostRoot + "/Quote/SMSToSP.aspx?B=" + BsnsSubGrupID
}

function ToggleCheckbox(obj){
	document.getElementById(obj).checked = !document.getElementById(obj).checked
}

function ManageCompareList(BsnsType, BsnsID, Mode){
	var s = getCookie("CompareBsnsType" + BsnsType)

	if(!s)s=""
	
	if(Mode == "ADD"){
		if(s.indexOf("," + BsnsID + ",") == -1){
			setCookie("CompareBsnsType" + BsnsType, s + BsnsID + ",", "", "/")
		}
	}
	else if(Mode == "DEL"){
		var exp = new RegExp("," + BsnsID + ",","g")
		s = "," + s
		s = s.replace(exp,",")
		s = s.substr(1)
		setCookie("CompareBsnsType" + BsnsType, s, "", "/")
	}
}

//Manage business calendar selection cookies
function ManageBsnsCldrSelection(BsnsType, BsnsID, Mode){
	var s = getCookie("BsnsCldr" + BsnsType)

	if(!s)s=""
	
	if(Mode == "ADD"){
		if(s.indexOf("," + BsnsID + ",") == -1){
			setCookie("BsnsCldr" + BsnsType, s + BsnsID + ",", "", "/")
		}
	}
	else if(Mode == "DEL"){
		var exp = new RegExp("," + BsnsID + ",","g")
		s = "," + s
		s = s.replace(exp,",")
		s = s.substr(1)
		setCookie("BsnsCldr" + BsnsType, s, "", "/")
	}
}

//Select business calendars
function CheckSelectedBsnsCldrs(){
	//window.parent.
	//Check previously selected business checkboxes
	var s = getCookie("BsnsCldr" + document.getElementById("ddlBsns").value)
    var arrBsnsIDs = new Array()
	
	if(s != null){
		arrBsnsIDs = s.split(",")
		for(var a in arrBsnsIDs){
			try{document.getElementById("chk"+arrBsnsIDs[a]).checked=true;}
			catch(ex){}
		}
	}
}


//This function returns the selected radio button object
function GetSelectedOption(argObject){
	var objReturn = false;

	if(argObject.type == 'radio'){
		//If there is only one radio button all together
		if(argObject.checked) return argObject;
		else return false;
	}
	else{
		//Loop through and find the selected option
		for(i=0;i<argObject.length;i++){
			if (argObject[i].checked){
				objReturn = argObject[i];
				break;
			}
		}
		return objReturn;
	}
}

function GetSelectedCheckboxes(obj){
    var rtn = ""
    
    if (!obj.length || obj.length == 1) {
        if (obj.checked == true) {
            return obj.value
        }
    } 
    else {
        for (var loop=0; loop<obj.length; loop++) {
            if (obj[loop].checked == true) {
                rtn += obj[loop].value + ","
            }
        }
        
        return rtn.substr(0,rtn.length-1) ;
    }
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;

	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

//This mess is to provide different functionalities based on browser
function ResizeDivByClick(direction){
	if(direction == 1 && document.all){
		ExpandDIV()
	}
	if(direction == 0 && document.all){
		CollapseDIV()
	}
}


function ExpandDIV(){
	//This workaround is to avoid refresh problems in IE
	if(document.all){	//Some reason ie did not like both conditions in one if clause
		var t = window.event.type
		if(t == "click"){
			increment=100
			ResizeDiv()
		}
	}
	else{
		increment=2
		ResizeDiv()
		timeout_state = setTimeout("ExpandDIV()", delay);
	}
}

function CollapseDIV(){
	if(document.all){	//Some reason ie did not like both conditions in one if clause
		var t = window.event.type
		if(t == "click"){
			increment=-100
			ResizeDiv()
		}
	}
	else{
		increment=-2
		ResizeDiv()
		timeout_state = setTimeout("CollapseDIV()", delay);
	}
}

function StopResize(){
	clearTimeout(timeout_state);
	timeout_state = null;
	
	//Store workarea height for future use
	var dt = new Date()
	dt.setFullYear(dt.getFullYear()+1)
	setCookie("FHWorkAreaH", MyMenuFrame.offsetHeight, dt, "/")
}

//This function expands a div by 100px at a time
function ResizeDiv(){
	//var objDiv = eval("document.getElementById('" + obj + "')")
	objDiv = MyMenuFrame	//document.getElementById("divFoodMenu")
	
	if(!objDiv)return false;
	
	if (isNaN(parseInt(objDiv.style.height))){
		objDiv.style.height = objDiv.offsetHeight + increment;
	}
	else{
		if(parseInt(objDiv.style.height) >= 400 || increment > 0){
			objDiv.style.height = parseInt(objDiv.style.height) + increment;
		}
	}
	
	//timeout_state = setTimeout("ResizeDiv()", delay);
}

function SetWorkareaDefaultHeight(){
	if(getCookie("FHWorkAreaH") && parseInt(getCookie("FHWorkAreaH")) > parseInt(MyMenuFrame.offsetHeight)){
		//MyMenuFrame.offsetHeight = parseInt(getCookie("FHWorkAreaH"))
		//alert(MyMenuFrame.offsetHeight)
		try{
			MyMenuFrame.style.height = parseInt(getCookie("FHWorkAreaH"))
		}
		catch(ex){}
	}
	
	if(parseInt(MyMenuFrame.offsetHeight) < 400){MyMenuFrame.style.height = 400}
	
}

//aligns the object to center of the screen
function LeftPosSet(obj){
	obj.style.left = ((screen.availWidth/2) - (parseInt(obj.style.width)/2))
}

//aligns the object to middle of the screen
function TopPosSet(obj){
	obj.style.top = ((screen.availHeight/2) - (parseInt(obj.style.height)/2))
}

function WindowAvailWidthGet(){
	return (screen.availWidth - 60)
}

function WindowAvailHeightGet(){
	return (screen.availHeight - 300)
}

//Highlight city names in ddlCity list
function HighlightCities(){
	var obj = document.getElementById("ddlCity")
	var c = "Hyderabad;Secunderabad;Visakhapatnam;Vijayawada;Bangalore;Chennai;Delhi;"
	var l = obj.options.length
	for(var i=0; i < l;i++){
		if(c.indexOf(obj.options[i].text + ";") >= 0){
			obj.options[i].style.color="red"
			obj.options[i].style.fontWeight="bold"
		}
	}
}

//Highlight popular services
function HighlightServices(){
	var obj = document.getElementById("ddlBsns")
	var c = "Function Halls;Caterers;Hindu Priestly Services;Hotels;"
	var l = obj.options.length
	for(var i=0; i < l;i++){
		if(c.indexOf(obj.options[i].text + ";") >= 0){
			obj.options[i].style.color="red"
			obj.options[i].style.fontWeight="Bold"
		}
	}
}

//This function is used to avid selecting data in the data page.
function RedirectFocus(e){
	var key = (window.event)? event.keyCode : e.which;
	if(key == 65 || key == 97){window.parent.focus();}
}


function GetHTMLSource(node) {
    var root = document.getElementsByTagName(node)[0];
    var root_begin = '&lt;' + root.tagName + get_attributes(root) + '&gt;';
    var root_end   = '&lt;/' + root.tagName + '&gt;';
    var src = root.innerHTML;
 
    src = src.replace(/&/g, '&amp;');
    src = src.replace(/</g, '&lt;');
    src = src.replace(/>/g, '&gt;');
    src = src.replace(/ /g, '&nbsp;');
    //src = src.replace(/\r\n|\r|\n/g, '<br>');
    src = src.replace(/\r\n|\r|\n/g, '');
    src = src.replace(/\t/g, '&nbsp;&nbsp;&nbsp;');
    return (root_begin + src + root_end)
}

function get_attributes (node){
    var attributes = '';
    for (var i = 0; i < node.attributes.length; i++) {
       // Check if the attribute has been specified
       if (node.attributes.item(i).specified)
          attributes += ' ' + node.attributes.item(i).name + '="' + 
          node.attributes.item(i).value + '"';
    }
    return attributes;
 }

var intNextImgIdx = 0;
var preloadImgs = new Image;
function ImagePreload(imgUrl,idx){
	//var l = preloadImgs.length;
	intNextImgIdx = idx
	document.getElementById("tdStts").innerHTML = "Pre-loading the picture " + intNextImgIdx + "..."
	
	preloadImgs.onload = OnImageLoad
	preloadImgs.src = imgUrl
}

function OnImageLoad(){
	document.getElementById("tdStts").innerHTML = "Picture " + intNextImgIdx + " is available for viewing"
}


function WindowAvailWidthGet(){
	return (screen.availWidth - 60)
}

function WindowAvailHeightGet(){
	return (screen.availHeight - 250)
}



// MESSAGE WINDOW DRAG
N = (document.all) ? 0 : 1;
var ob;
var over = false;

function MD(e) {
	if (over){
		if (N) {
			ob = document.getElementById("divMsgWnd");
			X=e.layerX;
			Y=e.layerY;
			return false;
		}
		else {
			ob = document.getElementById("divMsgWnd");
			ob = ob.style;
			X=event.offsetX;
			Y=event.offsetY;
		}
	}
}

function MM(e) {
	try{getMouseXY(e)}
	catch(ex){}

	if (ob) {
		if (N) {
			ob.style.top = e.pageY-Y;
			ob.style.left = e.pageX-X;
		}
		else {
			ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
			ob.pixelTop = event.clientY-Y + document.body.scrollTop;
			return false;
      }
   }
}

function MU() {
	ob = null;
}

if (N) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}



//Use this to read querystring parameters
function GetNVP(NVPString,NVPid){
	var NVPFound=false;
	var NVPArray=new Array();
	var NVPList=NVPString.split('&');

	for (x=0; x<NVPList.length; x++){
		NVPData=NVPList[x].split('=');
		NVPArray[NVPData[0]]=NVPData[1];
	}

	for (var LocalID in NVPArray)
		if(NVPid==LocalID)NVPFound=true;

	if (NVPFound)return (NVPArray[NVPid]);
	else return ('Name not found');
} 


// function taken from http://www.notestips.com/80256B3A007F2692/1/NAMO5RNV2S#23
function wordhighlight(aSourceObject, aWords){
	//Extract HTML Tags
	if(aSourceObject == null)return false;
	
	regexp=/<[^<>]*>/ig;
	vHTMLArray = aSourceObject.innerHTML.match(regexp);
	//Replace HTML tags
	vStrippedHTML = aSourceObject.innerHTML.replace(regexp,"$!$");

	//alert(vStrippedHTML);

	//Replace search words
	regexp= new RegExp ("(" + aWords + ")", "gi");
	vTemp = vStrippedHTML.replace(regexp,'<span id="hl">$1</span>');

	//Reinsert HTML
	for(i=0;vTemp.indexOf("$!$") > -1;i++){
	vTemp = vTemp.replace("$!$", vHTMLArray[i]);
	}

	//Diaply Result
	aSourceObject.innerHTML = vTemp;
	//alert(vTemp);
}

function CheckSelectedBusinesses(){
	//Check previously selected business checkboxes
	var s = getCookie("CompareBsnsType" + window.parent.document.getElementById("ddlBsns").value)
	var arrBsnsIDs = new Array()

	if(s != null){
		arrBsnsIDs = s.split(",")
		for(var a in arrBsnsIDs){
			try{document.getElementById("chk"+arrBsnsIDs[a]).checked=true;}
			catch(ex){}
		}
	}
}

function ReloadParentPage(){
	document.location = document.location;
}

//A VB.net function (same name) is used to build folder names based on the picture file name on pics.FunctionHalls.com website
//The picture files are stored in respective folders.
//Build folder name with similar logic to access the picture file
function PictureFolderNameBuild(f){
	var fileNameLen = 0;
	var folderName=""
	var strChar=""
	var folderNameLen = 3;

	//Get file name without extention
	f = f.slice(0,f.lastIndexOf(".")).toUpperCase()
	fileNameLen = f.length - 1;

	//Get the first folderNameLen alphabets
	for(i=0;i<=fileNameLen;i++){
		strChar = f.charAt(i)
		if(f.charCodeAt(i) >= 65 && f.charCodeAt(i) <= 90) folderName += strChar
		if(folderName.length == folderNameLen) break;
	}

	for(i=folderName.length;i<folderNameLen;i++){folderName += "_"}
	return folderName;
}

function WordKeyPress(e){
	var key = ""
	var name = ""

	if (navigator.appName.indexOf("Netscape") != -1){
		key = e.which;
		name = e.target.name;
	} 
	else{
        key = window.event.keyCode;
        name = e.srcElement.name;
	}

	//Jump to password box
	if(key == 13 && name == "txtWord"){
		SearchByWord()
	}
}

function SearchByWord(){
	var t = ""
	var w = document.getElementById("txtWord").value
/*
	if(document.getElementById("ddlCity")){
		t = parent.window.document.getElementById("ddlCity").value
	}
*/
	t += " Service Providers Index -- "
	
	MsgWndShow2("", t + "Search By Word", 20, -13, 650, 400, strHostRoot + "/SearchByWord.aspx?Word=" + escape(w))
}


function CustSprtDefaultsSet(sSubj, iTpltID){
	setCookie("CustSprtSubj",sSubj,"","/")
	setCookie("CustSprtTpltID",iTpltID,"","/")

	document.location = "../Misc/CustSprt.aspx"
}

var bolFlag = 0
function FlashSearchBG(){
	if(document.getElementById("txtWord")){
		if(bolFlag == 0)document.getElementById("txtWord").style.backgroundColor = "Yellow"
		else document.getElementById("txtWord").style.backgroundColor = "White"
		
		if(bolFlag == 0){
			setTimeout("FlashSearchBG()", (1 * 1000));
			bolFlag = 1
		}
		else{
			setTimeout("FlashSearchBG()", (5 * 1000));
			bolFlag = 0
		}
	}
}

//Returns the position of a given element
function getAbsolutePosition(element){
    var ret = new Point();
    for(; 
        element && element != document.body;
        ret.translate(element.offsetLeft, element.offsetTop), element = element.offsetParent
        );
        
    return ret;
}

//Supporting function for the above
function Point(x,y){
        this.x = x || 0;
        this.y = y || 0;
        this.toString = function(){
            return '('+this.x+', '+this.y+')';
        };
        this.translate = function(dx, dy){
            this.x += dx || 0;
            this.y += dy || 0;
        };
        this.getX = function(){ return this.x; }
        this.getY = function(){ return this.y; }
        this.equals = function(anotherpoint){
            return anotherpoint.x == this.x && anotherpoint.y == this.y;
        };
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
