/**
 * @author PC-Magic Software - copyrighted 2008
 */

var otherPopping = false;

function searchStuff(){
	opt = document.searchform.searchsrc.value;
	if (opt=='amazon') searchAmazon('All');
	if (opt=='amazonsub') searchAmazon(document.searchform.parent.value);
	if (opt=='buy') searchBuy();
	if (opt=='ebay') searchEbay();
	if (opt=='web') webSearch();
	return false;
}

function searchAmazon(searchIndex){
	document.searchform.target='_self';
	document.searchform.action='main.php?search=1&asearch=1&SearchIndex='+searchIndex;
	document.searchform.submit();	
	return false;
}

function searchBuy(){
	k = document.searchform.key.value;
	k.replace(" ","+");
	//f update tracking code periodically?
	t = "http://www.buy.com/retail/GlobalSearchAction.asp?adid=17662&aid=10387780&pid=2984703&qu="+k;
//	alert(t);
	centerPop(t,1024,600);
//	window.event.returnValue = false;  //didn't help
	return false;
}

function searchEbay(){
	document.searchform.action = "eb.php";
	document.searchform.target = "_self";
	document.searchform.submit();
	return false;
}

function CreateBookmarkLink() {
	setCookie("been2bookmark",3650);
	title = "TopSellers";
	url = "http://www.TopSellers.com";
	if (window.sidebar) { // Mozilla Firefox Bookmark
	window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
	window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
	return true; 
	}
	
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function delCookie ( cookie_name )
{
    document.cookie = cookie_name + "=; max-age=0;";
}

function goMerchant(m){
	if (m=='buy') {
		if (getCookie("buylast")){
			window.location=getCookie("buylast");
		}else{
			window.location="Balls.htm";
		}
	}
	
	if (m=='amazon') {
		if (getCookie("amlast")){
			window.location=getCookie("amlast");
		}else{
			window.location="allstars.htm";
		}
	}
	if (m=='ebay') {
		if (getCookie("ebaylast")){
			window.location=getCookie("ebaylast");
		}else{
			window.location="Ealls.htm";
		}
	}
}
//this is the opt=1 stuff
function centerPop(lnk,width,height){
	if (otherPopping) return;
//	ScrollTop = f_scrollTop();  //didn't work, cause pop-up window? no, works on other popup
	t = window.open(lnk,'','toolbar=1,scrollbars=1,location=1,status=0,menubar=0,resizable=1,width='+width+',height='+height+',top='+(((screen.height-height)/2)-40)+',left=' + ((screen.width-width)/2));
//	setTimeout("scrollTo(ScrollTop);",500);
	return t;
}

function centerPopp(lnk,width,height){
	t = window.open(lnk, '_blank');
	t.focus();
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function popUPC(upc){
	setPopping();
	ScrollTop = f_scrollTop();
	width=350;
	height=120;
//   t = window.open("http://pc-magic.com/ab.php?upc="+upc,'','toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,width='+width+',height='+height+',top='+(((screen.height-height)/2)-40)+',left=' + ((screen.width-width)/2));
   t = window.open("ab.php?upc="+upc,'','toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,width='+width+',height='+height+',top='+(((screen.height-height)/2)-40)+',left=' + ((screen.width-width)/2));
	setTimeout("scrollTo(ScrollTop);",500)  
}

function scrollTo(y){
//	alert(y);
	this.scroll(0,y);
}

function getCookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function webSearch(){
	t = document.searchform.key.value;
	document.searchform.q.value = t;
	t = document.searchform;
	t.target = "google window";
	t.action = "http://www.google.com/custom";
	t.method = "get";
	t.submit();
	return false;
}
function setSortColor(opts){
	try{	
		document.getElementById("sortval1").style.backgroundColor = "white";
		document.getElementById("sortval2").style.backgroundColor = "white";
		if (opts >2) document.getElementById("sortval3").style.backgroundColor ="white";
/*		document.getElementById("sortval"+sortval).style.color = "green"; */
		document.getElementById("sortval"+sortval).style.backgroundColor = "#FFFF80";

/*		
		document.getElementById("sortval1").src ="images/sort_1.png";
		document.getElementById("sortval2").src = "images/sort_2.png";
		if (opts >2) document.getElementById("sortval3").src = "images/sort_3.png";
		document.getElementById("sortval"+sortval).src = "images/sort_"+opts+"_sel.png";
*/		
	}
	catch(err){
		return;
	}
}

function setPageLink(opt){

	try{
	document.getElementById('pglink1').style.color = 'black';
	if (numProducts>30) document.getElementById('pglink2').style.color = 'black';
	if (numProducts>60) document.getElementById('pglink3').style.color = 'black';
	t = document.getElementById('pglink'+curpage);
	t.style.color = 'blue';
	}
	catch(err){
		return;
	}
}
function isNumeric(x) {
	if (!x) return false;
// I use this function like this: if (isNumeric(myVar)) { }
// regular expression that validates a value is numeric
var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452.
// compare the argument to the RegEx
// the 'match' function returns 0 if the value didn't match
var result = x.match(RegExp);
return result;
}
function disWishlist(){
	if ((wla.length>2)||(wle.length>2)){
//		document.getElementById('wishlist').style.visibility='visible';
//		if (!getCookie("usedWL")) {
			document["wlimg"].src = "images/wishlists_hi.gif";
			setTimeout("document['wlimg'].src = 'images/wishlists.gif'",4000);
			
//			document.getElementById('wishlist').style.backgroundColor = 'yellow';
//			setTimeout("document.getElementById('wishlist').style.backgroundColor='white';", 3000);
//		}
//	}else{
//		document.getElementById('wishlist').style.visibility='hidden';
	}
}

var dx;
var dy;
var cnt;
var po;
var eox; 
var x=10;
var y=10;

function moveLogo(opt){
	return;
	if (opt && getCookie("anilogo")) return;
	setCookie("anilogo", 1);
	cnt=0;
	setTimeout("shakeSub2();",50)
}

function setPopping(){
	otherPopping = true;	
	setTimeout("donePopping();",3000)
}

function donePopping(){
	otherPopping=false;
}

function shakeSub2(){
	if (cnt++>10){
		po.style.top = 0;
		return;
	}
	xx = ((cnt % 3)*5);
	po.style.top = xx+"px";
	setTimeout("shakeSub2();",30);
}
function moveLogo2(opt){
//	 w = screen.width;
	if (opt && getCookie("anilogo")) return;
	w = 840;
	h = screen.height / 2;
	dx = (w - x) / 40;
	dy = (h - y) / 40;
	cnt = 0;
	setCookie("anilogo", 1);
	setTimeout("movIt();", 50);
}

function movIt(){
	cnt++;
	if (cnt<40){
//		y=y+dy;
		x=x+dx;
//		po.style.top = y+"px";
		po.style.left = x+"px";
		setTimeout("movIt();",25);
	}else if (cnt<80){
		x = x-dx;
		po.style.left = x+"px";
		setTimeout("movIt();",25);
	}else if (cnt <94){
		x = 10+((cnt%3)*5);
		po.style.left = x+"px";
		setTimeout("movIt();",25);
	}else{
		po.style.left = "10px";
		cnt = 0;
	}
}

var bannercnt = 0;


function rotateBanner(){
	var banner1= document.getElementById('banner1');
	var banner2= document.getElementById('banner2');
	var banner3= document.getElementById('banner3');
	
	bannercnt = (bannercnt+1) % 4;
	banner1.style.visibility='hidden';
	banner2.style.visibility='hidden';
	banner3.style.visibility='hidden';
	if (bannercnt%2) banner1.style.visibility='visible';
	if (bannercnt==0) banner2.style.visibility='visible';
	if (bannercnt==2) banner3.style.visibility='visible';
	setTimeout("rotateBanner();",15000);
}
function shakeEmail(){
	rotateBanner();
	return;
	document.getElementById('explain').style.visibility='hidden';	
	eo.style.visibility='visible';
	if (getCookie("been2email")) return;
	cnt=0;
	setTimeout("shakeSub();",50)
}
function shakeSub(){
	if (cnt++>20){
		cnt = 0;
		setTimeout("shakeEmail();",120000);
		return;
	}
	xx = ((cnt % 3)*5)+parseInt(eox);
	eo.style.left = xx+"px";
	setTimeout("shakeSub();",50);
}
function hiliteBookmark(){
	return;
	if (getCookie("been2bookmark")) return;
	cnt=0;
	setTimeout("chgBookmark();",50)
}

function chgBookmark(){
	t = document.getElementById('bookmark');
	if (cnt++>1){
		cnt=0;
		setTimeout("chgBookmark();",180000);
		t.src = 'images/menu0a.gif';
		return;
	}
	if (cnt %2){
		t.src = 'images/menu0ah1.gif';
	}else{
		t.src = 'images/menu0a.gif';
	}
	setTimeout("chgBookmark();",5000) //200
}

var snowmax=25
var snowcolor=new Array("#AAAACC","#DDDDFF","#CCCCDD","#F3F3F3","#F0FFFF")
var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS")
var snowletter="*"
var sinkspeed=0.6
var snowmaxsize=22
var snowminsize=8
var snowingzone=1

var snow=new Array()
var marginbottom
var marginright
var timer
var i_snow=0
var x_mv=new Array();
var crds=new Array();
var lftrght=new Array();
var browserinfos=navigator.userAgent 
var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
var ns6=document.getElementById&&!document.all
var opera=browserinfos.match(/Opera/)  
var browserok=ie5||ns6||opera
var marginright=980
var marginbottom=100 //155

function randommaker(range) {		
	rand=Math.floor(range*Math.random())
    return rand
}

function initsnow() {

	var snowsizerange=snowmaxsize-snowminsize
	for (i=0;i<=snowmax;i++) {
		crds[i] = 0;                      
    	lftrght[i] = Math.random()*15;         
    	x_mv[i] = 0.03 + Math.random()/10;
		snow[i]=document.getElementById("s"+i)
		snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
		snow[i].size=randommaker(snowsizerange)+snowminsize
		snow[i].style.fontSize=snow[i].size
		snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
		snow[i].sink=sinkspeed*snow[i].size/5
		if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
		if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
		if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
		if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
		snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size)
		snow[i].style.left=snow[i].posx
		snow[i].style.top=snow[i].posy
	}
	movesnow()
}

function movesnow() {
	for (i=0;i<=snowmax;i++) {
		crds[i] += x_mv[i];
		snow[i].posy+=snow[i].sink
		snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
		snow[i].style.top=snow[i].posy
		
		if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
			if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
			if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
			if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
			if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
			snow[i].posy=0
		}
	}
	var timer=setTimeout("movesnow()",50)
}

//end of opt=1 stuff


