﻿    // JScript File
    //page load datetime stamp
    var pageLoadDate = new Date();
    
    function doNothing() 
    {
	    return; 
    } 
    
    function mouseover_btn(src) 
    {
	    return src.replace(/_a.gif/gi, "_b.gif"); 
    } 
    	
    function mouseout_btn(src) 
    {  
	    return src.replace(/_b.gif/gi, "_a.gif"); 
    } 
    
    function confirmDelete() 
    {
	    return window.confirm('Are you sure to delete the item?'); 
    } 

    var clicktime = 0;
    
    function ResetMultiClick()
    {
		clicktime=0;
	}

    function ValidateMultiClick()
    {
        var td = new Date();
        if ((td.getTime() - clicktime)>30000) 
        {
			clicktime=td.getTime(); 
			return true;
		} 
		else 
		{
			//alert('You already clicked button. Please be patient and wait for system to response.');
			return false;
		}
    }

    function ValidateMultiClick2(timeoutSec)
    {
        var td = new Date();
        if ((td.getTime() - clicktime)>timeoutSec*1000) 
        {
			clicktime=td.getTime(); 
			return true;
		} 
		else 
		{
			//alert('You already clicked button. Please be patient and wait for system to response.');
			return false;
		}
    }
    
    function BulkCheckboxSet(namePattern, isChecked)
    {
        var coll = document.getElementsByTagName("INPUT");
        for(var ii=0;ii<coll.length;ii++)
        {
            if (coll[ii].name.indexOf(namePattern)>=0)
                coll[ii].checked = isChecked;
        }
    }
    
	function ShowProduct(pid)
	{		
		var ascreenlength = 450;
		var ascreenheight = 300;
		ascreendefaultY = (screen.height-ascreenheight)/2 - 30;
		ascreendefaultX =	(screen.width-ascreenlength)/2 - 5;
		var wnd = null;
		if ((navigator.platform=="MacPPC") && (navigator.product != "Gecko") )
		{
			wnd = window.open("ProductPreview.aspx?pid="+pid,"popup1","width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=0,scrollbars=no,resizable=no,status=no");
			wnd.resizeTo(ascreenlength, ascreenheight);
		}
		else
			wnd = window.open("ProductPreview.aspx?pid="+pid,"popup1","width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=" + ascreendefaultY + ",scrollbars=no,resizable=no,status=no");
	}
	
	function ShowWaitScreen()
	{
		var el = document.getElementById("WaitScreen");
		if (el!=null) 
		{
		    el.style.position = "absolute";
		    el.style.left = (screen.width - 500)/2;
		    el.style.top = (screen.height - 200)/2;
		    el.style.visibility = "";
		}
	}
    
	function ShowDemo()
	{		
		var ascreenlength = 810;
		var ascreenheight = 500;
		ascreendefaultY = (screen.height-ascreenheight)/2 - 30;
		ascreendefaultX =	(screen.width-ascreenlength)/2 - 5;
		var wnd = null;
		if ((navigator.platform=="MacPPC") && (navigator.product != "Gecko") )
		{
			wnd = window.open("Main/HealthAssessment1.htm","popupDemo","width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=0,scrollbars=yes,resizable=no,status=no");
			wnd.resizeTo(ascreenlength, ascreenheight);
		}
		else
			wnd = window.open("Main/HealthAssessment1.htm","popupDemo","width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=" + ascreendefaultY + ",scrollbars=yes,resizable=no,status=no");
	}
    
	function ShowSecureScreen(h, w, url)
	{		
	    if (url.substring(0, 3)=="../")
	        url = url.substring(3);
	    else if (url.substring(0, 1)=="/")
	        url = url.substring(1);
	    url = appRootSecureUrl + url;
	    ShowScreen(h, w, url);
	}
   
	function ShowScreen(h, w, url)
	{		
		var ascreenlength = w;
		var ascreenheight = h;
		ascreendefaultY = (screen.height-ascreenheight)/2 - 30;
		ascreendefaultX =	(screen.width-ascreenlength)/2 - 5;
		var wnd = null;
		if ((navigator.platform=="MacPPC") && (navigator.product != "Gecko") )
		{
			wnd = window.open(url,"popup0","width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=0,scrollbars=yes,resizable=no,status=no");
			wnd.resizeTo(ascreenlength, ascreenheight);
		}
		else
			wnd = window.open(url,"popup0","width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=" + ascreendefaultY + ",scrollbars=yes,resizable=no,status=no");
		if (!url.indexOf(".pdf")) //pdf link creates an error - avoid it
    		wnd.focus();
	}
     
	function ShowNamedSecureScreen(h, w, url, name)
	{		
	    if (url.substring(0, 3)=="../")
	        url = url.substring(3);
	    else if (url.substring(0, 1)=="/")
	        url = url.substring(1);
	    url = appRootSecureUrl + url;
	    ShowNamedScreen(h, w, url, name);
	}
   
	function ShowNamedScreen(h, w, url, name)
	{		
		var ascreenlength = w;
		var ascreenheight = h;
		ascreendefaultY = (screen.height-ascreenheight)/2 - 30;
		ascreendefaultX =	(screen.width-ascreenlength)/2 - 5;
		var wnd = null;
		if ((navigator.platform=="MacPPC") && (navigator.product != "Gecko") )
		{
			wnd = window.open(url,name,"width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=0,scrollbars=yes,resizable=no,status=no");
			wnd.resizeTo(ascreenlength, ascreenheight);
		}
		else
			wnd = window.open(url,name,"width=" + ascreenlength + ",height=" + ascreenheight + ",screenX=" + ascreendefaultX + ",left=" + ascreendefaultX + ",screenY=" + ascreendefaultY + ",top=" + ascreendefaultY + ",scrollbars=yes,resizable=no,status=no");
		if (!url.indexOf(".pdf")) //pdf link creates an error - avoid it
    		wnd.focus();
	}
	
    function TrimString(val)
    {
        return val.replace(/^\s*|\s*$/g,"");
    }
    
    function isIE()
    {
        return window.navigator.appName.indexOf("Microsoft Internet Explorer")>=0;
    }
    
    function isEnter()
    {
        var code = (navigator.appName=='Netscape') ? oEvent.which : window.event.keyCode;
        return (code==13 || code==10) ;
    }

//client-side processing
    function GetDataFromServer(url, callback)
    {
        // code for Mozilla, etc.
        var objHttp;
        if (window.XMLHttpRequest)
           objHttp = new XMLHttpRequest();
        else if (window.ActiveXObject) // code for IE
                objHttp = new ActiveXObject('Microsoft.XMLHTTP');                

        if (objHttp == null)
            alert('Browser problem: Unable to create XMLHTTP object!');
        else 
        {
            objHttp.onreadystatechange = function()
            {
                if (objHttp.readyState == 4 || objHttp.readyState == 'complete')
                    callback (objHttp.responseText);
            }
            url = url + "&rsid=" + webRemotingSID;
            objHttp.open('GET', url, true);
            //objHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            objHttp.send('');
        }
    }

    var topPosition = 0;
    var leftPosition = 0;
    function CalculateCurrentPosition(oEvent)
    {
        topPosition = 0;
        leftPosition = 0;
        if (oEvent==null) return;
        
        //for NS
        if (oEvent.pageY || oEvent.pageX)
        {
			topPosition = oEvent.pageY;
			leftPosition = oEvent.pageX;
			return;
        }

        //calculate
        var oNode = window.event.srcElement;
        while(oNode.tagName!="BODY")
        {
            topPosition += oNode.offsetTop;
            leftPosition += oNode.offsetLeft;
            oNode = oNode.offsetParent;
        }
    }
    
///product details section - begin
    function GetProductDetails(productId)
    {
		var oEvent = window.event || arguments.callee.caller.arguments[0];
        CalculateCurrentPosition(oEvent);
        ShowLoading();
        var data = GetDataFromServer("base.ProductPreview.ashx?GetProductInfo&pid=" + productId, GetProductDetailsCallback);
    }
    
    function GetProductDetailsCallback(data)
    {									
        document.getElementById("prodView").style.left = "280px";
        if (topPosition==0) topPosition = 200;
        else if (topPosition > 200) topPosition -= 100;
        document.getElementById("prodView").style.top = topPosition + "px";
        document.getElementById("prodView").style.visibility = "visible";
        document.getElementById("prodView").style.display = "block";
        document.getElementById("prodView").innerHTML = data;
        document.getElementById("prodView").style.width = "500px";
    }    
///product details section - end
    
///product search section - begin
    function GetProductSearch(pattern)
    {
        var data = GetDataFromServer("base.ProductPreview.ashx?GetProductSearch&pattern=" + pattern + "&type=0", GetProductSearchCallback);
    }

    function GetProductSearchCallback(data)//, cn)
    {									
        document.getElementById("prodView").style.left = "280px";
        if (topPosition==0) topPosition = 200;
        else if (topPosition > 200) topPosition -= 100;
        document.getElementById("prodView").style.top = topPosition + "px";
        document.getElementById("prodView").style.visibility = "visible";
        document.getElementById("prodView").style.display = "block";
        document.getElementById("prodView").innerHTML = data;
        document.getElementById("prodView").style.width = "250px";
    }    
///product search section - end
    
    function HideProductDetails()
    {
        document.getElementById("prodView").style.visibility = "visible";
        document.getElementById("prodView").style.display = "none";
    }
    
    function ShowLoading()
    {									
        document.getElementById("prodView").style.left = "280px";
        document.getElementById("prodView").style.top = topPosition + "px";
        document.getElementById("prodView").style.visibility = "visible";
        document.getElementById("prodView").style.display = "block";
        document.getElementById("prodView").innerHTML = "<span class=textMediumLargeGray>Loading...</span>";
    }
    
    function doUpDawn(control)
    {									
		var oEvent = window.event || arguments.callee.caller.arguments[0];
		if (oEvent.offsetY <=8)
		    alert("up");
		else alert("down");
    }
    
    function setPal()
    {
        var items = document.getElementsByTagName("img");
        for(var ii=0;ii<items.length;ii++)
        {
            if (items[ii].src == "http://www.pingalink.com/free/buttons/monitoredbypingalink_07.gif")
            {
                items[ii].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(opacity=.3)";
                return;
            }
        }
    }
    
    function clearHealthConditions()
    {
        var items = document.getElementsByTagName("input");
        for(var ii=0;ii<items.length;ii++)
        {
            if (items[ii].type == "checkbox")
                items[ii].checked = false;
        }
    }

    function showVirtualPopup(data, left, width)
    {									
        document.getElementById("vPop").style.left = left + "px";
        if (topPosition==0) topPosition = 200;
        else if (topPosition > 200) topPosition -= 100;
        document.getElementById("vPop").style.top = topPosition + "px";
        document.getElementById("vPop").style.visibility = "visible";
        document.getElementById("vPop").style.display = "block";
        document.getElementById("vPop").innerHTML = data;
        document.getElementById("vPop").style.width = width + "px";
    }    
    function hideVirtualPopup()
    {
        document.getElementById("vPop").style.visibility = "visible";
        document.getElementById("vPop").style.display = "none";
    }
