﻿//Browser object - Start
function emi_Browser()
{
	d=document;
	this.agt=navigator.userAgent.toLowerCase();
	this.major=parseInt(navigator.appVersion);
	this.dom=(d.getElementById);
	this.ns=(d.layers);
	this.ns4up=(this.ns && this.major>=4);
	this.ns6=(this.dom&&navigator.appName=="Netscape");
	this.op=(window.opera);
	if(d.all)this.ie=1;else this.ie=0;
	this.ie4=(d.all&&!this.dom);
	this.ie4up=(this.ie&&this.major>=4);
	this.ie5=(d.all&&this.dom);
	this.ie6=(d.nodeType);
	this.sf=(this.agt.indexOf("safari")!=-1);
	this.win=((this.agt.indexOf("win")!=-1)||(this.agt.indexOf("16bit")!=-1));
	this.winme=(this.agt.indexOf("win 9x 4.90")!=-1);
	this.xpsp2=(this.agt.indexOf("sv1")!=-1);
	this.mac=(this.agt.indexOf("mac")!=-1);
}
var oBw=new emi_Browser();
//Browser object - End

//Floating Help - Start
var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
function hidelayer(lay)
{
	if (ie4) {document.all[lay].style.visibility = "hidden";}
	if (ns4) {document.layers[lay].visibility = "hide";}
	if (ns6) {document.getElementById([lay]).style.display = "none";}
}
function showlayer(lay)
{
	if (ie4) {document.all[lay].style.visibility = "visible";}
	if (ns4) {document.layers[lay].visibility = "show";}
	if (ns6) {document.getElementById([lay]).style.display = "block";}
}

function ShowHide(divId)
{
	var id = document.getElementById(divId);
	if (id.style.display == "none")
	{
		eval("id.style.display = 'block';");
	}
	else
	{
		eval("id.style.display = 'none';");
	}
}

//Floating Help - End
function emi_pop(s)
{
	var emipop = window.open(s,"emi_pop","width=520,height=500,scrollbars=yes,resizable=yes");
	emipop.focus();
}

function emi_preview(s)
{
	var pv_win = window.open(s,"emi_pv","width=560,height=380,scrollbars=yes,resizable=yes");
	pv_win.focus();
}

function upload_pop(s)
{
	var upop = window.open(s,"upload_pop","width=380,height=220,scrollbars=no,resizable=yes,left=200,top=250");
	upop.focus();
}

//Please wait... Start
function hideload() { document.getElementById('loading').style.display = 'none'; }
function showload() { document.getElementById('loading').style.display = 'block'; }
//Please wait... End

var helpPopUp;
var bResize=true;
function CallPaneHelp() 
{
	var sw = screen.width*0.24;
	var sWD="toolbar=0,status=0,menubar=0,resizable=1,left="+(screen.width-sw)+",top=0,width="+(sw-12) + ",height="+(screen.height-30);
	bResize=false;
	top.window.resizeTo(screen.width-sw,screen.height);
	top.window.moveTo(0,0);
	helpPopUp = window.open('/michiganestore/help/helpframe.aspx?pathname='+document.location.pathname,'ichat_help',sWD);
	helpPopUp.focus();
}
function SetThemeCookie(themeName)
{
    var date = new Date();
    date.setTime(date.getTime() + (365*24*60*60*1000));
    var expires = "; expires=" + date.toGMTString();
    document.cookie = "selected_theme" + "=" + themeName + expires +"; path=/";
}
function Select_DeSelectAll (chkVal, idVal)
{
    var frm = document.forms[0];
	
    //Find CheckAll element
    for (j=0; j<frm.length; j++)
    {
        if (frm.elements[j].name.indexOf('cbxSelectAll')!= -1)
            break;
    }
    
    // Look for our Header Template's Checkbox
    if (idVal.indexOf ('cbxSelectAll') != -1)
    {
        // loop through all elements
        for (i=0; i<frm.length; i++)
        {
            //Skip all other fields
            if (frm.elements[i].id.indexOf('cbxSelectRow') == -1)
                continue;
                
            // Check if main checkbox is checked, then select or deselect datagrid/gridview checkboxes 
            if(chkVal == true)
            {
                frm.elements[i].checked = true;
            }
            else
            {
                frm.elements[i].checked = false;
            }
        } 
    }
    else if (idVal.indexOf('cbxSelectRow') != -1)
    {
        // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
        if(frm.elements[idVal].checked == false)
            frm.elements[j].checked = false; 
    }
}

function ClearFieldValue(fld, defaultValue){if(fld.value==defaultValue){fld.value = "";}}
function SetFieldValue(fld, defaultValue){if(fld.value==""){fld.value = defaultValue;}}

function enterNumbersOnly(e)

{
	 var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;

	 if ( (charCode != 8) && 
              ((charCode < 48) || (charCode > 57)))
	 {
	    return (false);

	 }
}

function VerifyFieldLength(fld, fldLength)
{
    var len = 0;
    
    len = fld.value.length;
    if (len > fldLength)
    {
        fld.value=fld.value.substring(0, fldLength);
        alert("The maximum number of characters that can be entered is " + fldLength +". You have entered " + len + " characters.");
    }
}

//Calendar Scripts - START
var calPopUp; 

function OpenCalendar(idname, postBack)
{
	calPopUp = window.open('/michiganestore/calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=180,height=250,left=200,top=250');
	calPopUp.focus();
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	calPopUp.close();
	theform.elements[id].value = newDate;
}
//Calendar Scripts - END

var originalRowColor = "";
var HighlightRowColor = "#ffffc0";

function HighlightRow(row)
{
    originalRowColor = row.style.backgroundColor;
    row.style.backgroundColor =  HighlightRowColor;
}

function RestoreRowColor(row)
{
    row.style.backgroundColor =  originalRowColor;
}

var onKeyEventCtrAlert = null;
function onKeyEventCounter(field, counterField, charLimit)
{
    var len = field.value.length;
    
    if ( len > charLimit ){
        if ( onKeyEventCtrAlert!=null ) {
    	    alert(onKeyEventCtrAlert);
        } else {
    	    alert("The maximum number of characters that can be entered is" + 
    	    " " + charLimit +". You have entered" +
    	    " " + len + " " + "characters.");
        	
        }
        field.value=field.value.substring(0,field.value.length + charLimit - len);
        counterField.value = 0;
        field.focus();
    }
    else{
        counterField.value = (charLimit - len);
    }
}

function Go2Link(url)
{
    if (typeof(Going2Link) == 'function')
    {
        if (Going2Link(url))
            window.location.href = url;
        else
            return;
    }
    else
    {
        window.location.href = url;
    }
}