var br_ie = false;
var br_ns = false;
var br_opera = false;
var t_id
var pos = 0;
var dir = 2;
var len = 0;

var oWnd;
var myTimer;
var theTimeout = "20:00";

function DefineBrowser() {
    var user_agent = navigator.userAgent.toLowerCase();
    if (user_agent.indexOf("opera") != -1)
        br_opera = true;
    else {
        if (user_agent.indexOf("webtv") == -1) {
            if (user_agent.indexOf("msie") != -1)
                br_ie = true;
            else {
                if (user_agent.indexOf("compatible") == -1 && user_agent.indexOf("spoofer") == -1 && user_agent.indexOf("hotjava") == -1)
                    br_ns = true;
            }
        }
    }

    if (!br_opera && !br_ie && !br_ns)
        alert("The browser you are using is not supported.  Some functionality will be lost.");
}

DefineBrowser();

String.prototype.trim = function() {
    var temp_str = this;
    while (temp_str.charAt(0) == ' ')
        temp_str = temp_str.substr(1, temp_str.length - 1);
    while (temp_str.charAt(temp_str.length - 1) == " ")
        temp_str = temp_str.substr(0, temp_str.length - 1);

    return temp_str;
}
String.prototype.endsWith = function(value) {
    if (this.length < value.length)
        return false;

    if (this.substr(this.length - value.length, value.length) == value)
        return true;

    return false;
}
Array.prototype.contains = function(value) {
    for (var it = 0; it < this.length; it++) {
        if (this[it] == value)
            return true;
    }
    return false;
}
function GetElementById(value) {
    for (var i = 0; i < document.all.length; i++) {
        if (document.all[i].id != null &&
            document.all[i].id.length >= value.length &&
            document.all[i].id.indexOf(value) != -1)
            return document.all[i];
    }
    return null;
}
function aspKeyDown(iKeyCode, sFunc, e) {
    if (e == null)
        e = window.event;

    if (e.keyCode == iKeyCode) {
        eval(unescape(sFunc));
        return false;
    }
}
function PreviewHtmlInNewWindow(bodyText, params) {
    var w = window.open('', '_blank', params, true);
    var res, pattern;
    pattern = /__quote__/g;
    res = bodyText.replace(pattern, "'");
    pattern = /__dblquote__/g;
    res = res.replace(pattern, "\"");
    w.document.write(res);
    if (br_ie) {
        status = "";
      
    }
}
function PreviewHtmlInPrintPage(url, bodyText, params) {
    var w = window.open(url);
    var res, pattern;
    pattern = /__quote__/g;
    res = bodyText.replace(pattern, "'");
    pattern = /__dblquote__/g;
    res = res.replace(pattern, "\"");
    w.document.write(res);
    w.document.close();

    if (br_ie) {
        status = "";
        
    }
}
function CustomValidateInteger(source, arguments) {
    if (arguments.Value == "-2147483648")
        arguments.IsValid = false;
    else
        arguments.IsValid = true;
}
function CheckForSlowValidation() {
    if (typeof (Page_ClientValidate) == 'function' && Page_IsValid == false) {
        status = '';
    }
}
function attrBtnHover(sender, over, e) {
    var cells = sender.rows[0].cells;
    if (over) {
        var re = /-up-/g;
        for (var i = 0; i < cells.length; i++)
            cells[i].style.backgroundImage = cells[i].style.backgroundImage.replace(re, '-over-');

        if (document.attrBtnHint == null && sender.getAttribute('hint') != null) {
            if (!e)
                e = window.event;

            if (document.attrBtnHintTimeout != null)
                window.clearTimeout(document.attrBtnHintTimeout);
            document.attrBtnHintTimeout = window.setTimeout("attrBtnShowHint('" + sender.getAttribute('hint') + "'," + e.clientX + "," + e.clientY + ");", 1000);
        }
    }
    else {
        var re = /-over-/g;
        for (var i = 0; i < cells.length; i++)
            cells[i].style.backgroundImage = cells[i].style.backgroundImage.replace(re, '-up-');

        if (document.attrBtnHintTimeout != null)
            window.clearTimeout(document.attrBtnHintTimeout);

        if (document.attrBtnHint != null) {
            document.body.removeChild(document.attrBtnHint);
            document.attrBtnHint = null;
        }
    }
}
function attrBtnShowHint(hint, x, y) {
    document.attrBtnHint = document.createElement("DIV");
    document.attrBtnHint.innerHTML = "<div style='dispaly=block;background-color:#f9f7de;padding:3px 5px 3px 5px; border:solid 1px #967b68;font-size:10px;color:#967b68'>" + hint + "</div>";
    document.attrBtnHint.style.position = "absolute";
    document.attrBtnHint.style.left = x + 5 + document.body.scrollLeft; ;
    document.attrBtnHint.style.top = y + 5 + document.body.scrollTop;

    document.body.appendChild(document.attrBtnHint);
}
var reqRollUp;
var reqUnroll;
function InitializeXMLHttpRequest(req) {
    if (req != null)
        req.abort();

    try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (oc) { req = null; }
    }
    if (!req && typeof XMLHttpRequest != "undefined")
        req = new XMLHttpRequest();

    if (br_ie) {
        status = "";
      
    }

    return req;
}
function rollupModule(sender, contName) {

    var rollup = (sender.src.toLowerCase().indexOf("-unroll") == -1);
    var pmid = sender.getAttribute("pmid");
    var url = document.utilityPagePath + "?app=" + document.applicationId + "&pmid=" + pmid + "&modrup=" + rollup + "&time=" + (new Date()).getTime();

    if (rollup) {
        document.getElementById(contName).innerHTML = "";
        var re = /-roll/g;
        sender.src = sender.src.replace(re, '-unroll');
        reqRollUp = InitializeXMLHttpRequest(reqRollUp);
        reqRollUp.onreadystatechange = function() { };
        reqRollUp.open('GET', url, true);
        reqRollUp.send(null);
    }
    else {
        reqUnroll = InitializeXMLHttpRequest(reqUnroll);
        reqUnroll.onreadystatechange = function() {
            if (reqUnroll.readyState == 4 && reqUnroll.status == 200) {
                document.location.reload(true);
            }
        };
        reqUnroll.open('GET', url, true);
        reqUnroll.send(null);
    }

    return false;
}
function ShowProcessing() {
    window.setTimeout("CheckForSlowValidation()", 500);
}
function askConfirmationAndDisableButton(msg, btnCilentID) {
    var btn = document.getElementById(btnCilentID);
    if (!btn.disabled && confirm(msg)) {
        btn.style.visibility = 'hidden';
        ShowProcessing();
        return true;
    }
    return false;
}
function fontHover(sender, over, e) {
    if (over) {
        if (!e)
            e = window.event;
        if (document.attrBtnHint == null && sender.getAttribute('hint') != null) {
            if (document.attrBtnHintTimeout != null)
                window.clearTimeout(document.attrBtnHintTimeout);
            document.attrBtnHintTimeout = window.setTimeout("attrBtnShowHint('" + sender.getAttribute('hint') + "'," + e.clientX + "," + e.clientY + ");", 1000);
        }
    }
    else {
        if (document.attrBtnHintTimeout != null)
            window.clearTimeout(document.attrBtnHintTimeout);
        if (document.attrBtnHint != null) {
            document.body.removeChild(document.attrBtnHint);
            document.attrBtnHint = null;
        }
    }
}
function Integer(chr) {
      var eventInstance = window.event ? event : e;
        var keycode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;

    if (!(keycode >= 48 && keycode <= 57))
        event.keyCode = 0;
}
function Decimal(value) {
        var eventInstance = window.event ? event : e;
        var keycode = eventInstance.charCode ? eventInstance.charCode : eventInstance.keyCode;

    if (!(keycode >= 48 && keycode <= 57) && !(keycode == 46))
        event.keyCode = 0;

    if (value.indexOf(".") != -1 && keycode == 46)
        event.keyCode = 0;
}
function ReadOnly() { window.event.returnValue = false; }
function TextAreaMaxLength(objTextArea, maxLength) {
    if (objTextArea.value.length > maxLength - 1)
        window.event.keyCode = 0;
}
function DoPaste(control, maxLen) {
    var value = control.value;

    event.returnValue = false;

    if (maxLen == 0) {
        control.value = "";
    }
    else {
        var oTR = control.document.selection.createRange();
        var iInsertLength = parseInt(maxLen, 10) - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}
function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
					((expires) ? "; expires=" + expires.toGMTString() : "") +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");

    document.cookie = curCookie;
}
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));
}
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 showCookies() {
    var win = window.open();
    var cookies = document.cookie.split("; ");
    for (var i = 0; i < cookies.length; i++)
        win.document.write(cookies[i] + "<br /><br />");
}
function SetRequired() {
    var inputs = document.getElementsByTagName("input");
    var i = 0;
    for (i = 0; i < inputs.length; i++) {

        if (inputs[i].type == 'text' || inputs[i].type == 'textarea') {

            if (inputs[i].required != 'undefined') {
                if (inputs[i].required == 'required') {
                    if (inputs[i].value == "") {
                        inputs[i].style.backgroundColor = '#f7dba5'; //'#FFD4DA';
                    }
                    else {
                        inputs[i].style.backgroundColor = 'white';
                    }
                }
            }
        }
    }
    var textArea = document.getElementsByTagName("textarea");
    for (i = 0; i < textArea.length; i++) {
        if (textArea[i].required != 'undefined') {
            if (textArea[i].required == 'required') {

                if (textArea[i].value <= 0) {

                    textArea[i].style.backgroundColor = '#f7dba5'; //'#FFD4DA';
                }
                else {
                    textArea[i].style.backgroundColor = 'white';
                }
            }
        }
    }
    var DropDowns = document.getElementsByTagName("select");
    for (i = 0; i < DropDowns.length; i++) {
        if (DropDowns[i].required != 'undefined') {
            if (DropDowns[i].required == 'required') {

                if (DropDowns[i].selectedIndex <= 0) {

                    DropDowns[i].style.backgroundColor = '#f7dba5'; //'#FFD4DA';
                }
                else {
                    DropDowns[i].style.backgroundColor = 'white';
                }
            }
        }
    }
}
function fnKeyPress(object) {
    if (object.value == "") {
        object.style.backgroundColor = '#f7dba5'; //'#FFD4DA';
    }
    else {
        object.style.backgroundColor = 'white';
    }

}
function AlphaNumericSpaceDash() {

    var keycode = event.keyCode;

    if (keycode != 32 && !(keycode >= 65 && keycode <= 90) && !(keycode >= 97 && keycode <= 122) && !(keycode >= 48 && keycode <= 57) && keycode != 45)
        event.keyCode = 0;
}

function closeCal() {
    try {
        hideCal();
    } catch (exception) { }

}
function AlphaNumericURL() {
    var keycode = event.keyCode;

    if (!(keycode >= 65 && keycode <= 90) && !(keycode >= 97 && keycode <= 122) && !(keycode >= 48 && keycode <= 57) && !(keycode == 45) && !(keycode == 46))
        event.keyCode = 0;
}

function ChangeUrl(textboxId, labelId) {
    if (document.getElementById(textboxId).value != '')
        document.getElementById(labelId).innerText = 'http://' + document.getElementById(textboxId).value;
    else
        document.getElementById(labelId).innerText = 'http://' + 'Help Link URL'
}

function ShowHelp(helplink) {
    if (helplink == "") {
        openHelpDialog('about:blank')
    }
    else {
        helplink = 'http://' + helplink;
        openHelpDialog(helplink)
    }
}

function openHelpDialog(url) {

    
    if (window.radopen) {
        var oWnd = window.radopen(url, "Help");
        oWnd.SetUrl(oWnd.GetUrl());
    }
    return false;
}

function OnClientCloseHelpDisplay(radWindow) {


    if (radWindow.Argument != null) {
        if (radWindow.Argument != '') {
        }
        else { }
    }
}

function ShowHideDiv(id) {
    try {
        obj = document.getElementById(id);

        if (obj.style.display == "none") {
            obj.style.display = "inline";

            if (chkBillingInformation != null) {
                if (!chkBillingInformation.checked)
                    dvBillingDetail.style.display = "block";
                if (!chkShippingInformation.checked)
                    dvShippingDetail.style.display = "block";
            }
        }
        else {
            obj.style.display = "none";

        }
    }
    catch (exception) { }

    return false;

}


function SetClickForButton(e) {
   
    if (window.event) {
        var obj;
        obj = event.srcElement;

        if (obj.id != "") {

            __doPostBack(btnTestForFont, event.srcElement.id);

        }
    }
    else {
        var obj;
        obj = e.target;
        if (obj.id != "") {

            __doPostBack(btnTestForFont, e.target.id);

        }
    }
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

/*
    Comented By: Amit Khandhediya
    Reason:      Keep AJAX loader on center of Page.   
    Date:        13th June 2009
*/
var updateProgressId;
function adjustDivs()
{
    
    try
    {   
        dfs=document.getElementById(updateProgressId).style;
        dfs.position='absolute' ;
        dfs.zindex='20000';
        
        if(window.innerWidth)
        {
            
            dfs.left = (window.innerWidth / 2 + document.body.scrollLeft);
            dfs.top = (window.innerHeight / 2 + document.body.scrollTop);
        }
        else
        {
            
            dfs.left =(document.documentElement.offsetWidth/2 + document.body.scrollLeft);
            dfs.top = (document.documentElement.offsetHeight/2 + document.body.scrollTop);
        }
    }
    catch(exception){}
}
window.onload=adjustDivs;
window.onresize=adjustDivs;
window.onscroll=adjustDivs;
/*
    End Commented: Amit Khandhediya
*/


/* AdminToolbar.js functions */

function admToolOver(sender)
{
  sender.rows[0].cells[1].className='admtool_mid_selected';
  var im = sender.rows[0].cells[1].childNodes[0];
  var re = /-up/g;
  im.src = im.src.replace(re, '-over');
}
function admToolOut(sender)
{
  sender.rows[0].cells[1].className='admtool_mid';
  var im = sender.rows[0].cells[1].childNodes[0];
  var re = /-over/g;
  im.src = im.src.replace(re, '-up');
}

/* End AdminToolbar.js functions */

// Session timed out
function Minutes(data) 
{
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(0, i));
}
function Seconds(data) 
{
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(i + 1, data.length));
}
function Display(min, sec) 
{
var disp;
if (min <= 9) disp = " 0";
else disp = " ";
disp += min + ":";
if (sec <= 9) disp += "0" + sec;
else disp += sec; 
return (disp);
}
function Down() 
{   
        sec--;      
        if (sec == -1) 
        { 
        sec = 59; min--; 
        }
        //window.status = "Session will time out in: " + Display(min, sec);
        if (min == 0 && sec == 0) 
            {
            var Common_labilabi = Common_Get_Cookie("labilabi");
            if(Common_labilabi == null)
            {
            }
            else
            {
            if(Common_labilabi == "inside down")
                return;
                
            var value="inside down";
            var path = "/";
            var domain = "";
            var secure = "";
            // set time, it's in milliseconds
            var today = new Date();
            today.setTime( today.getTime() );
            // minutes:  expires = 2 * 1000 * 60;
            expires = 1 * 1000 ;  //seconds
            var expires_date = new Date( today.getTime() + (expires) );
            document.cookie = "labilabi" + "=" +escape( value ) +
            ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
            ( ( path ) ? ";path=" + "/" : "" ) +
            ( ( domain ) ? ";domain=" + "" : "" ) +
            ( ( secure ) ? ";secure" : "" );            
            __doPostBack('ctl00$login$mppLoginView$btnLogin','');
            return;                
			} 
			
			           
                var objLogout1 = document.getElementById('ctl00_login_mppLoginView_btnLogout');
                if(objLogout1 == null)
                {
                    //alert(document.utilityPagePath);
                    if(document.getElementById('ctl00_CPH_ctl02_BM_mppLogin_UserName') != null)
                    {
                        //alert("dont sent back again");
                        return;
                    }

                }
                else
                {
                var _url = this.window.location.protocol + "//" + this.window.location.host + "" + document.utilityPagePath.replace("utilities/utility.aspx", "")	            
	            try
	            {
	                oWnd = window.radopen(_url + 'Controls/Users/TimeOutSession.htm','SessionExpired');
	                oWnd.SetUrl(oWnd.GetUrl());
	                oWnd.SetTitle('Your Session Expired');
                    var height = 250; 
                    var width = 350; 
                    oWnd.SetSize(width, height);	            
	                oWnd.Center();
	                //myTimer = setTimeout("logMeOff()", 20000);
	                myTimer = setTimeout("fnLogoutPostBack();", 20000);
	            }
	            catch(e)
	            {
	            ;
	            }
                window.onscroll = setposition;
                window.onresize = setposition;	            
                return;
                }
            }
        else 
            myTimer = setTimeout("Down()", 1000);
}
function timeIt() 
{
    min = 1 * Minutes(theTimeout);
    sec = 0 + Seconds(theTimeout);
    Down();
}
function endTime()
{
    try
        {
        clearTimeout(myTimer);
        document.attrBtnHint.innerHTML = "";
        }
    catch(e)
        {
        ;
        }
}
function showTime()
{
document.attrBtnHint.innerHTML = "";
    try
        {
        clearTimeout(myTimer);
        timeIt(); 
        }
    catch(e)
    {
    ;
    }
}
function logMeOff()
{
//alert("back in logMeOff()");
/*
var objLogout = document.getElementById('ctl00_login_mppLoginView_btnLogout');
if( objLogout != null)
    {
    __doPostBack('ctl00$login$mppLoginView$btnLogout',1);
    }
*/    
}
function setposition()
{
    var oWindow = GetSelectedWindow();
    if (! oWindow )
      {return ;}
      
    oWindow.Center();
}
function GetSelectedWindow()
{
    var oManager = GetRadWindowManager();
    return oManager.GetActiveWindow();		
}
function Common_Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
//timeIt();