﻿// JScript File

function showHover(inString, inObj) 
{
    var myHov = document.getElementById('infoHover');
    myPos = findPos(inObj);
    myHov.style.left = (myPos[0] + 7) + 'px';
    myHov.style.top = (myPos[1] + 18) + 'px';
    myHov.innerHTML = inString;
}

function hideHover()
{
    var myHov = document.getElementById('infoHover');
    myHov.style.left = '-1000px';
    myHov.style.top = '-1000px';
    myHov.innerHTML = '';
}

function findPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent)
    {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent)
        {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

function highlight(highlightRow)
{
    highlightRow.className = "price-selected";

    var i;
    for(i=0;i<highlightRow.cells.length;i++)
    {
        if(highlightRow.cells[i].className=="")
            { highlightRow.cells[i].className = highlightRow.cells[i].className + "price-selected"; }
        else
            { highlightRow.cells[i].className = highlightRow.cells[i].className + "-selected"; }
    }
}

function unhighlight(highlightRow)
{
    highlightRow.className = "price";

    var i;
    for(i=0;i<highlightRow.cells.length;i++)
    {
        if(highlightRow.cells[i].className=="price-selected")
            { highlightRow.cells[i].className = ""; }
        else if(highlightRow.cells[i].className=="price-weekend-selected")
            { highlightRow.cells[i].className = "price-weekend"; }
        else if(highlightRow.cells[i].className=="price-weekend-sold-selected")
            { highlightRow.cells[i].className = "price-weekend-sold"; }
        else if(highlightRow.cells[i].className=="price-sold-selected")
            { highlightRow.cells[i].className = "price-sold"; }
        else if(highlightRow.cells[i].className=="ap-name-selected")
            { highlightRow.cells[i].className = "ap-name"; }
    }
}

function RowSelected(rowObject) 
{ 
    var columnUniqueName  = rowObject.Owner.Columns[1].UniqueName; 
    var cell = rowObject.Owner.GetCellByColumnUniqueName (rowObject, columnUniqueName ); 
    alert(cell.innerHTML); bring
}

function CheckAll(pattern, bCheck)
{
     var inps = document.getElementsByTagName("INPUT");
     var i;
     for(i=0;i<inps.length;i++)
     {
          if(pattern =='' || inps[i].id.indexOf(pattern) >=0)
            inps[i].checked = bCheck;
     }
     return;
}

function checkUncheckAll(pattern, e)
{
     var inps = document.getElementsByTagName("INPUT");
     var i;
     try
     {
         for(i=0;i<inps.length;i++)
         {
              if(pattern =='' || inps[i].id.indexOf(pattern) >=0)
                inps[i].checked = e.checked;
         }
         return;     
     }
     catch (e)
     {
        alert(e.message);
     }
}

function CheckAllCheck(pattern, bCheck, bUncheck)
{
     var inps = document.getElementsByTagName("INPUT");
     var inps2 = document.getElementById(bUncheck);
     var i;
     var x = true;
     for(i=0;i<inps.length;i++)
     {
          if(pattern =='' || inps[i].id.indexOf(pattern) >=0)
            if(inps[i].checked==false)
                x = false;
     }
     inps2.checked = x;
     return;
}

function PopupForm(URL, page_id, height, width)
{
    PopupForm(URL, page_id, height, width, 'yes', 'yes', 'yes');
}

function PopupForm(URL, page_id, height, width, resizable, scrollbars, dialog)
{
    var WindowObj = window.open(URL,page_id,'height=' + height + 'px,width=' + width + 'px,resizable=' + resizable + ',scrollbars=' + scrollbars + ',dialog=' + dialog);
    WindowObj.focus();
}

function editKeyBoard(objTxt, strValidChars, e)
{
	var valid = false;
	if(!e) e=window.event;
	var key;
	
	key = e.keycode ? e.keycode : e.which;
	if (!key)
		key = window.event.keyCode;
		
	for(i = 0; i < strValidChars.length; i++) {
		if(key == strValidChars.charCodeAt(i)||key==8) {
			valid = true;
		}
	}

	if (!valid)
	{
		objTxt.focus();
		return valid;
	}
}

function hideCalendar() {
    var myArray = getElementsByClassName("yui-calcontainer");
    for(var i=0,j=myArray.length; i<j; i++) {
	    var myCalendar = myArray[i];
	    myCalendar.style.display = 'none';
    }
}

function changeGoButtonImage(){
    var myButtonArray = getElementsByClassName("btnGo");
    
    for(var i=0,j=myButtonArray.length; i<j; i++) {
	    var myButton = myButtonArray[i];
	    myButton.src = '/images/go-button-mini.gif';
    }
}

function getElementsByClassName(classname, node) {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
    if(re.test(els[i].className))a.push(els[i]);
    return a;
}

/*
    This function was created in an attempt to fix the problem described in
    GAS-529. As it stands the code below only fixes the problem in Firefox, Safari and some
    builds of IE6. Currently there is no solution for IE7, Opera and some builds of IE6.
*/
function restoreDropDownValue(dropDownList) {

    var qsValue = getQueryVariable('curID');
    var ddl = document.getElementById(dropDownList);
    var currencyValue = document.getElementById(document.getElementById('CurrencyValueId').value);
    if (qsValue == 0)
    {
        ddl.options[currencyValue.value].selected = true;
    }
    else
    {
        //make sure nothing is selected in the drop down
        for (var i=0; i<ddl.length; i++)
        {
            ddl.options[i].selected = false;
        }
        for (var i=0; i<ddl.length; i++)
        {
            if (ddl[i].value == qsValue)
            {
                ddl.options[i].selected = true;
                return true;
            }
        }
    }
    
    
}

/*
    This function retrieves the values from the query string.
    Param: variable
        This is the query string id and it is case sensitive.
*/
function getQueryVariable(variable) 
    { 
        var query = window.location.search.substring(1); 
        var vars = query.split("&"); 
        for (var i=0;i<vars.length;i++) 
        { 
            var pair = vars[i].split("="); 
            if (pair[0] == variable) 
            {
                return pair[1];
            }
        }
        
        return '0';
    } 