var curSize="";
//prevent page from being loaded within a frame
try{
if (self != top)
{
   if (document.images)
      top.location.replace(window.location.href);
   else
      top.location.href = window.location.href;
}
}catch(er){}

window.onload = initPage;

function initPage(){
	var startPos=0;
	var gr=""; //groupname
	var pr="";//productname
	var ctr=1;	
	
	var halfBg=0;
	
	try{
		var pgURL = location.href.toLowerCase();		
		if (parseInt(screen.width) > 1152 || pgURL.indexOf("/sample_symbolism") > 0){ //if the screen width is > than 1152 then widen the page
 			document.getElementById('mainArea').style.width = "1152px";			
			if(document.getElementById('leftAndMain')!=null)
				document.getElementById('leftAndMain').style.width = "995px";
			if(document.getElementById('main')!=null)
				document.getElementById('main').style.width = "836px";	
			if(document.getElementById('mainNoRScroll')!=null)
				document.getElementById('mainNoRScroll').style.width = "992px";				
				
						
			//if(document.getElementById('mainNoScrolls')!=null)
			//	document.getElementById('mainNoScrolls').style.width = "1152px";	
			
			halfBg = parseInt((parseInt(screen.width) - 1152) / 2)-10; //get half of total background area (for a side)			
		}else{
			//normal size, nothing changed
			halfBg = parseInt((parseInt(screen.width) - 925) / 2); //get half of total background area (for a side)
		}	
			
		
		if(document.getElementById('leftBg')!=null){
			document.getElementById('leftBg').style.width = halfBg + "px";
			document.getElementById('rightBg').style.width = halfBg + "px";		
			if(halfBg<60){
				//could use smaller images if desired
			}			
		}	
		
	}catch(er){}		
	
	//initialize variables for scroll down thingy
	try{
		
		var rightCol = document.getElementById("right");
		if (parseInt(screen.width) > 1152 || pgURL.indexOf("/sample_symbolism") > 0){
			pop_Start=474;		
			//alert('fdasfffff');	
			endVar=800;
			if(rightCol==null)//if no right column exists
				endVar=955;								
			if (pgURL.indexOf("/shopcart") > 0){ 
				rectH=236;	//change clip height for shopcart page
				endVar=935;
			}
		}else{
			if(rightCol==null)//if no right column exists
				endVar=730;	
			if (pgURL.indexOf("/shopcart") > 0){ 
				rectH=236;	//change clip height for shopcart page
				endVar=715;
			}	
		}				
	}catch(er){}	
	
	
	curSize=getCookie("textSize");	
	
	//if size in cookie then use it to set the size 
	if (curSize!="")
		changeSize(0); 	
	if (location.href.indexOf("/Group.")>0){ //if category page expand products list
		startPos=location.href.indexOf("/Group.")+7;
		gr=location.href.substring(startPos,location.href.indexOf("/",startPos))
		gr=decodeURI(gr);	
		gr=replace(gr,"+"," ");			
		while(document.getElementById("gr" + ctr) != null){	
			if(document.getElementById("gr" + ctr).innerHTML==gr)
				 switchDesc("cat" + ctr); 
			ctr++;
		}		
	}	
	if (location.href.indexOf("/item.")>0){ //if on a product
		startPos=location.href.indexOf("/item.")+1;
		pr=location.href.substring(startPos,location.href.indexOf("/",startPos)+1)//pr is set as "item.xxxx/" having xxxx being the product number 
		ctr=1;
		while(document.getElementById("fullDesc_cat" + ctr) != null){//look for product number loop through groups	
			if(document.getElementById("fullDesc_cat" + ctr).innerHTML.indexOf(pr)!=-1)
				 switchDesc("cat" + ctr); 
			ctr++;
		}	
	}	
	if (location.href.indexOf("/theme.")>0){ //if on a product
		startPos=location.href.indexOf("/theme.")+1;
		pr=location.href.substring(startPos,location.href.indexOf("/",startPos)+1)//pr is set as "theme.xxxx/" having xxxx being the product number 
		ctr=1;
		while(document.getElementById("fullDesc_cat" + ctr) != null){//look for product number loop through groups	
			if(document.getElementById("fullDesc_cat" + ctr).innerHTML.indexOf(pr)!=-1)
				 switchDesc("cat" + ctr); 
			ctr++;
		}	
	}				
}
//only replaces values 1 character in length
function replace(argvalue, replaceFrom, replaceTo) {
  argvalue = argvalue.toString();
  var newValue = "";
  for (var n = 0; n < argvalue.length; n++){
    if (argvalue.substring(n, n+1) == replaceFrom){
    newValue = newValue + replaceTo;
    } else {
          newValue = newValue + argvalue.substring(n, n+1);      
    }
  } 
    return newValue;
}
function changeSize(addSizeVal){
	var originalSize;	
	if (curSize=="")//if never used
		curSize=0;
	originalSize=curSize;	
	curSize = parseInt(curSize)+parseInt(addSizeVal);	
	if (parseInt(curSize)>4||parseInt(curSize)<-2) 	
		curSize = originalSize;	
	setCookie("textSize",curSize,90,"/");	
	var ctr=1;	
	while(document.getElementById("sizeTxt" + ctr) != null){
		sizeT = document.getElementById("sizeTxt" + ctr);
		sizeT.className="fSize" + curSize;		
		ctr++;
	}	
}	

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 Rcertify() { 
  popupWin = window.open('http://www.bbbonline.org/cks.asp?id=10201258173320730', 'Participant', 'location=yes,scrollbars=yes,width=550,height=300');
  window.name = 'opener'; 
}
function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=550');
	self.name = "mainWin"; 
}
function new_window(url)  {
	links = window.open(url, 'Link', 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=1, width=325, height=370, left=330, top=160');
}
function newWindow(url,width,height){
	options = 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=1, width=' + width + ', height=' + height + ', left=330, top=160';
	tourWin = window.open(url, "win", options);
	self.name = "mainWin";
}

//scroll down window thingy
	var pop_Top= -131;
	var pop_Height=245; 
	var pop_UpDown=1;
	var pop_EndPoint=0;
	var pop_Hidden=0;	
	
	var rectH=185; //236 for shopcart	
	var endVar=580;//360; //220 for shopcart		
	var pop_Start=380;
		
	
		
		
	var tDelay = 19000;
	
	function pop_ViewAgain(){
		//replays the special window 
		pop_UpDown=1;
		pop_ShowSpecialNow();		
	}
	function pop_ShowSpecialNow(){	
		var ua=navigator.userAgent.toLowerCase();
						
		//if ( (ua.indexOf("opera")==-1)&&((ua.indexOf("msie")!=-1)&&(ua.indexOf("windows")!=-1))||((ua.indexOf("msie 5")!=-1)&&(ua.indexOf("mac")!=-1)) ) {	
			//pop_ClickSpecial.style.left=pop_ShowSpecial.style.left=((document.body.offsetWidth/2)-160)
			
			document.getElementById("pop_ClickSpecial").style.left=pop_Start + "px";
			document.getElementById("pop_ShowSpecial").style.left=pop_Start + "px";
			pop_PullDown();
		//}
	}
	function pop_PullDown(){			
		if (((pop_Height<rectH)&&(pop_UpDown==0)) || ((pop_Height>3)&&(pop_UpDown==1))) {
			if(pop_Height==rectH){document.getElementById("pop_ShowSpecial").style.display=""}
			(pop_UpDown==0)?pop_Height+=3:pop_Height-=3;
			(pop_UpDown==0)?pop_Top-=3:pop_Top+=3;
			document.getElementById("pop_ShowSpecial").style.clip= "rect(" + pop_Height + "px,220px," + rectH + "px,0px)";
			document.getElementById("pop_ShowSpecial").style.top=pop_Top + "px";
			setTimeout("pop_PullDown();",20);
		}else{
			if (pop_UpDown==1){
				document.getElementById("pop_ShowSpecial").style.clip="rect(0px,220px," + rectH + "px,0px)";
				document.getElementById("pop_ShowSpecial").style.top=114 + "px";
				pop_UpDown=0;
				document.getElementById("pop_ClickSpecial").style.display='';			
				setTimeout("pop_PullDown();",tDelay); //pause the popup before hidding
			}else{
				document.getElementById("pop_ShowSpecial").style.display='none';			
				pop_EndPoint=pop_Start; //(document.body.offsetWidth/2)-160;
				pop_Hide();			
			}
		}
	}
	
	function pop_StartHide(){	
	//created by Mike to hide the scroll right away and start sliding button to right 
	document.getElementById("pop_ShowSpecial").style.display='none';			
	pop_EndPoint=pop_Start;//(document.body.offsetWidth/2)-160;
	pop_Hide();			
}
	
function pop_Hide(){		
	//if(pop_EndPoint<(document.body.offsetWidth-endVar)){
	if(pop_EndPoint<(endVar)){
		pop_EndPoint+=5;
		document.getElementById("pop_ClickSpecial").style.left=pop_EndPoint + "px";
		setTimeout("pop_Hide();",20);
	}else{
		pop_Hidden = 1;
	}
}
function switchDesc(id) {
	var button = document.getElementById("switch_"+id);
	if(button==null)
		return true;	
	var part2 = document.getElementById("fullDesc_"+id);		
	if(button.className=='plusDesc') { //expand
		button.className='minusDesc';
		if(part2!=null) part2.style.display='inline';	
	} else if(button.className=='minusDesc') { // contract
		button.className='plusDesc';
		if(part2!=null) part2.style.display='none';	
	}
	if( navigator != null && navigator.userAgent != null && navigator.userAgent.indexOf("Firefox") != -1 )
		document.body.innerHTML = document.body.innerHTML; // force firefox to re-compute the layout
	return false;
}
 
function navigateTo(prod,sId,surname,origin){	
	if(prod=="JPG-CLAN"){
		location.href = "/clanresults.asp?item=" + prod + "&sId=" + sId + "&surname=" + surname;
	}else{	
		location.href = "/nameresults.asp?item=" + prod + "&sId=" + sId + "&surname=" + surname + "&origin=" + origin;
	}
	return false;
}

function newWindow(url) { 
	popupWin = window.open
	(url, 'Participant', 'location=no,scrollbars=yes,width=600,height=400');
}

function email_friend()
{
	var e_add= "";//prompt('Enter your friend\'s email address:',' ');
	var subj= "HouseOfNames Web Page"; //prompt('Enter the subject of your message:',' ');
	var e_body = ""
	if (location.href.indexOf("?") > 0){ //tried to append source=emailFriendReferrel 
		e_body = "You may be interested in this HouseOfNames.com web page " + location.href.replace("&","%26") + "%26source=emailFriendReferrel";
	}else{
		e_body = "You may be interested in this HouseOfNames.com web page " + location.href.replace("&","%26") + "?source=emailFriendReferrel" ;
	}
	if ((subj==" ") || (subj==null))
	 	subj="Hi!";
	if (e_add==null)
		e_add=""; 
	window.location="mailto:"+e_add+"?subject="+subj+"&body="+e_body;
}	