﻿var scrollingInfo = null;
var helpWindow = null;
var helpIFrame = null;

function setScrollingInfo()
{
    if (!scrollingInfo)
    {
        if (document.getElementById("divScrollingInfo"))
        {
            scrollingInfo = document.getElementById("divScrollingInfo");
        }
    }
	
	if (scrollingInfo)
	{
		window.onresize = setScrollingInfo;
		window.onscroll = setScrollingInfo;
		if (document.documentElement.scrollTop > 95)
		{
			scrollingInfo.style.left = (document.documentElement.clientWidth - scrollingInfo.clientWidth + document.documentElement.scrollLeft - 2) + "px";
			scrollingInfo.style.top = document.documentElement.scrollTop;
			scrollingInfo.style.display = "";
		}
		else
		{
			scrollingInfo.style.display = "none";
		}
	}			
}

function BillingIsShipping()
{
    if(aspnetForm.ctl00_ContentPlaceHolder1_cbShippingSameAsBilling.checked == true)
    {
        ctl00_ContentPlaceHolder1_divShippingAddress.style.display = 'none';
        
    }else{
    
        ctl00_ContentPlaceHolder1_divShippingAddress.style.display  = 'inline';
    }

}
function SetTestFormat(ignoreFormat)
{
    if(ignoreFormat == true)
    {
        aspnetForm.ctl00_ContentPlaceHolder1_cbTestFormatIgnore.checked = true;
        aspnetForm.ctl00_ContentPlaceHolder1_cblTestFormat_0.checked = false;
        aspnetForm.ctl00_ContentPlaceHolder1_cblTestFormat_1.checked = false;
        
    }else{
    
        aspnetForm.ctl00_ContentPlaceHolder1_cbTestFormatIgnore.checked = false;
    }
}

function initPhoneFields()
{
    try
    {
        if (document.forms.length > 0)
        {
            for (i=0;i<document.forms[0].length;i++)
            {
                if (document.forms[0][i].className)
                {
                    if (document.forms[0][i].className == "form_phone")
                    {
                        document.forms[0][i].onchange = formatPhoneNumber;
                    }
                }
            }
        }
    }   
    catch(exception)
    {
        return false;
    }
}

function defaultFocus()
{
    try
    {
        if (document.forms[0])
        {
            if (document.forms[0].length > 0)
            {
                for (x=0;x<document.forms[0].length;x++)
                {
                    if ((document.forms[0].elements[x].type == "text")||(document.forms[0].elements[x].type == "textarea"))
                    {                                    
                        document.forms[0].elements[x].focus();
                        break;
                    }                            
                }
            }
        }
    }
    catch(exception)
    {
        return false;
    }
}
            
function formatPhoneNumber()
{
    field = event.srcElement;
             
    if (isNaN(field.value))
    {
              
    }
    else
    {
        if (field.value.length == 10)
            {
	            newVal = "(" + field.value.substr(0,3) + ")" + field.value.substr(3,3) + "-" + field.value.substr(6,4);
                    field.value = newVal;
            }
    }                
}

function copyToClipboard(text)
{
    text = text.replace(/<br \/>/gi,"\r\n");
    text = text.replace(/<br>/gi,"\r\n");
    text = text.replace(/<br\/>/gi,"\r\n");
    window.clipboardData.setData("Text",text);
    window.status = "'" + text + "' was copied to the clipboard";
}

function showHelp(btn,srcText)
{
	closeHelp();
	
	if (document.getElementById(srcText))
	{
	    helpDiv = document.createElement("DIV");
	    helpDiv.id = "helpDiv";
	    helpDiv.className = "help_mainDiv";
	    helpDiv.style.top = DL_GetElementTop(btn) + "px";
	    helpDiv.style.left = DL_GetElementLeft(btn) + "px";
    	
	    headDiv = document.createElement("DIV");
	    headDiv.id = "headDiv";
	    headDiv.className = "help_headDiv"
    	
	    textDiv = document.createElement("DIV");
	    textDiv.className = "help_textDiv";
	    textDiv.innerHTML = document.getElementById(srcText).value;
    	
	    closeBtn = document.createElement("INPUT");
	    closeBtn.type = "button";
	    closeBtn.className = "help_closeBtn";
	    closeBtn.onclick = closeHelp;				
    					
	    headDiv.appendChild(closeBtn);				
	    helpDiv.appendChild(headDiv);
	    helpDiv.appendChild(textDiv);
	    document.body.appendChild(helpDiv);
	    
	    if (document.all) 
	    {
	        helpIFrame = document.createElement("IFRAME");
	        helpIFrame.style.top = DL_GetElementTop(btn) + "px";
	        helpIFrame.style.left = DL_GetElementLeft(btn) + "px";
	        helpIFrame.id = "helpIFrame";
	        helpIFrame.style.height = helpDiv.offsetHeight;
	        helpIFrame.style.width = helpDiv.offsetWidth;
	        document.body.appendChild(helpIFrame);
	    }
	    
	    helpWindow = helpDiv;
	}
	else
	{
	    alert("The Source Element for this help file cannot be found.  Expecting " + srcText);
	}
}

function closeHelp()
{
	if (helpWindow)
	{
		document.body.removeChild(helpWindow);
		if (helpIFrame) document.body.removeChild(helpIFrame);
		helpWindow = null;
		helpIFrame = null;
	}
}

function DL_GetElementLeft(eElement)
{
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nLeftPos;                             // return the number calculated
}

function DL_GetElementTop(eElement)
{
    var nTopPos = eElement.offsetTop;            // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nTopPos += eParElement.offsetTop;        // appending top offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nTopPos;                              // return the number calculated
}

