//var path_url='http://www.amherstwebdesign.com/proto/atlascomicbooks/';
var path_url='http://www.atlascomicbooks.com/';


function windowOnload() {

var e1; //general element holder

// set up the left menu

// atlas retro logo
e1=document.getElementById('atlas_ln').cbe; 
e1.resizeTo(130,450);
e1.moveTo(3,5);
e1.show();

j=0;
for (i=1; i<6; i++) {
	e1=document.getElementById('lmenu'+i).cbe; 
	e1.resizeTo(130,18);
	e1.moveTo(5,190+(18*i)+(j*15));
	e1.show();
	if ((p+1)!=i) {
		e1.addEventListener('mouseOver', mouseOverListener, false); 
		e1.addEventListener('mouseOut', mouseOutListener, false); 
		e1.addEventListener('click', clickListener, false); 
	}

	// load products submenu
	if (i==2) {
		for (j=1; j<5; j++) {
			e1=document.getElementById('lmenu'+i+j).cbe; 
			e1.resizeTo(130,15);
			e1.moveTo(5,190+(18*(i+1))+(15*(j-1)));
			e1.show();
			e1.addEventListener('mouseOver', mouseOverListener, false); 
			e1.addEventListener('mouseOut', mouseOutListener, false); 
			e1.addEventListener('click', clickListener, false); 
		}
		j--;
	}
}

window.cbe.addEventListener('scroll', scrollListener, false);
scrollListener(this);
if (p==99) document.forms[0].to.focus();
if (p==98) {
	e1=document.getElementById('certtxt').cbe; 
	e1.resizeTo(600,320);
	e1.moveTo(155,148);
	e1.show();
	e1=document.getElementById('certimg').cbe; 
	e1.resizeTo(600,320);
	e1.moveTo(153,146);
	e1.show();
}

if (p==1) {
	// products/store map
	var i=0;
	var j=0;
	// paint the map
	for (i=0; i<mapheight; i++) {
		for (j=0; j<mapwidth; j++) {	
		 	var e1=document.getElementById("dx"+i+"y"+j).cbe;
		 	e1.moveTo(moffx+(j*20),moffy+(i*20));
			setTerrain(i,j);
			e1.show();
		}
	}


	e1=document.getElementById("map").cbe;
	e1.moveTo(moffx,moffy);

	// add listeners for the map
	e1.addEventListener('mousemove', mapMove, false); 
	e1.addEventListener('mouseout', mapOut, false); 
	if (maint==1) {
		e1.addEventListener('click', mapClick, false); 
	}
	e1.show();

//	setCur();
//	document.getElementById("cur").cbe.show();

	handleKeyUpO(500);

	e1.width(560);
	e1.show();

	handleKeyUpO(500);
	document.forms[0].functioninput.focus();

}

}

function mouseOverListener(e) {
//alert(e.cbeCurrentTarget.id+'img'+" :"+ e.cbeCurrentTarget.id+'b');
  cbeSetImage(e.cbeCurrentTarget.id+'img', e.cbeCurrentTarget.id+'b');		
}
function mouseOutListener(e) {
//alert(e.cbeCurrentTarget.id+'img'+" :"+ e.cbeCurrentTarget.id+'b');
  cbeSetImage(e.cbeCurrentTarget.id+'img', e.cbeCurrentTarget.id+'a');		
}
function clickListener(e) {
//alert(e.cbeCurrentTarget.id+'img'+" :"+ e.cbeCurrentTarget.id+'b');
// set up for AWD
if (e.cbeCurrentTarget.id=='lmenu1') document.location.replace(path_url+'index.php');
if (e.cbeCurrentTarget.id=='lmenu2') document.location.replace(path_url+'products.php');
if (e.cbeCurrentTarget.id=='lmenu21') document.location.replace(path_url+'products.php');
if (e.cbeCurrentTarget.id=='lmenu22') document.location.replace(path_url+'products.php#role');
//if (e.cbeCurrentTarget.id=='lmenu23') document.location.replace(path_url+'products.php#manga');
if (e.cbeCurrentTarget.id=='lmenu23') document.location.replace(path_url+'products.php#supplies');
if (e.cbeCurrentTarget.id=='lmenu24') document.location.replace(path_url+'products.php#clix');
if (e.cbeCurrentTarget.id=='lmenu3') document.location.replace(path_url+'map.html');
if (e.cbeCurrentTarget.id=='lmenu4') document.location.replace(path_url+'how.php');
if (e.cbeCurrentTarget.id=='lmenu5') document.location.replace(path_url+'gallery.html');

}

function scrollListener(e) {
//alert('scroll!');

e1=document.getElementById('atlas_ln').cbe; 
e1.slideTo(3,5+document.cbe.scrollTop(),700);

j=0;
for (i=1; i<6; i++) {
	e1=document.getElementById('lmenu'+i).cbe; 
	e1.slideTo(5,190+(18*i)+(15*j)+document.cbe.scrollTop(),700);

	if (i==2) {
		for (j=1; j<5; j++) {
			e1=document.getElementById('lmenu'+i+j).cbe; 
			e1.slideTo(5,190+(18*(i+1))+(15*(j-1))+document.cbe.scrollTop(),700);
		}
		j--;
	}
}
}

function loadImages() {
cbeNewImage('lmenu1a', 'lmenu11.gif');
cbeNewImage('lmenu1b', 'lmenu12.gif');
cbeNewImage('lmenu2a', 'lmenu21.gif');
cbeNewImage('lmenu2b', 'lmenu22.gif');
cbeNewImage('lmenu21a', 'lmenu2_11.gif');
cbeNewImage('lmenu21b', 'lmenu2_12.gif');
cbeNewImage('lmenu22a', 'lmenu2_21.gif');
cbeNewImage('lmenu22b', 'lmenu2_22.gif');
cbeNewImage('lmenu23a', 'lmenu2_31.gif');
cbeNewImage('lmenu23b', 'lmenu2_32.gif');
cbeNewImage('lmenu24a', 'lmenu2_41.gif');
cbeNewImage('lmenu24b', 'lmenu2_42.gif');
cbeNewImage('lmenu25a', 'lmenu2_51.gif');
cbeNewImage('lmenu25b', 'lmenu2_52.gif');
cbeNewImage('lmenu3a', 'lmenu31.gif');
cbeNewImage('lmenu3b', 'lmenu32.gif');
cbeNewImage('lmenu4a', 'lmenu41.gif');
cbeNewImage('lmenu4b', 'lmenu42.gif');
cbeNewImage('lmenu5a', 'lmenu51.gif');
cbeNewImage('lmenu5b', 'lmenu52.gif');
}

function ship_validate(form) {
	// validate shipping address form
if (form.shipname.value == "") {
	alert( "Please enter your name." );
	form.shipname.focus();
	return false;
}
if ((form.phone_area.value<100) || (form.phone_area.value>999)) {
	alert ("Please enter your area code");
	form.phone_area.focus();
	return false;
}
if ((form.phone_part1.value<100) || (form.phone_part1.value>999)) {
	alert ("Please enter your phone number");
	form.phone_part1.focus();
	return false;
}
if (form.phone_part2.value>9999) {
	alert ("Please enter your phone number");
	form.phone_part2.focus();
	return false;
}

found=false;
for (i=0; i<numSF; i++) {
	t=eval("form.SF"+i+".checked");
	if (t) {
		found=true;
	}
}
if (!found) {
	alert ("Please select at least one comic!");
	return false
}
return true;
}

function ad_validate(form) {
	// validate add/drop form
if (form.firstname.value == "") {
	alert( "Please enter your first name." );
	form.firstname.focus();
	return false;
}
if (form.lastname.value == "") {
	alert( "Please enter your last name." );
	form.lastname.focus();
	return false;
}

if ((form.phone_area.value<100) || (form.phone_area.value>999)) {
	alert ("Please enter your area code");
	form.phone_area.focus();
	return false;
}
if ((form.phone_part1.value<100) || (form.phone_part1.value>999)) {
	alert ("Please enter your phone number");
	form.phone_part1.focus();
	return false;
}
if  (form.phone_part2.value>9999) {
	alert ("Please enter your phone number");
	form.phone_part2.focus();
	return false;
}
return true;
}

function cert_val(form) {
	// validate gift certificate form
if (form.email_from.value == "") {
	alert( "Please enter your email address where we should send the certificate link." );
	form.email_from.focus();
	return false;
}
return true;
}

function drawBanner() {

document.write("<table width=100% cellspacing=4><tr>");
document.write("<td><table width='130px' cellspacing=0 cellpadding=0><tr><td></td></tr></table></td>");
document.write("<td width='100%'><table width='100%' cellspacing=0 cellpadding=0><tr>");
document.write("<td align='left'><table background='banner.gif' height='90px' width='273px' cellspacing=4><tr><td valign='top' align='left'>");

document.write("<table cellspacing=0 cellpadding=3><tr valign='top'><td><img src='title.gif' alt='Atlas Comics'><br>");
document.write("<span class='subtitl'>&nbsp;1750 Rio Hill Center<br>&nbsp;Charlottesville, Virginia 22901<br></span><span class='subtitl3'>&nbsp;<b>434-974-7512</b><br>&nbsp;");
writeEmail('Web Inquiry');
document.write("</span>");
document.write("</td></tr></table>");
document.write("</td></tr></table>");
document.write("</td><td align='center' width='50%'><img src='bannerm.gif'></td>");
document.write("<td align='right'><table background='banner.gif' height='90px' width='273px'><tr><td align='center' valign='top'>");
document.write("<table cellspacing=0 cellpadding=0><tr>");
document.write("<td><span class='subtitl2'>Store Hours:&nbsp;&nbsp;</span></td>");
document.write("<td><span class='subtitl2'>Open&nbsp;&nbsp;</span></td>");
document.write("<td><span class='subtitl2'>Close&nbsp;&nbsp;</span></td>");
document.write("<td><span class='subtitl2'>Daily Specials</span></td></tr>");
document.write("<tr><td><span class='daily'>Sunday</span></td><td>");
document.write("<span class='daily'>noon</span></td><td><span class='daily'>6 pm</span></td><td>");
document.write("<span class='daily'><a title='All games and game accessories are 10% off' class='daily' href='products.php#role'>Game Day</a></span></td></tr>");
document.write("<tr bgcolor='cccccc'><td><span class='daily'>Monday</span></td><td>");
document.write("<span class='daily'>closed</span></td><td><span class='daily'></span></td><td>");
//document.write("<span class='daily'><a class='daily' href='products.php#role'>RPGs</a></span></td></tr>");
document.write("</td></tr>");
document.write("<tr><td><span class='daily'>Tuesday</span></td><td>");
document.write("<span class='daily'>noon</span></td><td><span class='daily'>8 pm</span></td><td>");
document.write("<span class='daily'><a title='All graphic novels are 10% off' class='daily' href='products.php'>Graphic Novels</a></span></td></tr>");
document.write("<tr bgcolor='cccccc'><td><span class='daily'>Wednesday</span></td><td>");
document.write("<span class='daily'>noon</span></td><td><span class='daily'>8 pm</span></td><td>");
document.write("<span class='daily'><a title='10% off for Atlas subscribers' class='daily' href='products.php'>New Comics</a></span></td></tr>");
document.write("<tr><td><span class='daily'>Thursday</span></td><td>");
document.write("<span class='daily'>noon</span></td><td><span class='daily'>8 pm</span></td><td>");
document.write("<span class='daily'><a title='All back stock 10% off&nbsp;' class='daily' href='products.php'>Back Stock</a></span></td></tr>");
document.write("<tr bgcolor='cccccc'><td><span class='daily'>Friday</span></td><td>");
document.write("<span class='daily'>noon</span></td><td><span class='daily'>8 pm</span></td><td>");
document.write("<span class='daily'><a title='10% off for all ladies' class='daily' href='products.php'>Lady's Day</a></span></td></tr>");
document.write("<tr><td><span class='daily'>Saturday</span></td><td>");
document.write("<span class='daily'>noon</span></td><td><span class='daily'>8 pm</span></td><td>");
document.write("<span class='daily'><a title='10% off for all kids under 13' class='daily' href='products.php'>Kids Day</a></span></td></tr></table>");
document.write("</td></tr></table>");
document.write("</td></tr></table>");
document.write("</td><td width='1px'></td></tr></table>");

document.write("<table width='100%' border='0' cellspacing='4' cellpadding='0'>");
//<!-- LEFT MENU -->
document.write("<tr><td>	<table width='130px' height='300px'><tr><td></td></tr></table></td>");
//<!-- PAGE BODY SET=UP -->
document.write("<td valign='top' width='100%'><table border=0 cellspacing=0 width='100%'><tr>");
document.write("<td valign='top' bgcolor='#ffffff'>");

return;
}

function drawFooter() {
document.write("</center></td></tr></table>");

document.write("</td></tr>");
//<!-- PAGE FOOT -->
document.write("<tr><td colspan=2 class='cright'><center>Copyright &copy;2003-2010 Atlas Endeavers, Inc.</center></td></tr>");

//<!-- AWD LOGO -->
document.write("<tr><td colspan=2 align=center><a href='http://www.amherstwebdesign.com' target='_blank'><div id='main'><img src='awd_link.gif'></a></tr></td><td width='1px'></td></tr>");
document.write("</table>");

}

function CertOnload() {

var e1; //general element holder

// set up the left menu

// atlas retro logo
e1=document.getElementById('certtxt').cbe; 
e1.resizeTo(600,320);
e1.moveTo(0,0);
e1.show();
return;

}

function popCert(pre) {
	var cwin=window.open(pre,"cert","toolbar=no,status=no,scrollbars=no,location=no,menubar=no,titlebar=no,width=610,height=350");
	cwin.focus();
	cwin.screenX=0;
	cwin.screenY=0;
}

function writeEmail(s) {
document.write("<a alt='eMail us' title='Send us email' href=mail");
document.write("to");
document.write(":info@");
document.write("atlascomicbooks.com?subject="+s+">info");
document.write("@atlascomicbooks.com</a>");
}

function toggleMe(a, c){
  var e=document.getElementById(a);

  var x='h'+c;
  var e1=document.getElementById(x);

  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  e=document.getElementById(c);
  if (e.value==' hide ') {
  	e.value='show';
  	e1.value=0;
  }
  else {
  	e.value=' hide ';
  	e1.value=1;
  }  
  return true;
}

function togglePm(a, c){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display!="block"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  e=document.getElementById(c);
  if (e.value=='-') {
  	e.value='+';
  }
  else {
  	e.value='-';
  }
  return true;
}

function d(id) {
	//alert("Under Construction!\nFetch Details for id="+id);
	 var anch="titlesbox";
   var topValue= 0,leftValue= 0;
    obj=document.getElementById(anch);
    while(obj){
  		leftValue+= obj.offsetLeft;
  		topValue+= obj.offsetTop;
  		obj= obj.offsetParent;
    }
  topValue+=30;
  leftValue+=30;	
  var e1=document.getElementById('mapu').cbe; 
	e1.resizeTo(500,200);
	e1.moveTo(leftValue,topValue);
	e1.show();
	ajaxDetails(id);

}

function cm() {
	var e1=document.getElementById('mapu').cbe; 
	e1.hide();
}

// AJAX functions
// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) 
     return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
     return new XMLHttpRequest();
   else {
   	alert("Your browser does not support AJAX.");
   	return null;
   	}
}

function ajaxDetails(id) {
	// for pullmgr.php title details
	// id is the SFid
	document.getElementById("mapuc").innerHTML="loading...";
	http = getHTTPObject();
	if (http != null) {
		var url = "http://www.atlascomicbooks.com/pullmgr.php";
		var params = "SFid="+id;
		http.open("POST", url, true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.onreadystatechange = setDetails;
		http.send(params);
	}
}

function setDetails() {
	if(http.readyState == 4){
		document.getElementById("mapuc").innerHTML=http.responseText;
	}
}


function setNoFilter() {
	if (document.forms.prefs.filter.checked) {
		document.forms.prefs.cat0.checked=true;
		document.forms.prefs.cat1.checked=true;
		document.forms.prefs.cat2.checked=true;
		document.forms.prefs.cat5.checked=true;
		document.forms.prefs.cat10.checked=true;
		document.forms.prefs.cat20.checked=true;
		document.forms.prefs.cat0.disabled=true;
		document.forms.prefs.cat1.disabled=true;
		document.forms.prefs.cat2.disabled=true;
		document.forms.prefs.cat5.disabled=true;
		document.forms.prefs.cat10.disabled=true;
		document.forms.prefs.cat20.disabled=true;
	}
	else {
		document.forms.prefs.cat0.disabled=false;
		document.forms.prefs.cat1.disabled=false;
		document.forms.prefs.cat2.disabled=false;
		document.forms.prefs.cat5.disabled=false;
		document.forms.prefs.cat10.disabled=false;
		document.forms.prefs.cat20.disabled=false;
	}
}

function sendPrefs() {
		document.forms.prefs.cat0.disabled=false;
		document.forms.prefs.cat1.disabled=false;
		document.forms.prefs.cat2.disabled=false;
		document.forms.prefs.cat5.disabled=false;
		document.forms.prefs.cat10.disabled=false;
		document.forms.prefs.cat20.disabled=false;
		document.forms.prefs.submit();
}