var tmp0=new Image(); tmp0.src = "/images/xaxxon-blink_0.gif";
var tmp1=new Image(); tmp1.src = "/images/xaxxon-blink_1.gif";
var tmp2=new Image(); tmp2.src = "/images/xaxxon-blink_2.gif";
var tmp3=new Image(); tmp3.src = "/images/xaxxon-blink_3.gif";
var blinksequence = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,
		0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,3,3,3,3];
var blinksequenceindex = 0;
var xmlhttp;
var linkhovercolor = "#bbbbbb";
var bodywidthorig;
var gmtoffset;

function loaded() {
	blink();
	loadtwitter();
	var msg = document.getElementById("msgbox").innerHTML;
	if (/\w+/.test(msg)) { alert(msg); }
	bodywidthorig= document.body.clientWidth;
	var e=new Date();
	gmtoffset = e.getTimezoneOffset();
}

function blink() {
  var a=document.getElementById("xaxxonblink");
  a.src="/images/xaxxon-blink_"+blinksequence[blinksequenceindex]+".gif";
  blinksequenceindex ++;
  if (blinksequenceindex >= blinksequence.length) { blinksequenceindex=0; }
  setTimeout("blink()",250);
}

function openxmlhttp(theurl, functionname) {
  xmlhttp=null;
  if (window.XMLHttpRequest) {// code for all new browsers
    xmlhttp=new XMLHttpRequest(); }
  else if (window.ActiveXObject) {// code for IE5 and IE6
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    theurl += "?" + new Date().getTime();
  }
  if (xmlhttp!=null) {
    xmlhttp.onreadystatechange=functionname; //event handler function call;
    xmlhttp.open("GET",theurl,true);
    xmlhttp.send(null);
  }
  else {
    alert("Error - browser does not support XMLHTTP");
  }
}

function loadtwitter() {
	openxmlhttp("/xaxxon/twitterfeed",twitterloaded)
}

function twitterloaded() {
  if (xmlhttp.readyState==4) {// 4 = "loaded"
    if (xmlhttp.status==200) {// 200 = OK
		var a = document.getElementById("twitterfeed");
		a.innerHTML = xmlhttp.responseText;
		var bw = document.body.clientWidth;
		if (bw < bodywidthorig) {
			document.body.style.paddingLeft = (bodywidthorig-bw)+"px";
		}
    }
  }
}

function news_signup() {
	var email = document.getElementById("mailing_list_user_email").value;
	openxmlhttp("/xaxxon/news_signup?email="+email,news_signup_response);
}

function news_signup_response() {
  if (xmlhttp.readyState==4) {// 4 = "loaded"
    if (xmlhttp.status==200) {// 200 = OK
      alert(xmlhttp.responseText);
    }
  }
}

function keypress(e) {
	var keynum;
	if (window.event) {
		keynum = e.keyCode;
	}// IE
	else if (e.which) {
		keynum = e.which;
	} // Netscape/Firefox/Opera
	return keynum;
}

function menubuttonover(id) {
	var a= document.getElementById(id);
	a.style.backgroundColor = linkhovercolor;
	a.style.borderColor = "#888888";
	document.getElementById("menu"+(parseInt(/\d+/.exec(id))+1)).style.borderColor = "#999999";
}

function menubuttonout(id) {
	var a= document.getElementById(id);
	a.style.backgroundColor = "transparent";
	a.style.borderColor = "#d2d2d2";
	document.getElementById("menu"+(parseInt(/\d+/.exec(id))+1)).style.borderColor = "#d2d2d2";
}

function menubuttonclick(url) {
	location.assign(url);
}

function shippingcalculate() {
	document.getElementById("waitingmessagebox").style.display = "";
	var f = document.getElementById("shippingform");
	f.action="/shop/shippingcalc";
	f.submit();
}

function shippingrecalcrequired() {
	var a = document.getElementById("showshippingcost")
	if (a != null) {
		a.style.display = "none";
		document.getElementById("calcshippingcost").style.display = "";
	}
}

function paypalclicked(paypaltranscode) {
	document.getElementById('waitingmessagebox').style.display = ''
	openxmlhttp("/shop/paypalgo?gmtoffset="+gmtoffset+"&paypaltranscode="+paypaltranscode, paypalsubmit);
}

function paypalsubmit() {
  if (xmlhttp.readyState==4) {// 4 = "loaded"
    if (xmlhttp.status==200) {// 200 = OK
			document.getElementById("paypalbutton").submit();
    }
    else {
      //alert("Problem retrieving XML data");
    }
  }
}

function signin(url) {
	var a=document.getElementById('shipto'); 
	if (a != null) {
		a.action='/shop/checkoutchanged?url='+url; 
		a.submit();
	}
	else { location.assign(url); }
}


