﻿// JScript File

//array of javascript commands to run on page load
arrOnLoad = new Array();


//const 
var IsLoggedOn;
var scriptOnLogon = "";
var scriptIfLogon = "";
var defaultLogonScript = "";
var curUserID = -1;

function ufdSearch()
{
    try
    {
        displaySearch();
        return;
    }
    catch(err){}
    
    redirect('BrowseResorts.aspx');
}

function raiseError() {
  throw "some error";
}

function notDone()
{
    alert('sorry, this bit aint done yet');
}


function runResultAsJS(result, eventArgs)
{
    try
    {
        if(result != "")
        {
    
            eval(result);
        }
    }catch(err){}
    
}

function runPageLoadScripts()
{
    try
    {
        for(var i=0; i<arrOnLoad.length;i++)
        {
            try
            {
                eval(arrOnLoad[i]);
            }catch(err){
                //ignore any scripts that faile
            }
        }
    }
    catch(err){//in case not defined
    }
}

function addPageLoadScript(scriptName)
{
    try
    {
        arrOnLoad[arrOnLoad.length] = scriptName;
    }
    catch(err)
    {
    }
}


function openNew(url)
{
    window.open(url);
}

function openSmall(url)
{
    window.open(url,'tc','width=400,height=500,toolbar=no,scrollbars=yes');
}


function chat()
{
    window.open("http://apps.facebook.com/upflatdown/?cmd=Chat",'tc','width=800,height=600,toolbar=no,scrollbars=yes');
}


function resetLogonScripts()
{
    try
    {
        scriptIfLogon = "";
        scriptOnLogon = defaultLogonScript;
    }
    catch(err){}
    
}

function setDefaultLogonScript(astrScript)
{
    defaultLogonScript = astrScript;
    scriptOnLogon = astrScript;
}

function recordLogOff()
{
    IsLoggedOn=false;
}

function recordLogOn(userID)
{
    try
    {
        IsLoggedOn=true;
        curUserID = userID;
        //run scripts
        if(scriptOnLogon != "")
        {
            eval(scriptOnLogon);
        }
    }
    catch(err){}
    
    //reset scripts no matter what
    resetLogonScripts();
    
}

function logon()
{
    runAfterLogon();
}

function checkLoggedOn()
{
    try
    {  
        if(!IsLoggedOn)
        {
            //not logged on so show the logon panel
            displayLogon();
        }
        return;
    }
    catch(err)
    {
    }
}


function runAfterLogon(astrJS)
{
    try
    {
    
        //if already logged on then just run
        if(IsLoggedOn)
        {       
            try
            {
                eval(astrJS);
            }catch(err){//ignore any script errors
            }
            return;
        }
    
        //this will run ok if tools control displayed
        scriptOnLogon = "hidePopup();" + astrJS + ";forcePostBack()";
        displayLogon();
        return;
    }
    catch(err){}

    //if got here then tools control not vis so need to redirect to logon page
    redirect('Logon.aspx');
}

function getURLParameters() 
{

	var sURL = window.document.URL.toString();
	var arrParam;
	var arrParamList;
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");	
		var arrParamList = arrParams[1].split("&");
		return arrParamList;
    }
    else
        return null;		
}




function getParamValue(astrParamName, arrParams) 
{
    try
    {
 	    for (var i=0;i<arrParams.length;i++)
	    { 
			    var sParam =  arrParams[i].split("=");
    			
			    if(sParam[0]==astrParamName)
			    {
			        return sParam[1];
			    }
	    }		
    }catch(err){}	

    return "";

}


    function updateUrlParam(url, paramName, paramValue)
    {
        var lintIndex;
        var lstrNewUrl = "";
        lintIndex = url.indexOf("?", 0);
        if(lintIndex < 0)
		{
		    //no existing params
			lstrNewUrl = url + "?" + paramName + "=" + paramValue;
			
		}
		else 
		{
		    var lintIndex = url.indexOf(paramName + "=", lintIndex);
		    //see if tab is already an index
		    if (lintIndex < 0)
		    {
		        //no so add param
		        lstrNewUrl = url + "&" + paramName + "=" + paramValue;
			}
			else
			{    			
			
		        //tab already exists so need to move it first
		        var lstrNewUrl = url.substring(0, lintIndex);
		        lstrNewUrl = lstrNewUrl + "Tab=" + paramValue;
		        //if params after this one need to add them back in
		        var lintIndex = url.indexOf("&", lintIndex);
		        if(lintIndex > 0)
		        {
		            lstrNewUrl = lstrNewUrl + url.substring( lintIndex);
		        }    
			}    
			
			
		}
		
		return lstrNewUrl;
		    
	}
  


    function findTab(tabCtlName, tabId)
    {
        var tabCtl = $find(tabCtlName);
        var tabList = tabCtl.get_tabs();
        var tabFound = false;
        for(var i=0; i < tabList.length;i++)                    {
            
            if(tabList[i].get_id() == tabId)
            {
                tabFound = true;
                break;
            }                        
        }          
        
        if(tabFound)
        {
            return i;
        }      
        else
        {
            return -1;
        }
    } 
    
    
    function changeTab(newTab)
    {
       
		var lstrUrl = "";
		lstrUrl  = updateUrlParam(location.href, "Tab", newTab);
		if(lstrUrl == "")
		{
		    //an error happened so refresh current page
		    lstrUrl = location.href;
		}
		window.location= lstrUrl;
		
	}                
 
function redirect(url)
{
    window.location = url;
}

function redirectAfterLogon(url)
{
    var lstrAction;    
    lstrAction = "redirect('" + url + "');"
    
    RunAfterLogon(lstrAction);
}



    function changeClass(divName, className)
    {
        try{
            var el =  document.getElementById(divName);
            el.className = className;
        }catch(err){        
        }
    }


    function highlightBox(divName)
    {
        try{
            var el =  document.getElementById(divName);
            el.style.borderColor = "White";
        }catch(err){        
        }
    }
    function unHighlightBox(divName)
    {
        try{
            var el =  document.getElementById(divName);
            el.style.borderColor = "Black";
        }catch(err){}
    }
    
    function updateBoxBorder(divName, color)
    {
        try{
            var el =  document.getElementById(divName);
            el.style.borderColor = color;
        }catch(err){        
        }
    }
    

    function highLightMenu(elName)
    {
        try
        {
            var el = document.getElementById(elName);
            el.style.borderColor = "White";
        }
        catch(err)
        {
        }
    }

    function unhighLightMenu(elMenu)
    {
        try
        {
            var el = document.getElementById(elMenu);
            //check menu not open
            el.style.borderColor = "Black";
        }
        catch(err)
        {
        }
    }




    function highLightMenuItem(elName)
    {
        try
        {
            var el = document.getElementById(elName);
            el.className = "subMenuItemSelect";;
        }
        catch(err)
        {
        }
    }

    function unhighLightMenuItem(elName)
    {
        try
        {
            var el = document.getElementById(elName);
            el.className = "subMenuItem";
        }
        catch(err)
        {
        }
    }


        function highLightMainMenu(elName)
        {
            try
            {
                var el = document.getElementById(elName);
                el.className = "mnuMainItemHover";
            }
            catch(err){}
            
        }


        function unHighLightMainMenu(elName)
        {
            try
            {
                var el = document.getElementById(elName);
                el.className = "mnuMainItem";
            }
            catch(err){}
            
        }


        function highLightContactMenu2(elName)
        {
            try
            {
                var el = document.getElementById(elName);
                el.className = "contactMenuSelect";
            }
            catch(err){}
            
        }


        function unHighLightContactMenu2(elName)
        {
            try
            {
                var el = document.getElementById(elName);
                el.className = "contactMenu";
            }
            catch(err){}
            
        }

    function toggleElDisplay(elName)
    {
        try
        {
            var el = document.getElementById(elName);
            if(el.style.display == "none")
            {
                el.style.display = "block";
            }
            else
            {
                el.style.display = "none";
            }
            
        }
        catch(err)
        {
        }
        
    }
    
    function displayEl(elName)
    {
        try
        {
            var el = document.getElementById(elName);
            el.style.display = "block";
            
        }
        catch(err)
        {
        }
        
    }

    function displayMenu(elMenuName, elMenuSelectName, elMenuItemsName)
    {
        try
        {
            var elMenu = document.getElementById(elMenuName);
            var elMenuSelect = document.getElementById(elMenuSelectName);
            var elMenuItems = document.getElementById(elMenuItemsName);
            elMenu.style.display = "none";
            elMenuSelect.style.display = "block";
           elMenuItems.style.display = "block";
        }
        catch(err)
        {
        }
    }

    function replaceElement(elCurrentName, elNewName)
    {
        try
        {
            var elCurrent = document.getElementById(elCurrentName);
            var elNew = document.getElementById(elNewName);
            elCurrent.style.display = "none";
            elNew.style.display = "block";
        }
        catch(err)
        {
        }
    }

    function hideMenu(elMenuName, elMenuSelectName, elMenuItemsName)
    {
        try
        {
            var elMenu = document.getElementById(elMenuName);
            var elMenuSelect = document.getElementById(elMenuSelectName);
            var elMenuItems = document.getElementById(elMenuItemsName);
            elMenu.style.display = "block";
            elMenuSelect.style.display = "none";
           elMenuItems.style.display = "none";
        }
        catch(err)
        {
        }
    }

    function hideEl(elName)
    {
        try
        {
            var el = document.getElementById(elName);
            el.style.display = "none";
        }
        catch(err)
        {
        }
    }
    function showElement(elName)
    {
        try
        {
            var el = document.getElementById(elName);
            el.style.display = "block";
        }
        catch(err)
        {
        }
    }



    function redirect(href)
    {
        try
        {
            location.href = href;
        }
        catch(err)
        {
        }
    }
    
    function editGeneral()
    {
    
        location.href="EditMyProfile.aspx";
    }

    function editMyRiding()
    {
        location.href="EditMyProfile.aspx?Tab=1";
    }

    function editMyInterests()
    {
        location.href="EditMyProfile.aspx?Tab=2";
    }
    function editMyGallery()
    {
        location.href="EditMyProfile.aspx?Tab=3";
    }

    function FCKUpdateLinkedField(id)
    {
        try
        {
            if(typeof(FCKeditorAPI) == "object")
            {
                FCKeditorAPI.GetInstance(id).UpdateLinkedField();
            }
        }
        catch(err)
        {
        }
    }

    
/************** standard messages****************/    

function companyMsg_NotAvailable()
{
    alert('Sorry, this information is not available at the moment.  Please send a message to the company direct via the send mail button.');
}
function resortMsg_NotAvailable()
{
    alert('Sorry, this information is not available at the moment.  Please send a message to the resort direct via the the send mail button.');
}


/*************** load apis ************/
function loadMapCode()
     {
        try
        {
            //start load of map code
	        var head = document.getElementsByTagName("head")[0];
	        var s = document.createElement('script');
	        s.id = 'VEScript';
	        s.type = 'text/javascript';
	        //version 3
	        //s.src = "http://maps.live.com/veapi.ashx?v=1.3.0908172755.52";
	        //version 4
	        //s.src = "http://maps.live.com/veapi.ashx?v=1.3.0908172755.52";
            //version 5
            s.src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5";
            
            //latest
	        //s.src = "http://local.live.com/veapi.asjx";
	        //slow
	        //s.src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"

	        head.appendChild(s);       
            
            
        }catch(err){
            
            return false;
        }
     }
