var ie, ns, ns6;
ie=document.all ?1:0;
ns=document.layers ?1:0;
ns6=(document.getElementById && !document.all )?1:0;

var curlink;


//===================================================================================
//===================================================================================
//========================== GENERAL FUNCTIONS STARTS HERE ==========================
function TrimChar (inputString, removeChar){
var returnString = inputString;
if (removeChar.length){
while(''+returnString.charAt(0)==removeChar){
returnString=returnString.substring(1,returnString.length);
}
while(''+returnString.charAt(returnString.length-1)==removeChar){ returnString=returnString.substring(0,returnString.length-1); 
  }
 }
return returnString;
}

//=========================================
function CheckEmail(Fld) {
var tmp;
Fld.value=TrimChar(Fld.value," ");
tmp=Fld.value;
if (tmp=="") { 
alert("Please provide the email address");
Fld.focus(); return false;
   }
else if ( (tmp.indexOf('@',0)==-1) || (tmp.indexOf('.')== -1 ) ){ 
alert("Invalid email address format!");
Fld.focus(); 
return false;
   }
else {return true; }
}

//=======================================
function CheckField(Fld,Msge){
Fld.value=TrimChar(Fld.value," ");
if(TrimChar(Fld.value," ")==""){
alert(Msge);Fld.focus(); return false;} 
else { return true;}  
}

//================================
function CheckNumber(Fld,Fldname){
var tmp;
Fld.value=TrimChar(Fld.value," ");
tmp=Fld.value;
if(tmp==""){ alert("Please provide "+Fldname+"?");  Fld.focus();return false;}
else if (isNaN(tmp)){ 
alert("Invalid Entry for "+ Fldname+"!\n"+
      "Must be number. No comma please!"); 
Fld.focus();  
return false;} 
else{ return true;}
}


//==============================================================================
//==============================================================================
//=========================== END GENERAL FUNCTIONS ============================

function PopulateSubCategory(selectedArray){
var i,n, tmp;

tmp=eval('document.searchform.subcategories');
while (1< tmp.options.length) {
tmp.options[(tmp.options.length-1)] = null;
}

if(selectedArray!=null){
n=selectedArray.length;
k=1;
for (i=0; i<n; i+=2) {
tmp.options[k]=new Option (selectedArray[i],selectedArray[i+1],false);
k++;
   }
}
  
tmp.options[0].selected=true;
}//end function


function DesignerChange(){
var k,tmp, curarray;
tmp=eval('document.searchform.designers');
k=tmp.options[tmp.selectedIndex].value;
var Parts=k.split('|');
var designerid=Parts[0];

curarray=eval('Designer_'+designerid);
PopulateSubCategory(curarray);

return true;
}

//============================================================
//======================Left links rollover effect ===========
function LinkSelect(clink){
var tmp, bcolor;
curlink=clink;

if(clink<'1'){bcolor="#C3CF3B"; }
else {bcolor="#555F00";}
if(clink!=''){
    if(ie){tmp=eval('document.all.hyp_'+clink); }
    else if (ns6){tmp=eval('document.getElementById("hyp_'+clink+'")'); }
    else if(ns){tmp=eval('document.layers["hyp_'+clink+'"]'); }
	
	tmp.style.background=bcolor;
    tmp.style.color="#FFFFFF";	
 }//end upper if

if(clink=='36'){
	tmp.style.color="#99FF66";
	tmp.style.background=bcolor;
	}

}//end function



function RightClick(evt) {
	var Msge="IBelieveCollectibles.com \n"+ "Collectibles for your imagination";
	  if(ie){ if (event.button==2) {alert(Msge);} }
else if(ns6){ if(evt.button==2){alert(Msge); } }
  }
//if(ie){document.onmousedown = RightClick;}
//else if(ns6){document.onmousedown = RightClick;}

function LinkOver(i){
var tmp;

if(i!=curlink){
if(ie){
tmp=eval('document.all.mlink'+i);
tmp.style.background="#AAFF55";
} 
else if(ns6){
tmp=eval("document.getElementById('mlink'+i)");
tmp.style.background="#AAFF55";
}
else if (ns){
tmp=eval('document.layers.mlink'+i);
tmp.style.background="#AAFF55";
 }
}
}


function LinkOut(i){
	if(i!=curlink){
if(ie){
tmp=eval('document.all.mlink'+i);
tmp.style.background="#A7D17C";
} 
else if(ns6){
tmp=eval("document.getElementById('mlink'+i)");
tmp.style.background="#A7D17C";
}
else if (ns){
tmp=eval('document.layers.mlink'+i);
tmp.style.background="#A7D17C";
}
	}
}


//=============================================================
//======================= Top navigation Links ===============
function TopOver(i){
var tmp;

if(ie){
tmp=eval('document.all.mlink'+i);
tmp.style.background="#9542B3";
} 
else if(ns6){
tmp=eval("document.getElementById('mlink'+i)");
tmp.style.background="#9542B3";
}
else if (ns){
tmp=eval('document.layers.tmlink'+i);
tmp.style.background="#9542B3";
}

}


function TopOut(i){
if(ie){
tmp=eval('document.all.mlink'+i);
tmp.style.background="#852D85";
} 
else if(ns6){
tmp=eval("document.getElementById('mlink'+i)");
tmp.style.background="#852D85";
}
else if (ns){
tmp=eval('document.layers.mlink'+i);
tmp.style.background="#852D85";
}

}

//===================================================
//============== Redeem Gift Certificate ============
function GiftRecipient(){
var tmp, Msge;
tmp=eval('document.myform.certificate');
Msge="Please enter the certificate number";
if(!CheckField(tmp, Msge)){ return false; }

tmp=eval('document.myform.email');
if(!CheckEmail(tmp)){ return false; }

tmp=eval('document.myform.recipient');
Msge="Please enter the recipient's name";
if(!CheckField(tmp, Msge)){ return false; }

document.myform.submit();
return true;
}


function GiftCertificate(){
var tmp, tmp1, fname;
tmp=eval('document.myform.recipient');
Msge="Please enter the recipient's full name";
if(!CheckField(tmp, Msge)){ return false; }

tmp=eval('document.myform.email');
if(!CheckEmail(tmp)){return false; }

document.myform.submit();
return true;
}


//====================================================
//=====================================================
function Tellafriend(){
StrFeatures="top=0, left=0, width=600, height=400, toolbar=no, menuba=0, location=no, directories=no";
window.open('tellafriend.html','NewWin', StrFeatures);
return true;
}


//==================================================================
//========================= SEARCH FEATURE =========================
function SubCategorySearch(){
var tmp;
tmp=eval('document.searchform.subcategories');

k=tmp.options[tmp.selectedIndex].value;
if(k!=''){
window.location='http://www.ibelievecollectibles.com/'+k;
return true;
}
else{
alert("Please select subcategory");
tmp.focus();
return false;
}

}//end function 


function CatalogSearch(){
var k, n, tmp;
var querystr='';
tmp=eval('document.searchform.keywords');
Msge="Please enter search keywords";
if(!CheckField(tmp, Msge)){return false; }
else {
k=tmp.value;
window.location='http://www.ibelievecollectibles.com/catalogsearch.php?keywords='+k;
return true;
}
}

//===============================================
function SubscribeVerify(){
var tmp;

tmp=eval('document.subscriptionform.email');
if(!CheckEmail(tmp)){return false; }

document.subscriptionform.submit();
return true;
}

//===============================================
function ShowToFriend(){
	var tmp;
	if(ie){
	tmp=eval('document.all.tofriend');
	tmp.style.visibility="visible";
	}
	else if(ns6){
	tmp=eval('document.getElementById("tofriend")');
	tmp.style.visibility="visible";
	}
	else if(ns){
	tmp=eval('document.layers.tofriend');
	tmp.style.visibility="visible";
	}
	
return true;	
}

//================================================
//=========================================
function CheckFriendEmail(Fld, Who) {
var tmp;
Fld.value=TrimChar(Fld.value," ");
tmp=Fld.value;
if (tmp=="") { 
alert("Please provide "+Who+" email address");
Fld.focus(); return false;
   }
else if ( (tmp.indexOf('@',0)==-1) || (tmp.indexOf('.')== -1 ) ){ 
alert("Invalid email address format!");
Fld.focus(); 
return false;
   }
else {return true; }
}


//=================================================

function SendToAFriend(){
var tmp1, tmp, Who;

tmp=eval('document.friendform.fromemail');
if(!CheckFriendEmail(tmp, 'your')){return false; }

tmp=eval('document.friendform.toemail');
if(!CheckFriendEmail(tmp, 'your friend')){return false; }

document.friendform.submit();
return true;
}

//======================================================================
function SendFeedback(){
var tmp;

tmp=eval('document.feedbackform.fullname');
Msge="Please enter your full name";
if(!CheckField(tmp, Msge)){return false; }
			   
Msge="Please enter your email address";			   
tmp=eval('document.feedbackform.email');
if(!CheckField(tmp, Msge)){return false; }
else if(!CheckEmail(tmp)){return false; }

tmp=eval('document.feedbackform.readpolicy');
if(!tmp.checked){
	if(confirm("Have you read our privacy policy?")){tmp.checked=true;}
			   else {
				   tmp.focus();
			       return false;
			   }

	}

document.feedbackform.submit();
return true;
}


//================================================
function ShippingVerify(){
var k, p,tmp, tmp1, tmp2;

tmp=eval('document.shipform.billToCountry');
k=tmp.options[tmp.selectedIndex].value;
tmp1=eval('document.shipform.billToState');
p=tmp1.options[tmp1.selectedIndex].value;
document.shipform.bcountry.value=tmp.options[tmp.selectedIndex].text;
document.shipform.bstate.value=tmp1.options[tmp1.selectedIndex].text;

if(k==''){
	alert('Please select your country');
	tmp.focus();
	return false;
}
else if(k=='us' && p==''){
	alert('Please select your home state');
	tmp1.focus();
	return false;	
}

//================ Verify Shipping Information ===============
tmp=eval('document.shipform.shipToCountry');
k=tmp.options[tmp.selectedIndex].value;
tmp1=eval('document.shipform.shipToState');
p=tmp1.options[tmp1.selectedIndex].value;
document.shipform.scountry.value=tmp.options[tmp.selectedIndex].text;
document.shipform.sstate.value=tmp1.options[tmp1.selectedIndex].text;

if(k==''){
	alert("Please select the country you are\n"+
		  "shipping the merchandise to");
	tmp.focus();
	return false;
}
else if(k=='us'){//shipping to the US
ShowShipFields();
	if(p==''){
		alert("Please select the state you are\n"+"shipping the merchandise to");
		tmp1.focus();
		return false;
	}
	else if(p=='HI' || p=='AK'){
		ShowShipFields();
		tmp2=eval('document.shipform.shipping');
		Msge="Please contact us to determine your shipping cost \n"+
			  "OR enter the dollar amount sent to you by email.";
		if(!CheckField(tmp2,Msge)){return false; }
		
		if(!CheckNumber(tmp2, 'shipping cost')){return false; }
		else if(parseFloat(tmp2.value)<0){
			      alert("Please enter your shipping cost");
				  tmp2.focus();
				  return false;
				  }
	}
	
}//end else if
else {//not shipping to the US	
	ShowShipFields();
		tmp2=eval('document.shipform.shipping');
		Msge="Please contact us to determine your shipping cost \n"+
			  "OR enter the dollar amount sent to you by email.";
		if(!CheckField(tmp2, Msge)){return false; }

		if(!CheckNumber(tmp2, 'shipping cost')){return false; }
		else if(parseFloat(tmp2.value)<0){
			      alert("Please enter your shipping cost");
				  tmp2.focus();
				  return false;
				  }
	
}
	
document.shipform.submit();
return true;
}//end function
	

//==============================
function ShowShipFields(){
var k, p,tmp, tmp1;

tmp=eval('document.shipform.shipToCountry');
tmp1=eval('document.shipform.shipToState');
k=tmp.options[tmp.selectedIndex].value;
p=tmp1.options[tmp1.selectedIndex].value;

if( (k=='us' && p!='HI' && p!='AK') || k=='' ){
	 if(ie){
	  document.all.shiplabel.style.visibility="hidden";
	  document.all.shipbox.style.visibility="hidden";
	  }
  else if(ns6){
	  document.getElementById("shiplabel").style.visibility="hidden"; 
	  document.getElementById("shipbox").style.visibility="hidden"; 
	  }
}
else {
if(ie){
	  document.all.shiplabel.style.visibility="visible";
	  document.all.shipbox.style.visibility="visible";
	  }
  else if(ns6){
	  document.getElementById("shiplabel").style.visibility="visible"; 
	  document.getElementById("shipbox").style.visibility="visible"; 
	  }	
}
	
	return true;
}//end function

var isFirst=false; 	
//======================================
function GoogleTranslate(){
var langpair=eval("document.translateform.langpair.value");

if(langpair==""){alert("Please select a language to translate to"); return false; }
if(!isFirst){
	alert("Note: Translations are not always perfect.\n"+
		  "Only translate on a page per page basis if needed \n"+
		  "If the page looks wrong or something is not working,\n"+
		  "then please go back and use the original english page.\n\n"+
		  "Thanks For Shopping at IBelieveCollectibles.com");	
}
isFirst=true; 
var desturl="http://translate.google.com/translate?u="+window.location+"&langpair="+langpair;
window.open(desturl, "NewWin"); 
}//end function



function ValidateBanner(){
var tmp, Msge;

tmp=document.bannerform.ContactEmail;
Msge='Please enter your email address';
if(!CheckEmail(tmp)){return false; }
tmp=document.bannerform.SiteURL;
Msge='Please enter your web site address';
if(!CheckField(tmp, Msge)){return false; }

tmp=document.bannerform.Banner;
Msge='Please select your banner image';
if(!CheckField(tmp, Msge)){return false; }

tmp=document.bannerform.ReciprocalURL;
Msge='Please enter yourreciprocal link address';
if(!CheckField(tmp, Msge)){return false; }
	
document.bannerform.submit();
return true;
}