function checkPhone(phone)
{
    var phoneRegex = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{3,8}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
    if (phone.value != '') 
    {
     if(!phone.value.match(phoneRegex)) 
        {
        alert('Please enter a valid Phone number.');
        phone.value = '';
        phone.focus();
        return false;
        }
    }
    return true;
}

function checkZipCode(code)
{
    var zipRegex = /^\d{5}$/
    if (code.value != '')
    {
    if (!code.value.match(zipRegex))
        {
        alert('Please enter a valid Zipcode.');
        code.value = '';
        code.focus();
        return false;
        }
}
return true;
}


function ValidateState(source, arguments)
{
    var val = 
        document.getElementById(document.getElementById(
        source.id).controltovalidate).value;
    //Now check that is they selected other, the filled in the text 
    if (val == "0") 
       {
          arguments.IsValid = false;
       }
    else
       {
          arguments.IsValid = true;
       }
}   
        

function wordCount(count, wordLen,inputID) {
    var cntWord;                                    
    var words = count.split(/\s/);
    cntWord = words.length;
    var ele = document.getElementById(inputID);
    ele.value = cntWord;
    if (words.length > wordLen) {
        alert("Only "+wordLen+" words allowed.");
    return false;
    }
    return true;
}


//Trying to make the footer go down if the page is short

function getElementTop(Elem) {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
  		var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
  		if (yPos+236 < windowHeight)
  		{
  		    elem.style.top=(windowHeight-(yPos+236)) + "px";
  		}
        
		return yPos;
	}




//ok, lets do some home-made ajax for the email registration

function RegisterEmail()
{
    var emailBox=document.getElementById("txtEmail")    
    var xhReq = createXMLHttpRequest();
    xhReq.open("GET", "ppm_RegEmail.aspx?addy=" + emailBox.value, true);
    xhReq.onreadystatechange = function() {
        if (xhReq.readyState != 4)  { return; }
        var serverResponse = xhReq.responseText;
        if (serverResponse == "true"){
//            var div1=document.getElementById("divEmail1");
//            var div2=document.getElementById("divEmail2");
//            
//            div1.className="EmailHiddenPanel";
//            div2.className="EmailShowingPanel";  

            emailBox.value="";
            fade('blockMessage');
            setTimeout("fade('blockMessage')",3500);      
        } else {
            //ShowModal(serverResponse); 
            fade('blockInvalidError');
            setTimeout("fade('blockInvalidError')",3500);      
        }
     };
    xhReq.send(null);
}

function RegisterEmailFromPage()
{
    var emailBox=document.getElementById("txtEmailFromPage")    
    var confirmBox=document.getElementById("txtConfirmFromPage")    
    if (emailBox.value == confirmBox.value)
    {
        var xhReq = createXMLHttpRequest();
        xhReq.open("GET", "K2_RegEmail.aspx?addy=" + emailBox.value, true);
        xhReq.onreadystatechange = function() {
            if (xhReq.readyState != 4)  { return; }
            var serverResponse = xhReq.responseText;
            if (serverResponse == "true"){
                emailBox.value="";
                confirmBox.value="";
                var div=document.getElementById("divThanks")
                div.className="EmailRegThanks";                
                fade("divThanks");
            } else {
                var div=document.getElementById("divThanks")
                div.className="EmailRegError";                
                fade("divThanks");                 
                setTimeout("fade('divThanks')",3500);      
            }
         };
        xhReq.send(null);
      } else {
        alert ("The email and confirmation do not match.  Please try again.");
      }
}


function createXMLHttpRequest() {
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }
 
 
//this function send you to the search
function DoSearch()
{
    var searchText=document.getElementById("txtSearchBox");
    location="search.aspx?SearchTerm=" + searchText.value;
}




//this function is used to go to the appropriate SectionID with the right QueryString
function BSGoToStore(inStore,onSale,newItem)
{
    var daURL;
    if (inStore==true)
    {
       BSSetStoreOnly(true);
       daURL="s-2-Online-Store.aspx?ms=bsm1";
       if (onSale==true){
        daURL+='&SaleOnly=1';
       } 

    } else {
       BSSetStoreOnly(false);
       daURL="s-1-Our-Products.aspx?ms=bsm1"; 

       if(newItem==true)
       {
        daURL+='&NewOnly=1';
       }
    }
    
    location=daURL;
}

function BSLeaveStore(pageName)
{
    document.cookie="StoreOnly=1";
    BSSetStoreOnly(false);
    location=pageName;
}

//this function will set how many products to show on a grid page
function BSSetPageSize(size)
{
    //document.cookie="PageSize=" + size;
    var url;
    var qStringIdx;
    var newURL;
    
    qStringIdx=document.URL.indexOf("?");
    if (qStringIdx>0){
        qStringIdx=document.URL.indexOf("pagenum");
        if (qStringIdx>0){
            newURL=document.URL.slice(0,qStringIdx+8) + "1"; 
            if (newURL.length < document.URL.length){
                newURL=newURL + document.URL.slice(qStringIdx + 10);
            }  
            newURL=newURL + "&PageSize=" + size.toString();      
        } else {
            newURL=document.URL + "&pagenum=1&PageSize=" + size.toString();
        }
        
    } else {
        newURL=document.URL + "?pagenum=1&PageSize=" + size.toString();
    }
    location=newURL;
    //location.refresh(false);
}

//this function causes all K2 products to show in the BS site
function BSSetOverride(bOverride)
{ 
 
    if (bOverride){
        document.cookie="overrideURL=1";
    } else {
        document.cookie="overrideURL=0";
    }
   
}

function BSSetStore(chk)
{
    if(BSSetStoreOnly(chk.checked))
    {
        chk.form.submit();
    }
}

//this function causes all products to show only if in the BS store
function BSSetStoreOnly(bStoreOnly)
{ 
    var pg = location.pathname;
    
    var date = new Date();
	date.setTime(date.getTime()+(15*60*1000));
	var expires = "; expires="+date.toGMTString();
    
    if (bStoreOnly){
        document.cookie="StoreOnly=2" + expires;
        document.cookie    
        if (pg.indexOf("s-1-")>-1 || pg.indexOf("showsection")>-1)
        {
            location="s-2-Online-Store.aspx?ms=bsm1";
            return false;
        }
    } else {
        document.cookie="StoreOnly=1";        
        if (pg.indexOf("s-2-")>-1 || pg.indexOf("showsection")>-1)
        {
            location="s-1-Our-Products.aspx?ms=bsm1";
            return false;
        }
    }
   
   return true;
}

//This sets the check box that includes all K2 products
function BSSetInclude()
{
    var pInc;
    
    chk=document.getElementById("chkAll");
    pInc=readCookie("overrideURL");
    
    if (pInc==null)
    {
        pInc=0;
    }
    if (pInc==0) {
        chk.checked=false;
    } else {
        chk.checked=true;
    }
    

}

//This sets the check box that shows only store products
function BSSetStoreChk()
{
    var pInc;
    var ddl=document.getElementById("divSort");
    chk=document.getElementById("chkStore");
    pInc=readCookie("StoreOnly");
    
    if (pInc==null)
    {
        pInc=1;
    }
    if (pInc==1) {
        chk.checked=false; 
        ddl.style.display="none";
       
    } else {
        chk.checked=true;
        pInc=readCookie("priceDir");
        ddl.style.display="inline";
        
        var sel=document.getElementById("selSort");
        if (pInc==null)
        {
            pInc=0;
        }
        
        sel.selectedIndex=pInc;
        
    }
    
    
    
    
}

//This function sets a cookie for sort direction by price
function BSSetSort(frm,val)
{
    document.cookie="priceDir=" + val;
    frm.form.submit();
}
//this function swaps the product image
function SwapImage(src)
{
    img=document.getElementById("MainImageDisplayed");
    
    img.src=src;

}

function GetDivHeight(divID)
{
    var daDiv=document.getElementById(divID);
    
    alert(daDiv.clientHeight);
    
}
//this function controls the tabs on the detail page.
function ShowTab(tabName)
{
    var tab1=document.getElementById("tab1");
    var tab2=document.getElementById("tab2");
    var tab3=document.getElementById("tab3");
    var div1=document.getElementById("div1");
    var div2=document.getElementById("div2");
    var div3=document.getElementById("div3");

    if (tabName=='tab1')
    {
        if (tab1!=null){tab1.className="FrontTab";}        
        if (tab2!=null){tab2.className="BackTab";}
        if (tab3!=null){tab3.className="BackTab";}
        if (div1!=null){div1.className="FrontDiv";}        
        if (div2!=null){div2.className="BackDiv";}
        if (div3!=null){div3.className="BackDiv";}
    } else if (tabName=='tab2')
    {
        if (tab1!=null){tab1.className="BackTab";}        
        if (tab2!=null){tab2.className="FrontTab";}
        if (tab3!=null){tab3.className="BackTab";}
        if (div1!=null){div1.className="BackDiv";}        
        if (div2!=null){div2.className="FrontDiv";}
        if (div3!=null){div3.className="BackDiv";}
    
    } else if (tabName=='tab3')
    {
        if (tab1!=null){tab1.className="BackTab";}        
        if (tab2!=null){tab2.className="BackTab";}
        if (tab3!=null){tab3.className="FrontTab";}
        if (div1!=null){div1.className="BackDiv";}        
        if (div2!=null){div2.className="BackDiv";}
        if (div3!=null){div3.className="FrontDiv";}
    
    }

}

var ScrollerStep;
var divStartLeft;
var intID=0;
var AWBIdx=1;
var scrolling=false;

function MoveABWLeft(){
    if (intID!=0)
    {
        return
    }
    div=document.getElementById("DetailsAlsoBoughtScroller");
    AWBIdx+=1;
    if (div!=null){
        
        divStartLeft=parseInt(div.style.left);
        
        var curWidth=parseInt(div.style.width);
//        if (divStartLeft-390<(curWidth * -1))
//        {
//            ScrollerStep=0;
//            intID= setInterval("ScrollerAnimate(1,Math.abs(divStartLeft),50)",10);
//        } else {
//            ScrollerStep=0;            
//          intID= setInterval("ScrollerAnimate(-1,390,50)",10);    
//        }
        if (AWBIdx<=3){
            if (intID==0){
                ScrollerStep=0;            

                intID= setInterval("ScrollerAnimate(-1,390,50)",10); 
            }
        } 
        if(AWBIdx>=3) {
            img=document.getElementById("imgNextProd");
            img.src="skins/skin_2/images/DetailImages/NextProdOff.jpg";            
            AWBIdx=3;
        } 
        
    }
    img=document.getElementById("imgPrevProd");
    img.src="skins/skin_2/images/DetailImages/PrevProd.jpg";


}

function ScrollerAnimate(dir,distance,end)
{
    if (ScrollerStep == end)
    {
        clearInterval(intID);
        intID=0;        
        //step=1000;
    }
    var x = Easing.quartic.ease_both(ScrollerStep, 0, distance, end);
    
    x=(x*dir)+divStartLeft;
    
    div=document.getElementById("DetailsAlsoBoughtScroller");
    div.style.left=x + "px";    
    ScrollerStep +=1;

}

function MoveABWRight(){
    if (intID!=0)
    {
        return
    }
    div=document.getElementById("DetailsAlsoBoughtScroller");
    AWBIdx-=1;
    if (div!=null){
        divStartLeft=parseInt(div.style.left);
        
        var curWidth=parseInt(div.style.width);
//        if (divStartLeft+390>0)
//        {
//            ScrollerStep=0;
//            intID= setInterval("ScrollerAnimate(-1,curWidth-390,50)",10);
//        } else {
//            ScrollerStep=0;            
//            intID= setInterval("ScrollerAnimate(1,390,50)",10);   
//        }
        if (AWBIdx>=1){           
            ScrollerStep=0;
            intID= setInterval("ScrollerAnimate(1,390,50)",10); 

        } 
        if(AWBIdx<=1) {
            img=document.getElementById("imgPrevProd");
            img.src="skins/skin_2/images/DetailImages/PrevProdOff.jpg";            
            AWBIdx=1;
        }         
        
    }
    img=document.getElementById("imgNextProd");
    img.src="skins/skin_2/images/DetailImages/NextProd.jpg";


}



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


//This is code for the AddThis box
$(function(){    $('.custom_button, .hover_menu').mouseenter(function()    {        $('.hover_menu').fadeIn('fast');        $('.custom_button').addClass('active');        $(this).data('in', true);        $('.hover_menu').data('hidden', false);    }).mouseleave(function()    {        $(this).data('in', false);        setTimeout(hideMenu, delay);    });    var delay = 400;    function hideMenu()    {        if (!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden'))        {            $('.hover_menu').fadeOut('fast');            $('.custom_button').removeClass('active');            $('.hover_menu').data('hidden', true);        }    }});



//This function opens and closes the groups on the Awards page
    function toggleAward(year)
    {
        var img;
        var src ; 
        img=document.getElementById('img'+year);
        src=img.src;
        //img.src="images/expand_down_btn.jpg";
        if (src.toLowerCase().indexOf("expand")>-1)
        {
            img.src="images/collapse_up_btn.jpg";
            toggleAwardSpans(year,true);
        } else {
            img.src="images/expand_down_btn.jpg";        
            toggleAwardSpans(year,false);
        }
        
    }

       
//This function will hide or show the different years
    function toggleAwardSpans(year,show)
    {
        var spanCollection = document.getElementsByTagName("span");
        
        for (var i=0; i<spanCollection.length; i++) {
            //alert(spanCollection[i].id);
            if(spanCollection[i].id.indexOf(year)>-1) {
              
                if (show){
                    spanCollection[i].style.display="block";   
                    //spanCollection[i].setAttribute("style","display:block"); 
                } else {
                    spanCollection[i].style.display="none";                 
                    //spanCollection[i].setAttribute("style","display:none"); 
                }
            } 
        }

    } 
//This function submits the results of the How Did you Hear about Us poll
    function submitChoice(str)
    {

    var xmlHttp=null;

    try
      {// Firefox, Opera 8.0+, Safari, IE7
      xmlHttp=new XMLHttpRequest();
      }
    catch(e)
      {// Old IE
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch(e)
        {
        alert ("Your browser does not support XMLHTTP!");
        return;  
        }
      }
    var url="K2_PollWorker.aspx?pollResult=" + str; 
    url=url+"&sid="+Math.random();
    xmlHttp.open("GET",url,false);
    xmlHttp.send(null);
    document.getElementById("txtResponse").innerHTML=xmlHttp.responseText;
    document.getElementById("radioButtons").style.display="none";
    }





		//Deals with Primary Navigation Links	

			
			function PrimaryLinkOn(id)
			{
				if (id != '0a')
				{
					document.getElementById(id).className='MainTextOn';
				}
			}
			
			function PrimaryLinkOff(id)
			{
				document.getElementById(id).className='MainTextOff';
			}
			
			
			//Deals with Secondary Navigation Image Roll-overs		
			
			function ShowCircle(id)
			{
				if (id != '0xcir')
				{
					document.getElementById(id).src = 'images/circle1.jpg'
				}
			}
			
			function HideCircle(id)
			{
				document.getElementById(id).src = 'images/spacer.gif';
			}
			
			
			//Deals with Secondary Navigation Links			
			
			function SwitchSecondary(id)
			{	
				if (id != 'Sub0')
				{
					HideAllSecondary();
					ShowSelectedSecondary(id);
				}
				else
				{
					HideAllSecondary();				
				}
			}

			function HideAllSecondary()
			{
			//loop through the array and hide each element by id
				for (var i=0;i<SecondaryIDs.length;i++)
				{
					HideSelectedSecondary(SecondaryIDs[i]);
				}		  
			}

			function HideSelectedSecondary(id) 
			{
			//safe function to hide an element with a specified id
			    
				if (document.getElementById) 
				{ 
					// DOM3 = IE5, NS6
					document.getElementById(id).style.display = 'none';
				}
				else 
				{
					if (document.layers) 
					{ 
						// Netscape 4
						document.id.display = 'none';
					}
					else 
					{ 
						// IE 4
						document.all.id.style.display = 'none';
					}
				}
			}

			function ShowSelectedSecondary(id) 
			{
			//safe function to show an element with a specified id
		        
				if (document.getElementById) 
				{ 
					// DOM3 = IE5, NS6
					document.getElementById(id).style.display = 'block';
				}
				else 
				{
					if (document.layers) 
					{ 
						// Netscape 4
						document.id.display = 'block';
					}
					else 
					{ 
						// IE 4
						document.all.id.style.display = 'block';
					}
				}
			}
			
			function ChangeHeightValue (id, sid)			
			{
				if (sid == "4")
				{
					document.getElementById(id).style.height = document.getElementById("MainAdRegion").offsetHeight - 140;
				}
			
			}

var tags = new Array( 'table','tr','td','p','font','span','label','a','ul','li' );
var sizes = new Array( '10','11','12','13','14','15','16' );
var startSize = 1;

function ChangeTextSizes( target,inc ) {
	if (!document.getElementById) return
	var doc = document,Adam1 = null,size = startSize,i,j,xTags;
	
	size += inc;
	if ( size < 0 ) size = 0;
	if ( size > 6 ) size = 2;
	startSize = size;
	if ( !( Adam1 = doc.getElementById( target ) ) ) Adam1 = doc.getElementsByTagName( target )[ 0 ];

	Adam1.style.fontSize = sizes[ size ] + 'px';

	for ( i = 0 ; i < tags.length ; i++ ) {
		xTags = Adam1.getElementsByTagName( tags[ i ] );
		for ( j = 0 ; j < xTags.length ; j++ ) xTags[ j ].style.fontSize = sizes[ size ] + 'px';
	}
}

var flipDelay = 9000; 
var flipLinkDelay = 8250; 
var flipMainAdLinkDelay = 3000; 
var flipCurrent_i; 
var flipTimer; 
var flipImages;
var flipLinks; 
var flipMainAdLinks; 
var flipMainAdTimer; 
var flipCurrent_j; 
 
function flipPRLinkInit(id) 
{   
	var container = returnObjById(id);	
	flipLinks = container.getElementsByTagName("a");    
	if(typeof(flipCurrent_i)=="undefined")   
	{     
	
		for(var i=0;i<flipLinks.length;i++)
		{       
			if(flipLinks[i].style.visibility)
			{         
				flipCurrent_i = i;         
				break;       
			}     
		}     
	}    
	 
	flipTimer = setInterval("flipLinkFlop()",flipLinkDelay); 
} 
function flipMainAdLinkInit(id) 
{   
	var container = returnObjById(id);	
	flipMainAdLinks = container.getElementsByTagName("a");    
	if(typeof(flipCurrent_j)=="undefined")   
	{     
	
		for(var i=0;i<flipMainAdLinks.length;i++)
		{       
			if(flipMainAdLinks[i].style.visibility)
			{         
				flipCurrent_j = i;         
				break;       
			}     
		}     
	}    
	 
	flipMainAdTimer = setInterval("flipMainAdLinkFlop()",flipMainAdLinkDelay); 
} 
function flipInit() 
{   
	var container = returnObjById("flipcontainer");   
	flipImages = container.getElementsByTagName("img");	   
	if(typeof(flipCurrent_i)=="undefined")   
	{     
		for(var i=0;i<flipImages.length;i++)
		{       
			if(flipImages[i].style.visibility)
			{         
				flipCurrent_i = i;         
				break;       
			}     
		} 		
	}     
	flipTimer = setInterval("flipFlop()",flipDelay);	 
} 
function flipFlop() 
{   
	flipImages[flipCurrent_i].style.visibility = ""   
	flipCurrent_i = ++flipCurrent_i % flipImages.length   
	flipImages[flipCurrent_i].style.visibility = "visible" 
}
function flipLinkFlop() 
{   
	flipLinks[flipCurrent_i].style.visibility = ""   
	flipCurrent_i = ++flipCurrent_i % flipLinks.length   
	flipLinks[flipCurrent_i].style.visibility = "visible" 
}
function flipMainAdLinkFlop() 
{   
	flipMainAdLinks[flipCurrent_j].style.visibility = ""   
	flipCurrent_j = ++flipCurrent_j % flipMainAdLinks.length   
	flipMainAdLinks[flipCurrent_j].style.visibility = "visible" 
}

function returnObjById( id ) 
{ 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
} 

	function TableHeight() 
	{ 
		
		var myWidth;
		var myHeight;
		var hiY;
		if( typeof( window.innerWidth ) == 'number' ) 
		{ 
			//Non-IE 
			myWidth = window.innerWidth; 
			myHeight = window.innerHeight; 
		} 
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{ 
			//IE 6+ in 'standards compliant mode' 
			myWidth = document.documentElement.clientWidth; 
			myHeight = document.documentElement.clientHeight; 
		} 
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		{ 
			//IE 4 compatible 
			myWidth = document.body.clientWidth; 
			myHeight = document.body.clientHeight; 
		} 
			//hiY = document.write(myHeight - 140); 
			hiY = myHeight - 400; 
			return hiY;

	} 
function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; 
if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for 
(i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function setTextOfTextfield(objName,x,newText)
{ 
  //v3.0
  var obj = findObj(objName); 
  if (obj) 
    {
    obj.value = newText;
    obj.focus();
    }
  
}
function NSFix()
{
var agt= navigator.userAgent.toLowerCase();
if((!!(agt.indexOf('gecko')!= -1)) & !agt.match("firefox") & !agt.match("seamonkey")) //Is it a Netscape/Mozilla Browser, Not Firefox or SeaMonkey?
{
wHeight=window.outerHeight != undefined ? window.outerHeight : document.body.offsetHeight;
wWidth=window.outerWidth != undefined ? window.outerWidth : document.body.offsetWidth;
sHeight=screen.availHeight
sWidth=screen.availWidth
if((wHeight >= sHeight) & (wWidth >= sWidth)) //Maximized
{
window.resizeTo(sWidth-1,sHeight-1)
window.moveTo(0,0)
}
else {
 
window.resizeBy(-1,0);
window.resizeBy(1,0);
}
}
}
	 function SetSectionVisible(id_root, visible, list_section) {
     on_data = document.getElementById(id_root + "data");
     on_controls = document.getElementById(id_root + "show");
     off_controls = document.getElementById(id_root + "hide");
     if (list_section == 0) {
       off_elipses = document.getElementById(id_root + "e0");
       display_style = "inline";
     } else {
       off_elipses = null;
       display_style = "block";
     }
     if (visible == 0) {
       on_data.style.display = "none";
       //on_controls.style.display = "none";
       off_controls.style.display = display_style;
       if (off_elipses != null) {
         off_elipses.style.display = "inline";
       }
     } else {
       on_data.style.display = display_style;
       on_controls.style.display = display_style;
       off_controls.style.display = "none";
       if (off_elipses != null) {
         off_elipses.style.display = "none";
       }
     }
  }
  function SetListSectionVisible(id_root, visible) {
    SetSectionVisible(id_root, visible, 1);
  }
  function SetTextSectionVisible(id_root, visible) {
    SetSectionVisible(id_root, visible, 0);
  }
//<script language="javascript">document.write( "<td height=\"" + TableHeight() + "\" valign=\"bottom\" align=\"left\">" );</script>


function ChangeMainImage(ImageName)
			{
				document.getElementById('MainImageDisplayed').src = ImageName;
			}
			
			 function DisableButton(e) {
                document.forms[0].submit();
    var buttonID;
    var targ;
    if (!e) var e = window.event; // IE, because it can't follow convention and send the event as an argument.
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) targ = targ.parentNode // defeat Safari bug
    buttonID=targ.id    
                window.setTimeout("disableButton('" + buttonID + "')", 0);
    }


            function disableButton(buttonID) {
                document.getElementById(buttonID).disabled=true;
            }
function errorHandler(msg, url, linenumber)
  {
  if(msg.indexOf("this.blur") != -1) return true
  else return false
  }
function max() { 
window.moveTo(1,1); //Needed because Netscape 7.1 can't handle the last pixel :P 
window.moveTo(0,0); 
window.resizeTo(screen.width,screen.height); 
} 

		function transferAll()
		{ 
		transfer("PL_140_FirstName","PL_140_sFirstName")
		transfer("PL_140_LastName","PL_140_sLastName")
		transfer("PL_140_Phone","PL_140_sPhone")
		transfer("PL_140_Address1","PL_140_sAddress1")
		transfer("PL_140_Address2","PL_140_sAddress2")
		transfer("PL_140_City","PL_140_sCity")
		transfer("PL_140_ZipCode","PL_140_sZipCode")
		transferBox("PL_140_State","PL_140_sState")
		transferBox("PL_140_Country","PL_140_sCountry")
		transferBox('PL_140_Title','PL_140_sTitle')

		}
		
		function transfer(source, dest)
		{
		document.getElementById(dest).value=document.getElementById(source).value
		}
		
		function transferBox(source, dest)
		{

		var i;
		var s=document.getElementById(source);
		var d=document.getElementById(dest);
		
		for (i=0;i < d.length;i++)
		{
			if(d.options[i].text==s.options[s.selectedIndex].text)
			{
			d.selectedIndex = i
			return
			}
		}
		d.selectedIndex = 0
		return

		}
		
		function cancelBox()
		{
		document.getElementById("PL_140_chkSameAsBilling").checked = false
		}
		function emptyAll()
		{
		document.getElementById("PL_140_sFirstName").value=""
		document.getElementById("PL_140_sLastName").value=""
		document.getElementById("PL_140_sPhone").value=""
		document.getElementById("PL_140_sAddress1").value=""
		document.getElementById("PL_140_sAddress2").value=""
		document.getElementById("PL_140_sCity").value=""
		document.getElementById("PL_140_sZipCode").value=""
		document.getElementById("PL_140_sTitle").value=""
		document.getElementById("PL_140_sState").selectedIndex=0
		document.getElementById("PL_140_sCountry").selectedIndex=0
		}
		
function writePWBox() {
	document.getElementById("passbox").innerHTML="<input type=password class=\"SearchField\" id=\"Header1_Nav1_SmallPassword\" tabindex=\"100\" onmousedown=\"setTextOfTextfield('Header1_Nav1_SmallPassword','','')\" onkeydown=\"if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('Header1_Nav1_LoginBtn').click();return false;}} else {document.getElementById('Header1_Nav1_hfielda').value=this.value; return true};\" onkeyup=\"document.getElementById('Header1_Nav1_hfielda').value=this.value;\">";
    //document.getElementById("passbox").innerHTML="<input type=password class=\"SearchField\" id=\"Header1_Nav1_SmallPassword\" tabindex=\"100\" onchange=\"document.getElementById('Header1_Nav1_hfielda').value=this.value;\" onmousedown=\"setTextOfTextfield('Header1_Nav1_SmallPassword','','')\" onkeydown=\"if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('Header1_Nav1_LoginBtn').click();return false;}} else {return true};\">";
    //alert(document.getElementById("password").value)
    setTimeout("document.getElementById('Header1_Nav1_SmallPassword').focus()",75);
    
    }
    
//=======================================

//set on focus and on blur textbox bg colors

ColorFocus = '#FDF3CE'//'#D3DAED'

ColorBlur = '#ffffff'

//=======================================

//-->

// Written and Tested by David Leuszler

function TBC(obj,state)
{

if (state == '1')
	obj.style.backgroundColor=ColorFocus;
else
	obj.style.backgroundColor=ColorBlur;
}




function expandPanel(panel, plus)
{
this.panel=panel;
this.plus=plus
this.status=true
this.switchMenu=switchMenu
this.setExpand=setExpand
}


function switchMenu() {
this.status=!this.status
this.setExpand(this.status)
}

function setExpand(newStatus) {
	//alert(this.obj.toString())
	var el = document.getElementById(this.panel.toString());
	var plus = document.getElementById(this.plus.toString());
	//alert(this.plus.toString())
	if ( newStatus == false ) {
		this.status = false
		el.style.display = 'none';
		plus.innerHTML = '+'
		genStatusString()
	}
	else {
		this.status = true
		el.style.display = '';
		plus.innerHTML = '-'
		genStatusString()
	}
}


function findPos(obj) {
	var el = document.getElementById(obj);
	var curtop = 0;
	if (el.offsetParent) {
		curtop = el.offsetTop
		while (el = el.offsetParent) {
			curtop += el.offsetTop
		}
	}
	//alert(curtop);
	return curtop;
}

function cascadeErrorFind(old, current) {
	if(old == -1) {
		var el = document.getElementById(current)
		if(!el.isvalid) {
		return findPos(current)
		}
	}
	return old
}



/* This is for my Ajax Stuff!!! */


function gimmeAJAX()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    
    }
  }

return xmlHttp;
}

function runAJAXRequest(url,paramstring)
{
var xmlHttp
xmlHttp = gimmeAJAX()
if(xmlHttp == null) { return false }

xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.getElementById("response").innerHTML=xmlHttp.responseText;        
        }
      }
    var request = url+"?"+paramstring
    xmlHttp.open("GET",request,true);
    xmlHttp.send(null);
    return true
}



function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}

function changeDiv(idold, idnew)
{
toggleDiv(idnew,1)
toggleDiv(idold,0)
}

function openSequence()
{
inTransition = true
setTimeout("changeDiv('Anim1','Anim2')",100)
setTimeout("changeDiv('Anim2','Anim3')",150)
setTimeout("changeDiv('Anim3','contentDiv')",200)
setTimeout("inTransition = false",201)
boxOpen = true
//document.getElementById("testing").innerHTML="I think the box is open"
}

function closeSequence()
{
inTransition = true
setTimeout("changeDiv('contentDiv','Anim3')",100)
setTimeout("changeDiv('Anim3','Anim2')",150)
setTimeout("changeDiv('Anim2','Anim1')",200)
setTimeout("toggleDiv('Anim1',0)",225)
setTimeout("inTransition = false",226)
boxOpen = false
//document.getElementById("testing").innerHTML="I think the box is closed"
}

var onImg = false
var onBox = false
var boxOpen = false
var inTransition = false

function moveOnImg()
{
onImg = true
confirmOpen()
//if(!(onImg | onBox)) openSequence()

//document.getElementById("testing").innerHTML="Moved on Image"
//document.getElementById("image").innerHTML="onImg TRUE"
}

function moveOnBox()
{
onBox = true
confirmOpen()

//if(!(onImg | onBox)) openSequence()
//onBox = true

//document.getElementById("testing").innerHTML="Moved on Box"
//document.getElementById("box").innerHTML="onBox TRUE"
}

function moveOffImg()
{
onImg = false
setTimeout("confirmClose()",500)
//onImg = false
//if(!(onImg | onBox)) closeSequence()
//document.getElementById("testing").innerHTML="Moved off Image"
//document.getElementById("image").innerHTML="onImg False"
}

function moveOffBox()
{
onBox = false
setTimeout("confirmClose()",500)
//onBox = false
//if(!(onImg | onBox)) closeSequence()
//document.getElementById("testing").innerHTML="Moved off Box"
//document.getElementById("box").innerHTML="onBox False"
}

function confirmOpen()
{
if(!(onImg & onBox) & !inTransition & !boxOpen) openSequence()
}

function confirmClose()
{
if(!(onImg | onBox) & !inTransition & boxOpen) closeSequence()
}

 /* End my Ajax Stuff!!!! */

/*///////////////////////////////////////////////////
05.12.2009:SH (yes Gary, it's a little borrowed...)
This is *hopefully* collaspsing the FAQs into a more readable <ul> list(s)) 
*/

/*
* The Variable names have been compressed to achive a higher level of compression.
*/

// Prototype Method to get the element based on ID
function $(d){
	return document.getElementById(d);
}

// set or get the current display style of the div
function dsp(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
}

// set or get the height of a div.
function sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		if(dsp(d)!='none'&& dsp(d)!=''){
			return d.offsetHeight;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = dsp(d);
		dsp(d,'block');
		r = parseInt(d.offsetHeight);
		dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height=v;
	}
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=7;
t=10;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	d = $(d);
	if(sh(d)>0){
		v = Math.round(sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)-v);
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,0);
		dsp(d,'none');
		clearInterval(d.t);
	}
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et(d){
	d = $(d);
	if(sh(d)<d.maxh){
		v = Math.round((d.maxh-sh(d))/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)+v);
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,d.maxh);
		clearInterval(d.t);
	}
}

// Collapse Initializer
function cl(d){
	if(dsp(d)=='block'){
		clearInterval(d.t);
		d.t=setInterval('ct("'+d.id+'")',t);
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none'){
		dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('et("'+d.id+'")',t);
	}
}

// Removes Classname from the given div.
function cc(n,v){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc){
			s.splice(p,1);
			n.className=s.join(' ');
			break;
		}
	}
}
//Accordian Initializer
function Accordian(d,s,tc){
	// get all the elements that have id as content
	l=$(d).getElementsByTagName('div');
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
	}
	sel=null;
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
			d=$(h.substr(0,h.indexOf('-'))+'-content');
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
			h=$(h);
			h.tc=tc;
			h.c=c;
			// set the onclick function for each header.
			h.onclick = function(){
				for(i=0;i<this.c.length;i++){
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					if((n+'-header')==this.id){
						ex($(n+'-content'));
						n=$(n+'-header');
						cc(n,'__');
						n.className=n.className+' '+n.tc;
					}else{
						cl($(n+'-content'));
						cc($(n+'-header'),'');
					}
				}
			}
			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}

//Gets date code popup
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=690,left = 368,top = 187.5');");
}

//pops up windows in the Print Template
function popUpInTemplate(URL,width,height) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+width + ',height=' + height + ',left = 368,top = 187.5');");
}


//parse the querystring
window.location.querystring = (function() {
 
    // by Chris O'Brien, prettycode.org
 
    var collection = {};
 
    // Gets the query string, starts with '?'
 
    var querystring = window.location.search;
 
    // Empty if no query string
 
    if (!querystring) {
        return { toString: function() { return ""; } };
    }
 
    // Decode query string and remove '?'
 
    querystring = decodeURI(querystring.substring(1));
 
   // Load the key/values of the return collection
 
    var pairs = querystring.split("&");
 
    for (var i = 0; i < pairs.length; i++) {
 
        // Empty pair (e.g. ?key=val&&key2=val2)
 
        if (!pairs[i]) {
            continue;
        }
 
        // Don't use split("=") in case value has "=" in it
 
        var seperatorPosition = pairs[i].indexOf("=");
 
        if (seperatorPosition == -1) {
            collection[pairs[i]] = "";
        }
        else {
            collection[pairs[i].substring(0, seperatorPosition)] 
                = pairs[i].substr(seperatorPosition + 1);
        }
    }
 
    // toString() returns the key/value pairs concatenated
 
    collection.toString = function() {
        return "?" + querystring;
    };
 
    return collection;
})();

//used by the print template to decide whether to automatically pop up the print dialog
        function PrintOrNoPrint()
        {
            var querystring=window.location.querystring;
            var qKey;
            for (var key in querystring){
                qKey=key.toString();
                if (qKey.toLowerCase()=="printme"){
                    if (querystring[key]==1) {
                        window.print()
                    }                 
                }
            }
        }
        
     //These functions are for greyscaling the awards images   

     function MakeGreyScale(imageID){
            var imgObj = document.getElementById(imageID);
            
            if($.browser.msie){
                grayscaleImageIE(imgObj);
            } else {
                imgObj.src = grayscaleImage(imgObj);
            }           
        }
    function grayscaleImageIE(imgObj)
    {
        imgObj.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayScale=1)';
    }
 
    function grayscaleImage(imgObj)
    {
        var canvas = document.createElement('canvas');
        var canvasContext = canvas.getContext('2d');
        
        var imgW = imgObj.width;
        var imgH = imgObj.height;
        canvas.width = imgW;
        canvas.height = imgH;
        
        canvasContext.drawImage(imgObj, 0, 0);
        var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH);
        
        for(var y = 0; y < imgPixels.height; y++){
            for(var x = 0; x < imgPixels.width; x++){
                var i = (y * 4) * imgPixels.width + x * 4;
                var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
                imgPixels.data[i] = avg; 
                imgPixels.data[i + 1] = avg; 
                imgPixels.data[i + 2] = avg;
            }
        }
        
        canvasContext.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
        return canvas.toDataURL();
    }        
        

//*********************** Some Fade Stuff  ******************//
var TimeToFade = 500.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
  //if (element.style.display == 'none') element.style.display='block';
  if(element.FadeState == null)
  {
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    element.style.display = element.FadeState == 2 ? 'none' : 'block';
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.display = element.FadeState == 1 ? 'block' : 'none';
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
  
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

//************** END FADE STUFF ****************/


function openRules() {
    var open1 =
    window.open('rulesandregulations.aspx','','scrollbars=no,height=650,width=720,resizable=no');
}
function openEmailaFriend() {
    var open2 =
    window.open('emailfriend.aspx','','scrollbars=no,height=730,width=850,resizable=no');
}
