﻿function clearCache()
{
    if(window.screenLeft < 8000)
    {
    }
    else
    {
        if(window.parent.name == '')
        {
            var url = "./ClearCache.axd?";
            ProcessHttpRequest(url)
        }
    }
}

function ProcessHttpRequest(url)
{
	var sep = (-1 < url.indexOf("?")) ? "&" : "?"	
	url = url + sep + "__=" + encodeURIComponent((new Date()).getTime());	// make url unique. prevents caching url

	var theHttpRequest = getNewHttpObject();
	/* theHttpRequest.onreadystatechange = function() {processAjax();}; */
	theHttpRequest.open("GET", url, false);
	try
	{
		theHttpRequest.send(null);
	}
	catch(e)
	{
	   // error
	   return false;
	}
	
	if (theHttpRequest.status == 200) {
		return true;
   }
   else {
	  // error
	   return false;
   }
}


function Trim(TRIM_VALUE)
{
    if(TRIM_VALUE.length < 1)
    {
        return"";
    }
    TRIM_VALUE = RTrim(TRIM_VALUE);
    TRIM_VALUE = LTrim(TRIM_VALUE);
    if(TRIM_VALUE=="")
    {
        return "";
    }
    else
    {
        return TRIM_VALUE;
    }
} //End Function

function RTrim(VALUE)
{
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    if(v_length < 0)
    {
        return"";
    }
    var iTemp = v_length -1;

    while(iTemp > -1)
    {
        if(VALUE.charAt(iTemp) == w_space)
        {
       
        }
        else
        {
            strTemp = VALUE.substring(0,iTemp +1);
            break;
        }
        iTemp = iTemp-1;

    } //End While
    return strTemp;

} //End Function

function LTrim(VALUE){
    var w_space = String.fromCharCode(32);
    if(v_length < 1){
    return"";
    }
    var v_length = VALUE.length;
    var strTemp = "";

    var iTemp = 0;

    while(iTemp < v_length){
    if(VALUE.charAt(iTemp) == w_space){
    }
    else{
    strTemp = VALUE.substring(iTemp,v_length);
    break;
    }
    iTemp = iTemp + 1;
    } //End While
    return strTemp;
} //End Function

//Check if parameter is numeric
function check(contents)
{
    //Trim(contents);
    if ((contents != 0) && ((contents / contents) != 1)) 
    {
        //alert('Please enter only a number into this text box')
        return false;
    }
    else
    {
        return true;
    }
}

var saveBgColor = null;

function HighLight(obj, hoverBgColor) {
	saveBgColor = obj.style.backgroundColor;
	
	if (hoverBgColor == null || hoverBgColor == '')
		hoverBgColor = '#DFDFDF'
	
	if (obj.style != null)
		obj.style.backgroundColor = hoverBgColor;
}

function LowLight(obj) {
	if (obj.style != null)
		obj.style.backgroundColor = saveBgColor;
}


  /*
  Ranbir March 2006
  This function Checks All CheckBoxes in an DataGrid Using a Single CheckBox in the header

  call to the JavaScript function passes in the name of the CheckBox appearing on each row
  and the value of the check all CheckBox.
  
  aspCheckBoxID : This is the name of the CheckBox appearing on each row of the Datagrid
  checkVal : This is the value of the checkall check box in the Header  
 
  
  */
  function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal)
   {
        //generated control  name starts with a colon
        re = new RegExp(aspCheckBoxID)  
        for(i = 0; i < document.forms[0].elements.length; i++)
        {
            elm = document.forms[0].elements[i]
            if (elm.type == 'checkbox')
            {
                if (re.test(elm.name)) 
                {
                    elm.checked = checkVal;
                }
            }
        }
   } 
   
   String.prototype.endsWith = function(s){
	var reg = new RegExp(s + "$");
	return reg.test(this);
}

/* Using RadioButton Controls in a Repeater. RadioButton controls each have a unique ID but a common GroupName parameter. This allows the RadioButton controls to work together as a group. 
However, a Repeater mangles the control IDs and group names, causing them to not work correctly. The fix is a simple bit of JavaScript that you can add to pages with Repeaters and RadioButton controls*/
function SetUniqueRadioButton(nameregex, current) {
    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;
}

$(document).ready(function() {
    var currentTime = new Date();
    $.get("./maintenance.txt?" + currentTime, function(txt) {
        if (txt != "")
            $('#maintenanceMessage').html(txt);
            /*$('#maintenanceMessage').width(300);*/
    });
});

/* Call to WS. Incase we need to hit DB.
$(document).ready(function() {
    $.get("./ws/qfleetinternal.asmx/GetMaintenanceMessage", function(xml) {
        var txt = $(xml).find("string").text();
        if (txt != "")
        $('#maintenanceMessage').html(txt);
    });
});
*/