﻿function clearConcurrentLoginCache() {
    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);
}

function isBlank(text) {
    return !text || /^\s*$/.test(text);
}

function isDate(x) {
    return (null != x) && !isNaN(x) && ("undefined" !== typeof x.getDate);
}

/* 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;
}

function openWindow(url) {
    // window.open(url, 'somerandomname', 'width=' + w + ',height=' + h + ',resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=no,status=no,menubar=no,copyhistory=no');
    var winRef = window.open(url, 'somerandomname');
    if (!_hasPopupBlocker(winRef))
        window.location.href = url;
    
}

function _hasPopupBlocker(poppedWindow) {
    var result = false;

    try {
        if (typeof poppedWindow == 'undefined') {
            // Safari with popup blocker... leaves the popup window handle undefined
            result = true;
        }
        else if (poppedWindow && poppedWindow.closed) {
            // This happens if the user opens and closes the client window...
            // Confusing because the handle is still available, but it's in a "closed" state.
            // We're not saying that the window is not being blocked, we're just saying
            // that the window has been closed before the test could be run.
            result = false;
        }
        else if (poppedWindow && poppedWindow.test) {
            // This is the actual test. The client window should be fine.
            result = false;
        }
        else {
            // Else we'll assume the window is not OK
            result = true;
        }

    } catch (err) {
        //if (console) {
        //    console.warn("Could not access popup window", err);
        //}
    }

    return result;
}

// Creating custom :external selector
$.expr[':'].external = function (obj) {
    return !obj.href.match(/^mailto\:/i)
            && !obj.href.match(/^javascript\:/i)
            && (obj.hostname != location.hostname);
};

$(document).ready(function () {
    var currentTime = new Date();
    $.get("./maintenance.txt?" + currentTime, function (txt) {
        if (txt != "")
            $('#maintenanceMessage').html(txt);
        /*$('#maintenanceMessage').width(300);*/
    });

    /*// hide input boxes that have 0 width - Kiran 8/31/2010
    $("input:text[width='0']").each(function () {
    $(this).hide();
    });
    */

    $("input:text").each(function () {
        if ($(this).width() == '0')
            $(this).hide();
    });

    /* Kiran 3/9/2011. This is sort of a hack. Tooltip is set with title tag however qfleet uses alt tag. So set title from alt if title is empty*/
    $("img").each(function (i) {
        var $this = $(this);
        var alt = $this.attr("alt");
        var title = $this.attr("title");

        if (title == "" && alt != "") {
            $this.attr("title", alt);
        }
    });

    var zIndexNumber = 1000;
    $('table').each(function () {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 10;
    });

    $('div').each(function () {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 10;
    });

    // $('a:external').attr({ target: "_blank" });
});

/* 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);
    });
});
*/
