function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("It's about time to upgrade you browser don't you think?");
	}
}

var getReq = getXmlHttpRequestObject();


function captcha_refresh() {
	if (getReq.readyState == 4 || getReq.readyState == 0) {
		var rand=Math.random();
		getReq.open("GET", '/update_captcha.php?'+rand, true);
		getReq.onreadystatechange = captcha_request;
		getReq.send(null);
	}
}



function captcha_request()
{
if (getReq.readyState == 4) {
		var ss = document.getElementById('captcha_img');
		ss.innerHTML = '';
		ss.innerHTML = getReq.responseText;
			}
}


function jsRate(value, id)
{
		document.getElementById(id).value=value;
		var echo_val=value*17;
		document.getElementById('rating_layer').innerHTML ='';
		document.getElementById('rating_layer').innerHTML ='<ul class="unit-rating"><li class="current-rating" style="width:'+echo_val+'px;">'+echo_val+'</li><li><a href="#" title="Bad" class="r1-unit"  onclick="jsRate(\'1\', \''+id+'\'); return false;">1</a></li><li><a href="#" title="Poor" class="r2-unit" onclick="jsRate(\'2\', \''+id+'\'); return false;">2</a></li><li><a href="#" title="Fair" class="r3-unit" onclick="jsRate(\'3\', \''+id+'\'); return false;">3</a></li><li><a href="#" title="Good" class="r4-unit" onclick="jsRate(\'4\', \''+id+'\'); return false;">4</a></li><li><a href="#" title="Excellent" class="r5-unit" onclick="jsRate(\'5\', \''+id+'\'); return false;">5</a></li></ul>';
}


function ajaxRate(value,number)
{
	if (getReq.readyState == 4 || getReq.readyState == 0) {
                var rand  = Math.random();
		getReq.open("GET", '/product_rate.php?number='+number+'&value='+value+'&rand='+rand, true);
		getReq.onreadystatechange = ajaxRate_request;
		getReq.send(null);
	}
}


function ajaxRate_request()
{
	if (getReq.readyState == 4) {
		var str = getReq.responseText;
		document.getElementById('rating_layer').innerHTML=str;
	}
}




function menu_show_hide(id,classid,show)
{
if (show==1)
	{
	document.getElementById(id).style.display='block';
	document.getElementById('parent-'+id).className=classid+'-a';
	}

else if (show==2)
	{
	document.getElementById(id).style.display='none';
	document.getElementById('parent-'+id).className=classid;
	}

else 
{
if (document.getElementById(id).style.display=='none')
	{
	document.getElementById(id).style.display='block';
	document.getElementById('parent-'+id).className=classid+'-a';
	}
else	{
	document.getElementById(id).style.display='none';
	document.getElementById('parent-'+id).className=classid;
	}
}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,field,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; field=args[i+1]; val=MM_findObj(args[i]);
    if (val) { 
	if (field!='') nm=field; else nm=val.name;
	if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function set_background(div, bg) {
	document.getElementById(div).innerHTML='<img src="'+bg+'" alt=""/>';
}


function check_box(box, product){
  if (document.getElementById('buy_box_checkbox').checked==true)  
	document.getElementById('buy_now_btn').innerHTML = '<a href="/buy.html?add='+product+'&box='+box+'" class="buynow-btn-b">&nbsp;</a>';
  else	
	document.getElementById('buy_now_btn').innerHTML = '<a href="/buy.html?add='+product+'" class="buynow-btn-b">&nbsp;</a>';
}


function url_display(page, height, width) 
{
 var win = window.open(page, page, 'height='+height+',width='+width+',toolbar=0,location=0');
}
