function openAWindow( pageToLoad, winName, width, height, center){

	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) &&(center)){
		xposition = (screen.width - width) / 8;
		yposition = (screen.height - height) / 3;
	}

	args = "width=" + width + ","
		+ "height=" + height + ","
		+ "location=0,"
		+ "menubar=0,"
		+ "resizable=0,"
		+ "scrollbars=0,"
		+ "status=0,"
		+ "titlebar=0,"
		+ "toolbar=0,"
		+ "hotkeys=0,"
		+ "screenx=" + xposition + "," //NN Only
		+ "screeny=" + yposition + "," //NN Only
		+ "left=" + xposition + "," //IE Only
		+ "top=" + yposition; //IE Only

	window.open( pageToLoad, winName, args );

}



function openAWindow2( pageToLoad, winName, width, height, center){

	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) &&(center)){
		xposition = (screen.width - width) / 8;
		yposition = (screen.height - height) / 3;
	}

	args = "width=" + width + ","
		+ "height=" + height + ","
		+ "location=0,"
		+ "menubar=0,"
		+ "resizable=0,"
		+ "scrollbars=1,"
		+ "status=0,"
		+ "titlebar=0,"
		+ "toolbar=0,"
		+ "hotkeys=0,"
		+ "screenx=" + xposition + "," //NN Only
		+ "screeny=" + yposition + "," //NN Only
		+ "left=" + xposition + "," //IE Only
		+ "top=" + yposition; //IE Only

	window.open( pageToLoad, winName, args );

}

function f_clientWidth() {
	return f_filterResults (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
			);
}
function f_clientHeight() {
	return f_filterResults (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
			);
}
function f_scrollLeft() {
	return f_filterResults (
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0
			);
}
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 getObject( obj ) {
	if ( document.getElementById ) {
		// step 1
		obj = document.getElementById( obj );

	} else if ( document.all ) {
		// step 2
		obj = document.all.item( obj );

	} else {
		//step 3
		obj = null;
	}

	//step 4
	return obj;
}
function displayObject( obj, show ) {

	// step 1
	obj = getObject( obj );
	if (obj==null) return;

	// step 2
	obj.style.display = show ? 'block' : 'none';
	obj.style.visibility = show ? 'visible' : 'hidden';
}
function winSize(w) {
	// This may break in future browser versions.
	// http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(w==1){return myWidth;}else{return myHeight;}
}

function moveObject(O,e) {
	var o=5;
	var OHolder=O;
	O=getObject(O);
	if (O==null) return;
	displayObject(OHolder,true);
	if((e.clientY+O.offsetHeight+o)>winSize(0)){
		O.style.top=(e.clientY-O.offsetHeight-o)+'px';
	}else{
		O.style.top=(e.clientY+o)+'px';
	}
	if((e.clientX+O.offsetWidth+o)>winSize(1)){
		O.style.left=(e.clientX-O.offsetWidth-o)+'px';
		//alert(e.clientX+O.offsetWidth);
	}else{
		O.style.left=(e.clientX+o)+'px';
	}
	// alert("clientY: "+e.clientY+" Height: "+O.offsetHeight+"\nTotal: "+(e.clientY+O.offsetHeight+o)+"   WinSize: "+winSize(0));

}

function midScreen(obj){
	Obj=getObject(obj);


}
function definesize(param) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else {
		if( document.documentElement &&
				( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	}

	if(param==1){  return myWidth;}
	else{return myHeight;}
}



function lightboxon(fl,width,height,event,rt)
{
	dd=getObject("lightbox")
		dd.style.width=width+2
		dd.style.width=height+2
		dd.innerHTML="<table border='0' cellpadding='0' cellspacing='1' bgcolor='#000000' width='"+(width+2)+"'  height="+(height+2)+"><tr><td bgcolor='#FFFFFF' style='background-image: url("+rt+"/images/loading.gif); background-repeat: no-repeat;'><img src='"+fl+"' width='"+width+"' height='"+height+"'><"+"/td><"+"/tr><"+"/table>"
		displayObject("lightbox",true);

	//alert(document.body.scrollTop)

	if(definesize(1)-event.clientX-10-width>0)
	{
		dd.style.left=event.clientX+10;
	}
	else
	{
		dd.style.left=event.clientX-10-width;
	}

	if(definesize(2)-event.clientY-10-height>0)
	{
		dd.style.top=event.clientY+document.body.scrollTop+10;
	}
	else
	{
		dd.style.top=event.clientY+document.body.scrollTop-10-height;
	}



}








function lightboxon2(fl,width,height,event,rt)
{
	dd=getObject("lightbox")
		dd.style.width=width+2
		dd.style.width=height+2
		dd.innerHTML="<table border='0' cellpadding='0' cellspacing='1' bgcolor='#000000' width='"+(width+2)+"'  height="+(height+2)+"><tr><td bgcolor='#FFFFFF' style='background-image: url("+rt+"/images/loading.gif); background-repeat: no-repeat;'><OBJECT ID='MediaPlayer' WIDTH='"+width+"' HEIGHT='"+height+"' CLASSID='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' STANDBY='Loading Windows Media Player components...' TYPE='application/x-oleobject'><PARAM NAME='FileName' VALUE='"+fl+"'><PARAM name='ShowControls' VALUE='false'><param name='ShowStatusBar' value='false'><PARAM name='ShowDisplay' VALUE='false'><PARAM name='autostart' VALUE='true'><EMBED TYPE='application/x-mplayer2' SRC='"+fl+"' NAME='MediaPlayer' WIDTH='"+width+"' HEIGHT='"+height+"' ShowControls='0' ShowStatusBar='0' ShowDisplay='0' autostart='1'><"+"/EMBED><"+"/OBJECT><"+"/td><"+"/tr><"+"/table>"
		displayObject("lightbox",true);



	if(definesize(1)-event.clientX-10-width>0)
	{
		dd.style.left=event.clientX+10;
	}
	else
	{
		dd.style.left=event.clientX-10-width;
	}

	if(definesize(2)-event.clientY-10-height>0)
	{
		dd.style.top=event.clientY+document.body.scrollTop+10;
	}
	else
	{
		dd.style.top=event.clientY+document.body.scrollTop-10-height;
	}



}





function lightboxon3(fl,width,height,event,rt)
{
	dd=getObject("lightbox")
		dd.style.width=width+2
		dd.style.width=height+2
		dd.innerHTML="<table border='0' cellpadding='0' cellspacing='1' bgcolor='#000000' width='"+(width+2)+"'  height="+(height+2)+"><tr><td bgcolor='#FFFFFF' style='background-image: url("+rt+"/images/loading.gif); background-repeat: no-repeat;'><object classid='CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000'  style='width:"+width+"px;height:"+height+"px;' codebase='http://active.macromedia.com/flash2/cabs/swflash.cab#version=8,0,0,0'><param name='movie' value='"+rt+"/images/movie.swf?url="+fl+"&autoplay=true&loop=true&controlbar=false&sound=true&swfborder=true'><param name='quality' value='high'><param name='scale' value='fit'><param name='menu' value='true'><param name='bgcolor' value='#FFFFFF'><param name='video_url' value=' '><embed src='"+rt+"/images/movie.swf?url="+fl+"&autoplay=true&loop=true&controlbar=false&sound=true&swfborder=true' quality='high' scale='fit' menu='false' bgcolor='#FFFFFF' style='width:"+width+"px;height:"+height+"px;' swLiveConnect='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'><"+"/embed><"+"/object><"+"/td><"+"/tr><"+"/table>"
		displayObject("lightbox",true);



	if(definesize(1)-event.clientX-10-width>0)
	{
		dd.style.left=event.clientX+10;
	}
	else
	{
		dd.style.left=event.clientX-10-width;
	}

	if(definesize(2)-event.clientY-10-height>0)
	{
		dd.style.top=event.clientY+document.body.scrollTop+10;
	}
	else
	{
		dd.style.top=event.clientY+document.body.scrollTop-10-height;
	}



}

// For SWF. 21May2009 --MJL
// Title support. 22Oct2009 --MJL
// Better (more IE-friendly) title support. 27Oct2009 --MJL
function lightboxon4(fl,width,height,event,rt,tt)
{
	dd=getObject("lightbox");
	dd.style.width=width+2;
	dd.style.width=height+2;
	dd.innerHTML="<div id='lightboxtitle'>"+tt+"<"+"/div><table cellspacing='0' cellpadding='0' bgcolor='#FFFFFF' style='border-style:groove;border-width:2px;border-color:#333' width='"+(width+2)+"' height="+(height+2)+"><tr><td bgcolor='#FFFFFF' style='width:"+width+"px;height:"+height+"px;background-image:url("+rt+"/images/loading.gif); background-repeat: no-repeat;'><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' style='width:"+width+"px;height:"+height+"px;' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'><param name='movie' value='"+fl+"'"+"><param name='quality' value='high'><param name='scale' value='fit'"+"><param name='bgcolor' value='#333333'"+"><embed src='"+fl+"' quality='high' scale='fit' bgcolor='#333333' style='width:"+width+"px;height:"+height+"px;' swLiveConnect='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'><"+"/embed><"+"/object><"+"/td><"+"/tr><"+"/table>";
	displayObject("lightbox",true);
	moveObject("lightbox",event);
}


function lightboxmove(width,height,event)
{
	moveObject("lightbox",event);
}

function AFbc(boxname) { // boxclose
	dd=getObject(boxname);
	dd.innerHTML='';
	displayObject(boxname,false);
}

function lightboxoff(){AFbc("lightbox");}
function infoboxoff(){AFbc("infobox");}

function pD(q){return unescape(q.replace(/\+/gi,'%20'));}
function rM(rq){RvE=/R\d{1,5}v/;if(RvE.exec(rq)){return true;}else{return false;}}
function rG(rq){var rGr=":&nbsp;";rq=rq.substring(1,6);for(i=0;i<5;i++){rGr+="<img src='"+tR+"images/vote"+rq.substring(i,i+1)+".gif' width='8' height='8' border='0'>";}return rGr;}
function infoboxon(event,tt,l1l,l1r,l2l,l2r,l3l,l3r,l4l,l4r,l5l,l5r)
{
	ddH="<div id='infoboxtitle'>"+tt+"<img class='rC' src='"+sR+"/images/icons/window-close.png' onclick='infoboxoff();'><"+"/div><div id='infoboxmain'><p>";
	if(l1l){ddH+=l1l;
		if(l1r){if(rM(l1r)){ddH+=rG(l1r);}else{ddH+=":&nbsp;"+pD(l1r);}}
		ddH+="<br>";
	}
	if(l2l){ddH+=l2l;
		if(l2r){if(rM(l2r)){ddH+=rG(l2r);}else{ddH+=":&nbsp;"+pD(l2r);}}
		ddH+="<br>";
	}
	if(l3l){ddH+=l3l;
		if(l3r){if(rM(l3r)){ddH+=rG(l3r);}else{ddH+=":&nbsp;"+pD(l3r);}}
		ddH+="<br>";
	}
	if(l4l){ddH+=l4l;
		if(l4r){if(rM(l4r)){ddH+=rG(l4r);}else{ddH+=":&nbsp;"+pD(l4r);}}
		ddH+="<br>";
	}
	if(l5l){ddH+=l5l;
		if(l5r){if(rM(l5r)){ddH+=rG(l5r);}else{ddH+=":&nbsp;"+pD(l5r);}}
		ddH+="<br>";
	}
	ddH+="<"+"/p><"+"/div><"+"/td><"+"/tr><"+"/table>";
	dd=getObject("infobox");
	dd.innerHTML=ddH;
	moveObject('infobox', event);
}

function add_cart(value,itemname,itemdesc) {
	var req = new JsHttpRequest();
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			getObject('shopping_cart').innerHTML=req.responseText;
			dd=getObject("items_added");
			if (itemname) {dd.innerHTML=itemname+" ";}
			else {dd.innerHTML="The item ";}
			if (itemdesc) { dd.innerHTML="("+itemdesc+")<br>"; }
			dd.innerHTML+="has been added to the cart.";
			dd.style.position="fixed";
			dd.style.left=f_clientWidth()-(dd.offsetWidth*2)+"px";
			dd.style.top=f_clientHeight()-(dd.offsetHeight*2)+"px";
			displayObject("items_added",true);
			hid = setTimeout("AFbc('items_added');",3210);
		}
	}
	req.open(null, sR+'/members/shopping_cart_add.php', true);
	req.send( {id: value } );
}
function items_add_hide(){AFbc("items_added");}

function AFcp(sid,itemname){ // cart processor
	ddT='<div id="buyboxtitle">Add To Cart<img class="rC" src="'+sR+'/images/icons/window-close.png" onclick="AFbc(\'buybox\');"><'+'/div><div id="buyboxmain" style="text-align:center">';
	ddI='<img src="'+sR+'/images/loading.gif"><p>Loading options';
	if (itemname) { ddI+=' for '+itemname; }
	ddI+='...<br>Please wait...<'+'/p>';
	ddB='<'+'/div>';
	dd=getObject("buybox");
	dd.innerHTML=ddT+ddI+ddB;
	displayObject("buybox",true);
	dd.style.left="50%";
	dd.style.top="15%";

	JsHttpRequest.query(
			sR+'/members/shopping_cart_get.php',
			{
			'id': sid,
			'name': itemname
			},
			function(result, errors) {
			getObject("debug").innerHTML = errors; 
			if (errors) {alert(errors);}
			if (result) {dd.innerHTML = ddT+result["itemlist"]+ddB;}
			},
			false
			);

}

function reviews_show(value) {
	var req = new JsHttpRequest();
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('reviewscontent').innerHTML =req.responseText;
		}
	}
	req.open(null, sR+'/members/reviews_content.php', true);
	req.send( { id: value } );
}


function reviews_add(value) {
	var req = new JsHttpRequest();
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('reviewscontent').innerHTML =req.responseText;

		}
	}
	req.open(null, sR+'/members/reviews_content.php', true);
	req.send( {'form': document.getElementById(value) } );
}


function reviews_hide() {
	document.getElementById('reviewscontent').innerHTML ="";
}



function tell_show(value) {
	var req = new JsHttpRequest();
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('reviewscontent').innerHTML =req.responseText;
		}
	}
	req.open(null, sR+'/members/tell_a_friend.php', true);
	req.send( { id: value } );
}


function tell_add(value) {
	var req = new JsHttpRequest();
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById('reviewscontent').innerHTML =req.responseText;

		}
	}
	req.open(null, sR+'/members/tell_a_friend.php', true);
	req.send( {'form': document.getElementById(value) } );
}


function update_favorite(v,s){
	if(s=='add'){S='off';t='Add to ';}else{S='on';t='Delete from ';}
	o=getObject(v);if(o){o.innerHTML='<a href="javascript:'+s+'_favorite('+v+')" title="'+t+'Lightbox"><img style="border:0" src="'+sR+'/images/icons/lightbox-'+S+'.png" alt="Lightbox" title="'+t+'Lightbox"></a>';}
	O=getObject('b'+v);if(O){O.innerHTML='<a href="javascript:'+s+'_favorite('+v+');" class="nodec"><button class="actionbutton" onclick="javascript:'+s+'_favorite('+v+');">'+t+'Lightbox</button></a>';}
}

function add_favorite(value) {
	var req = new JsHttpRequest();
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			try{
				update_favorite(value,'delete');
				document.getElementById('favorite').innerHTML =req.responseText;
			}catch(e){}
		}
	}
	req.open(null, sR+'/members/favorite_add.php', true);
	req.send( { id: value } );
}


function delete_favorite(value) {
	var req = new JsHttpRequest();
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			try{
				update_favorite(value,'add');
				document.getElementById('favorite').innerHTML =req.responseText;
			}catch(e){}
		}
	}
	req.open(null, sR+'/members/favorite_delete.php', true);
	req.send( { id: value } );
}


