﻿// JScript File
var _mapPrefix;
var _ddl;

// sets quantity textbox to 1 or empty string on display group page
function setTxtQuantity(rbl,txt)
{
   var txtQuantity = document.getElementById(txt);
         
   // if rbl is null then it must be "None" choice
   if(rbl.checked && rbl.value=="0")
   {
        txtQuantity.disabled = true;
        txtQuantity.value = "";
        return true;
   }
   else
   {
        txtQuantity.disabled = false;
        txtQuantity.value = "1";
        txtQuantity.focus();
        return true;
   }
}

function evaluateTxtQuantity(txt,origValue)
{
   var txtQuantity = document.getElementById(txt);
   var value = txtQuantity.value;
   var len = txtQuantity.value.length;
   
   for(var i=0;i<len;i++)
   {
        value = value.replace(' ','');
   }

   if(value.length==0||isNaN(value))
   {
        txtQuantity.value = origValue;
   }
   
}

function setDropDown(parentID,value)
{
    var parent = document.getElementById(parentID);
    
    findDropDown(parent);
    
    if(!_ddl) return;
    
    _ddl.selectedIndex = -1;
    for(var i=0;i<_ddl.options.length;i++)
    {
        if(_ddl.options[i].text == value)
        {
            _ddl.options[i].selected = true;
        }
    }
}

function findDropDown(n)
{
    if(n.type!=undefined)
    {
        if(n.type=="select-one")
        {
            _ddl = n;
            return;
        }
    }
    
    for(var i=0;i<n.childNodes.length;i++)
    {
        if(n.childNodes[i].childNodes.length>0)
        {
            findDropDown(n.childNodes[i]);
        }  
    }
}

function getDropDownValue(ddl)
{
    for(var i=0;i<ddl.options.length;i++)
    {
        if(ddl.options[i].selected)
            return ddl.options[i].value;
    }
}

function confirmDropDownCookieWrite(value)
{
    if(value!='All')
    {
        writeCookie(value);
    }
}   

function showHideTab(a, tab1, tab2, tab3)
{
    var t1 = document.getElementById("rootTab1");
    var t2 = document.getElementById("rootTab2");
    var t3 = document.getElementById("rootTab3");

    t1.style.display = tab1;
    t2.style.display = tab2;
    t3.style.display = tab3;
    
    writeCookie(a);
    
    //setDropDown('headersub',a);
}

function writeCookie(value)
{
    document.cookie = _mapPrefix+"="+value+";path=/;"
}

/*
checks maximum length of characters for <textArea>
*/
function checkMaxLength(textbox,l)
{
    return (textbox.value.length < l);
}

function isPoBox(sender, args)
{
     var regex = /(^(p[\s|\.|,-]*| ^post[\s|\.]*)(o[\s|\.|,]*| office[\s|\.]*))| (^box[.|\s]*\d+)/;
     
     if(regex.test(args.Value)==true)
     {
        args.IsValid = false;
     }
     else
     {
        args.IsValid = true;
     }
     
     return;
}

/*
    Email preference unsubscribe checkbox action
*/

function setCheckboxes(chkBoxIds, chkBoxId)
{
    var ids = chkBoxIds.split(",");
    var chkBox = document.getElementById(chkBoxId);
    
    for(var i=0;i<ids.length;i++)
    {
        document.getElementById(ids[i]).checked = chkBox.checked;
    }
}

/* 
    Textbox and Button event pairings 
*/

function isCorrectPairing(e, buttonID)
{
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.

    if(e.which || e.keyCode)
    {
        if ((e.which == 13) || (e.keyCode == 13))
        {
            //Get the button the user wants to have clicked

            var btn = document.getElementById(buttonID);
            if (btn != null)
            { //If we find the button click it
                
                btn.click();
            }
        }
    }
}
//	{
//		if ((e.which == 13) || (e.keyCode == 13)) 
//		{
//			document.getElementById(buttonID).click();
//			return false;
//		}
//		else
//		{
//			return true;
//		}
//	} 
//			
//    return true;
//}


function showHideDivWithLink(divId, linkId, linkShowText, linkHideText) {
	
	var div = window.document.getElementById(divId);
	var link = window.document.getElementById(linkId);
	var linkText = '';
	
	if(div.style.display == 'none') {
		div.style.display = 'block';
		linkText = linkHideText + ' (-)';			
	}
	else {
		div.style.display = 'none';
		linkText = linkShowText + ' (+)';	
	}
	
	link.innerHTML = linkText;
}

function setHiddenValue(hdnId, value)
{
    var hdn = document.getElementById(hdnId);
    
    hdn.value = value;
}