
function PrevNext() {
	alert('' + location.href + '');
	window.location.reload();
}

function change(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}


function AddCrit(obj, type){
	
	
	if (type=='category'){
		var cat = document.getElementById('CAT');
		if (cat !=null) {
			cat.innerHTML = obj.value;
			}
	}
	
	
	if(type=='brands'){
		var brand = document.getElementById('BRAND');
		if (brand !=null) {
			brand.innerHTML = obj.value;
			}
	}
	
	if(type=='manf'){
		var manf = document.getElementById('MANF');
		if (manf !=null) {
			manf.innerHTML = obj.value;
		}
	//	var manfx = document.getElementById('MANFX');
	//	manfx.innerHTML = '<img src="/images/yellowx.gif"';
	}
	
	if(type=='sort'){
		var order = document.getElementById('ORDER');
		if (order !=null) {
			order.innerHTML = obj.value;
		}
	}
	
// this sets the url querystring which sets param for query. 
	
	RunProducts();
}

// this sets the url querystring which sets param for query. 
function RunProducts(){
// set values
//	var urlString = "http://hobbygames.com.websitelive.net/products.asp?";	
	var brand = document.getElementById('BRAND');
	var cat = document.getElementById('CAT');
	var manf = document.getElementById('MANF');
	var order = document.getElementById('ORDER');
	var sort= document.getElementById('ORDER');
	
//set urlstring
// add order by to query string
	var currentURL = window.location;
//	alert( currentURL.hostname + ' ' + currentURL.pathname);
	var urlString="http://" + currentURL.hostname + currentURL.pathname + "?";
	
//get value of radio button 
	
	//make sure radio button exists
		
		for (var i=0; i < document.order.sort.length; i++)
		{
			if (document.order.sort[i].checked)
			{
				var rad_val = document.order.sort[i].value;
			urlString =urlString + 'SORT=' + rad_val;
			}
		}
	
//check to see what search criteria has been chosen
		if (cat.innerHTML!=''){
			urlString =urlString + '&CAT=' + cat.innerHTML;
		}
	
	if (brand.innerHTML!=''){
		if (cat.innerHTML!='') {
			urlString =urlString + '&BRAND=' + brand.innerHTML;
		}
		else{
			urlString =urlString + '&BRAND=' + brand.innerHTML;
		}
	}
		
	if (manf.innerHTML!=''){
		if (cat.innerHTML!='' || brand.innerHTML!='' ) {
			urlString =urlString + '&MANF=' + manf.innerHTML;
		}
		else{
			urlString =urlString + '&MANF=' + manf.innerHTML;
		}
	}	
	location.href= urlString;
}

function SetTable(){
//set values
//this function runs onLoad and is for setting the crtieria table
	var CatVar= getQuerystring('CAT');
	var BrandVar= getQuerystring('BRAND');
	var ManfVar= getQuerystring('MANF');
	
//	alert ('in there!' + CatVar + '');
	if (CatVar!='' && CatVar!=null) {
		var cat = document.getElementById('CAT');
		cat.innerHTML = unescape(CatVar);
		var catx = document.getElementById('CATX');
		catx.innerHTML = '<a href="#" border="0" name="cat" onclick="Clear(this); return false;"><img src="/images/yellowx.gif" border="0"></a>';
	}
	if (BrandVar!='' && BrandVar!=null) {
		var brand = document.getElementById('BRAND');
		brand.innerHTML = unescape(BrandVar);
		var brandx = document.getElementById('BRANDX');
		brandx.innerHTML = '<a href="#" border="0" name="brand" onclick="Clear(this); return false;"><img src="/images/yellowx.gif" border="0"></a>';
	
	}
	if (ManfVar!='' && ManfVar!=null) {
		var manf = document.getElementById('MANF');
		manf.innerHTML = unescape(ManfVar);
		var manfx = document.getElementById('MANFX');
		manfx.innerHTML = '<a href="#" border="0" name="manf" onclick="Clear(this); return false;"><img src="/images/yellowx.gif" border="0"></a>';
	}
}



function Clear(obj){

	
	if (obj.name=='manf') {
		var manf = document.getElementById('MANF');
		manf.innerHTML='';
		RunProducts();
	}
	
	if (obj.name=='brand') {
		var brand = document.getElementById('BRAND');
		brand.innerHTML='';
		RunProducts();
	}

	if (obj.name=='cat') {
		var cat = document.getElementById('CAT');
		cat.innerHTML='';
		RunProducts();
	}
}


function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return null;
  else
    return qs[1];
}

function getObj(idvalue) {
        if (document.getElementById) this.style = document.getElementById(idvalue).style;
        else if (document.layers) this.style = document.layers[idvalue];
    }

function show(num) {
        var sub = 'menu' + num;
        menu = new getObj(sub);
        if (menu.style.display == 'block') menu.style.display = 'none';
        else menu.style.display = 'block';
}


var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes";win=window.open(mypage,myname,settings);
win.focus();}

function Login_Validator(theForm)
{

  var chkVal = theForm.Terms.checked;
  var prsVal = chkVal;
  if (chkVal != true)
  {
    alert("Please Accept the Terms and Conditions To Use This Site");
    theForm.Terms.focus();
    return (false);
  }
  return (true);
}

function TheFormCheck2() {
if (document.reviewform.rating.value=="") 
{
alert("Please enter your rating for this product.");
document.reviewform.rating.focus();return false
}
if (document.reviewform.title.value=="") 
{
alert("Please enter the title for this review.");
document.reviewform.title.focus();return false
}
if (document.reviewform.review.value=="") 
{
alert("Please enter your review.");
document.reviewform.review.focus();return false
}
} 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function TheFormCheck() {
if (document.form1.email.value=="") 
{
alert("email is required");
document.form1.email.focus();return false
}

if (document.form1.email.value!="") 
{if (document.form1.email.value.indexOf("@")==-1 || document.form1.email.value.indexOf(".")==-1 || document.form1.email.value.indexOf(" ")!=-1 || document.form1.email.value.length<6) 
{alert("Sorry, your email address is not valid.");
document.form1.email.focus();return false}
}
} 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
