
try{
if (self != top)
{
   if (document.images)
      top.location.replace(window.location.href);
   else
      top.location.href = window.location.href;
}
}catch(er){}

//Declare variables to store initial layout widths here so they can be reset back to these values
var initMainArea = ""; 
var initLeftAndMain = "";
var initMain = ""; 
var initPgBotR = "";
var fontCtr = 0;	
var min=8; //font minimum size
var max=18;	//font maximum size

window.onload = init;
//window.onUnload = finishUp;



function init(){
	//function to initialize everything for on page load 
	
	//set variables to store initial layout widths here so they can be reset back to these values
	initMainArea = document.getElementById('mainArea').style.width; 
	initLeftAndMain = document.getElementById('leftAndMain').style.width;
	initMain = document.getElementById('main').style.width; 
	initPgBotR = document.getElementById('pgBotR').style.width;

	//document.getElementById('topLinks').style.fontSize = "13px";
	
	if(getCookie("screenView")=="wide") //if display was changed to a wide layout
		switchView();
	if(getCookie("fontCtr")!="") //if font size was changed
		fontCtr = parseInt(getCookie("fontCtr"));
	if(parseInt(getCookie("fontCtr"))==0){
		//do nothing
	}else{
		if(fontCtr>0){					
			for(var i=0;i<fontCtr;i++){ 
				increaseFontSize(false);
			}						
		}else{ //fontCtr < 0 so use decreaseFontSize function
			for(var i=0;i>fontCtr;i--) 
				decreaseFontSize(false);
		}
	}
	/*	
	if(fontCtr>3){
		document.body.style.lineHeight="100%";
	}else{ 
		document.body.style.lineHeight="130%";
	}
	*/						
}

function restoreDefaults(){
	//restores the page to it's original width and font size
	
	//Note: to use a larger font on the page use <strong> tag or may need to store indexes of the larger font. Would probably have to put style="font-size:13px;" on the tag as well because it will not be detected from the .css file
	//font percentage doesn't work and font-size:larger is too big but may be able to alter code for it. The above note is more ideal
	
	var tempFontCtr = fontCtr;	
	if (parseInt(document.getElementById('mainArea').style.width) != 925)
		switchView();		
	if(fontCtr!=0){ 				
		if(fontCtr>0){					
			for(var i=0;i<tempFontCtr;i++) 
				decreaseFontSize(true);																
		}else{ //fontCtr < 0 so use decreaseFontSize function
			for(var i=0;i<Math.abs(tempFontCtr);i++) 
				increaseFontSize(true);					
		}		
	}	
	//document.getElementById('topLinks').style.fontSize = "13px";
	switchOptionDisp();
	setFormFields();
}
	
function switchView(){	
	//this function handles change the display area from narrow or wide view
	if (parseInt(document.getElementById('mainArea').style.width) == 925){ //currently narrow view so switch to a wide view
		if (parseInt(screen.width) > 800){ //ensure display is above 800*600 screen resolution
			document.getElementById('mainArea').style.width = eval(parseInt(screen.width) -70)  + "px";
			document.getElementById('leftAndMain').style.width = eval(parseInt(document.getElementById('mainArea').style.width)-180) + "px";
			document.getElementById('main').style.width = eval(parseInt(document.getElementById('leftAndMain').style.width)-186) + "px";
			document.getElementById('pgBotR').style.width = eval(parseInt(document.getElementById('mainArea').style.width)-11) + "px";
			if(document.getElementById("widthView") != null) //if widthView has been written to the document
				document.getElementById('widthView').innerHTML = "Switch to narrow view";			
			setCookie("screenView","wide",90,"/");	
		}
	}else{ //narrow view (default)
		//reset screen layout back to there initial values
		document.getElementById('mainArea').style.width=initMainArea;
		document.getElementById('leftAndMain').style.width=initLeftAndMain;
		document.getElementById('main').style.width=initMain; 
		document.getElementById('pgBotR').style.width=initPgBotR;	
		if(document.getElementById("widthView") != null) //if widthView has been written to the document
			document.getElementById('widthView').innerHTML = "Switch to wide view";		
		setCookie("screenView","narrow",90,"/");			
	}	
	setFormFields();					
}

function increaseFontSize(changeFontCtr) {		
	changeTagFontSize(true,"div")
	//changeTagFontSize(true,"span")
	//handle a tags with a class specified
	
	var a = document.getElementsByTagName('a');
	
   	for(i=0;i<a.length;i++) {		   
   		if (a[i].className !=""){	 //also needs to be done for decreaseFontSize function  		
	      	if(a[i].style.fontSize) {
	         	var s = parseInt(a[i].style.fontSize.replace("px",""));					
	      	} else {	
				var s = 11;				
	      	}
	      	if(s!=max) {
	         	s += 1;
	      	}
			a[i].style.fontSize = s+"px"			 
		 }
	}
	
	if (changeFontCtr==true){
		if(fontCtr<7){
			fontCtr++; 
			setCookie("fontCtr",fontCtr,90,"/");
		}
	}
	dispOrHideFontChange()//decide whether to show or hide the link to increase or decrease the font size				
}		
function decreaseFontSize(changeFontCtr) {
	changeTagFontSize(false,"div")
	//changeTagFontSize(false,"span")
	//handle a tags with a class specified 
	
	var a = document.getElementsByTagName('a');   	
	for(i=0;i<a.length;i++) {
		if (a[i].className !=""){	 //also needs to be done for increaseFontSize function  
	      	if(a[i].style.fontSize) {
	         	var s = parseInt(a[i].style.fontSize.replace("px",""));
	      	} else {
				var s = 11;
	      	}
	      	if(s!=min) {
	         	s -= 1;
	      	}
			a[i].style.fontSize = s+"px"
		}
   	}
		
	if (changeFontCtr==true){
		if(fontCtr>-3){
			fontCtr--;		
			setCookie("fontCtr",fontCtr,90,"/");						
		}					
	}	
	dispOrHideFontChange()//decide whether to show or hide the link to increase or decrease the font size		 
}
function changeTagFontSize(addInstead,theTag){
	//changes the font size of the html tag passed.  addInstead is a boolean to decide whether to increase or decrease the font size  
	var p = document.getElementsByTagName(theTag);
   	for(i=0;i<p.length;i++) {		   
   		if (p[i].id !="logo"){	 //don't change size of logo font(big pinscentral.com wording) 		
	      	if(p[i].style.fontSize) {
	         	var s = parseInt(p[i].style.fontSize.replace("px",""));
	      	} else {
	         	var s = 11;
	      	}
			if (addInstead == true){ //if making larger instead of smaller
		      	if(s!=max) 
		         	s += 1;
		    }else{  //making smaller
	      		if(s!=min) 
	         		s -= 1;
			}					
	      	p[i].style.fontSize = s+"px"				 
		 }
	} 
	/*
	if(fontCtr>3){
		document.body.style.lineHeight="100%";
	}else{ 
		document.body.style.lineHeight="130%";
	}	
	*/		
}

function dispOrHideFontChange(){
	//decide whether to show or hide the link to increase or decrease the font size
	
	
	
	if(document.getElementById("fontIncrease") != null) {//if fontIncrease has been written to the document
		if(fontCtr<7){
			document.getElementById("fontIncrease").innerHTML = "<a href='#' onclick='increaseFontSize(true);' id='fontIncreaseLink'>Make text larger</a>"
		}else{				
			document.getElementById("fontIncrease").innerHTML = "";
		}	
		if(fontCtr>-3){
			document.getElementById("fontDecrease").innerHTML = "<a href='#' onclick='decreaseFontSize(true);' id='fontDecreaseLink'>Make text smaller</a>";
		}else{
			document.getElementById("fontDecrease").innerHTML = "";
		}
		document.getElementById("restoreLink").style.fontSize = document.getElementById("pageOptBtn").style.fontSize;
		document.getElementById("widthView").style.fontSize = document.getElementById("pageOptBtn").style.fontSize;
		if (document.getElementById("fontIncreaseLink")!=null)
			document.getElementById("fontIncreaseLink").style.fontSize = document.getElementById("pageOptBtn").style.fontSize;
		if (document.getElementById("fontDecreaseLink")!=null)
			document.getElementById("fontDecreaseLink").style.fontSize = document.getElementById("pageOptBtn").style.fontSize;
	}
	setFormFields();
}


function setCookie(name,value,duration,path,domain,secure){
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration) + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
document.cookie=cookiestring;
} 
function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}	
function getCookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function switchOptionDisp(){
	var s="";
	//shows or hides the page options
	if(document.getElementById("pageOptions").style.visibility=="visible"){
		document.getElementById("pageOptions").style.visibility="hidden";		
		document.getElementById("pageArrow").src = "/i/arrowDown.gif";
		document.getElementById("pageOptBox").innerHTML = "";	
		//document.getElementById("pageOptions").style.height="0px;";
	}else{
		document.getElementById("pageOptions").style.visibility="visible";		
		document.getElementById("pageArrow").src = "/i/arrowUp.gif";		
	
		s = "<div class='greenBotBorder'><a href='#' onclick='restoreDefaults();' id='restoreLink'>Restore defaults</a></div>";
		if (parseInt(document.getElementById('mainArea').style.width) == 925){ //currently narrow view so switch to a wide view			
			s += "<div class='greenBotBorder'><a href='#' id='widthView' onclick='switchView();'>Switch to wide page</a></div>";
		}else{
			s += "<div class='greenBotBorder'><a href='#' id='widthView' onclick='switchView();'>Switch to narrow page</a></div>";
		}
		s += "<div id='fontIncrease'><a href='#' onclick='increaseFontSize(true);' id='fontIncreaseLink'>Make text larger</a></div>";
		s += "<div id='fontDecrease'><a href='#' onclick='decreaseFontSize(true);' id='fontDecreaseLink'>Make text smaller</a></div>";
		document.getElementById("pageOptBox").innerHTML = s;	
		dispOrHideFontChange();
	}	
}

function email_friend()
{
	var e_add= "";//prompt('Enter your friend\'s email address:',' ');
	var subj= "Pinscentral.com Web Page"; //prompt('Enter the subject of your message:',' ');
	var e_body = "You may be interested in this Pinscentral.com web page " + location.href;
	if ((subj==" ") || (subj==null))
	 	subj="Hi!";
	if (e_add==null)
		e_add=""; 
	window.location="mailto:"+e_add+"?subject="+subj+"&body="+e_body;
}
function Rcertify() { 
popupWin = window.open
('http://www.bbbonline.org/cks.asp?id=1020125821119005', 'Participant', 'location=yes,scrollbars=yes,width=550,height=300,resizable=1') 
window.name = 'opener'; 
} 

function setFormFields(){
	try{
		
		document.form1.fontCtr.value = fontCtr;
		if(getCookie("screenView")!="")
			document.form1.screenView.value = getCookie("screenView");
		//alert(document.form1.fontCtr.value);
	}catch(er){}
	
}

function openRepWindow(url) { 
  popupWin = window.open
  (url, 'Participant', 'location=no,scrollbars=yes,width=510,height=350') 
  window.name = 'repPopup'; 
}
	