// JavaScript Document
function zoomImage(){var src='',img=new Image();openLightbox('<div style="display: block; width: 500px; line-height: 300px; height: 300px; text-align: center;"><img src="/images/loading.gif"></div>','');
img.onload=function(){var vw=img.width+32,vh=img.height+16,of='',ws=winSize();
if(img.width>(ws[0]*0.9)){vw=(ws[0]*0.9);of=' overflow: scroll';}
if(img.height>(ws[1]*0.85)){vh=(ws[1]*0.85);of=' overflow: scroll';}
refreshLightbox('<div style="display: block; text-align: center; width: '+vw+'px; height: '+vh+'px;'+of+'"><img src="'+img.src+'" style="cursor: pointer;" onClick="closeLightbox()"></div>');}
if($('medimage').getAttribute('toggle')==1){img.src=$('medimage').getAttribute('largeversion1');}else{img.src=$('medimage').getAttribute('largeversion2');}}

function flipImage(){var img=$('medimage');if(img.getAttribute('toggle')==1){img.setAttribute('toggle',2);img.src=img.getAttribute('normalimage2');}else{img.setAttribute('toggle',1);img.src=img.getAttribute('normalimage1');img.style.cursor='url(/images/zoomin.cur), pointer';$('zoomtext').style.display='block';}}
function buyNow(id){openLightbox(ajax.gets('/buynow.php?id='+$('itemview').getAttribute('sellerid')+'&item='+$('itemview').getAttribute('itemid')),'Buy Now Options');}
function makeOffer(){var t=$('theme').value;openLightbox(ajax.gets('/templates/'+t+'/makeofferwin.html'), 'Make Offer');}
function doOffer(){var n=$('mo_name').value,e=$('mo_email').value,p=$('mo_phone').value,a=$('mo_amount').value,i=$('itemview').getAttribute('itemid');if(n.length<1){$('mo_name').focus();$('mo_name').select();return;}if(e.length<1){$('mo_email').focus();$('mo_email').select();return;}if(p.length<1){$('mo_phone').focus();$('mo_phone').select();return;}if(a.length<1){$('mo_amount').focus();$('mo_amount').select();return;}ajax.get('/offers.php?item='+i+'&name='+n+'&email='+escape(e)+'&phone='+p+'&amount='+a,function(e){offerDone(e);});}
function offerDone(e){if(e.length<5){refreshLightbox('<div style="padding: 10px 30px; text-align: center;">Your offer has been submitted through Chris Porter Sports Collectibles.<br><br>A copy has been emailed to you, and you will be contacted shortly with an acceptance or a counter-offer.<br><br>Thank you for your offer.<br><br><br><input type="button" value="Close" onClick="closeLightbox()"></div>');}}
function showLogin(){var t=$('theme').value;openLightbox(ajax.gets('/templates/'+t+'/loginwin.html'), 'Account Login');}
function handleLogin(){var u=$('lo_user').value,p=$('lo_pass').value;if(ajax.gets('/checklogin.php?u='+u+'&p='+p)=='VALID'){gotoUrl('/seller/index.php');}else{refreshLightbox('<div style="display: block; width: 320px; margin: 20px 10px; font-size: 13px; color: red; text-align: center;">Invalid login.<br><input type="button" value="Close" style="margin-top: 30px; width: 90px;" onClick="closeLightbox()"></div>');}}
function showLogout(){var t=$('theme').value;openLightbox(ajax.gets('/templates/'+t+'/logoutwin.html'), 'Account Logout');}
function completeLogout(){var r=ajax.gets('/checklogin.php?k=1');setTimeout("gotoUrl('/')", 250);}

function searchKey(e){var k;if(window.event){k=e.keyCode;}else if(e.which){k=e.which;}if(k==13){doSearch();return 0;}return 13;}
function doSearch(){
var q=$('searchq').value;
if(q.length>1)gotoUrl('/search/'+q+'/');	
}
function doAdvSearch(){
var q=$('searchq2').value,t=$('searchtype').value;
if(q.length>1)gotoUrl('/search/'+t+'/'+q+'/');}
function refreshList(){
	var cat=$('categoryheader').getAttribute('catid'),s=$('sortby').value;
	gotoUrl('/category/'+cat+'/'+s+'/');
}
