var request = false;
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = false;
    }
  }
}

var req_status = 0; 



/*Fx.FadeHoverLink = Fx.Style.extend({
    initialize: function(el, options) {
		options.wait = false;
        this.parent(el, 'opacity', options);
        this.set(0.01);
        this.element.addEvent('mouseover', function() { this.custom(0.01,1); }.bind(this) );
        this.element.addEvent('mouseout', function() { this.custom(1,0.01); }.bind(this) );
    }
});

window.addEvent('domready', function() {
	//-- for IE6 but not IE7, Moz, Safari, Opera...
	if (typeof document.body.style.maxHeight == "undefined") {
		try {
		  document.execCommand('BackgroundImageCache', false, true);
		} catch(e) { }
	} // if

	$$('.bvFadeLink').each(
		function(el) {
			el.fl = new Fx.FadeHoverLink(el,{duration:500});
		}
	);
}); // addEvent..onload*/

// Universal Rollover Script
function imghighlight(whichimg) {
	var imgsrc = new String(whichimg.src);
	imgsrc = imgsrc.replace(new RegExp('_off\.','g'),'_on\.');
	whichimg.src = imgsrc;
}

function imgnohighlight(whichimg) {
	var imgsrc = new String(whichimg.src);
	imgsrc = imgsrc.replace(new RegExp('_on\.','g'),'_off\.');
	whichimg.src = imgsrc;
}


//SHOW/HIDE DIV
function hidediv(pass) {
	var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++){
		if(divs[i].id.match(pass)){//if they are 'see' divs
			if (document.getElementById) // DOM3 = IE5, NS6
				divs[i].style.display="none";// show/hide
			else
			if (document.layers) // Netscape 4
				document.layers[divs[i]].display = 'none';
			else // IE 4
				document.all.hideshow.divs[i].display = 'none';
			}
	}
}

function showdiv(pass) {
	var divs = document.getElementsByTagName('div');
		for(i=0;i<divs.length;i++){
			if(divs[i].id.match(pass)){
				if (document.getElementById)
					divs[i].style.display="block";
				else
				if (document.layers) // Netscape 4
					document.layers[divs[i]].display = 'block';
				else // IE 4
					document.all.hideshow.divs[i].display = 'block';
			}
	}
}

//Pop-up Functions
function popwin(loc,winname,w,h,scroll,resize) {
	eval('var newwin = window.open("' + loc + '","' + winname + '","width=' + w + ',height=' + h + ',top=100,left=200,location=no,scrollbars=' + scroll + ',menubar=no,toolbar=no,resizable=' + resize + '")');
}


function pulldownGoTo(thePulldown)
{

var theUrl = thePulldown.options[thePulldown.selectedIndex].value;

	if(theUrl != '@')
	{
		window.location = theUrl;
	}
	else
	{
	
	}
}

//create input
function create_input(type, name, id, value, parentID, chb){
	try{
		var input = document.getElementById(id);
		document.getElementById(parentID).removeChild(input);
	}catch(noelem){}

	if (chb.checked){
		var input = document.createElement('input');
		input.type = type;
		input.name = name;
		input.id = id;
		input.value = value;
		document.getElementById(parentID).appendChild(input);
	}
}
//create input

//check checkbox status
function check_chbs(){
	check_chbs_true('compare_prod_form');
}

function check_chbs_true(parentID){
	var inputs = document.getElementsByTagName("input"); 
	for (var i=0; i<inputs.length; i++){
		
		if (inputs[i].type == "checkbox"){
			var num = inputs[i].name.replace(/^chb(\d+)$/, "$1");
			create_input('hidden', 'ID[]', 'compare'+num, num, parentID, inputs[i]);
		}
	}
}
//check checkbox status


function send_data(url, funcname, post_data, req){
  	 req.open("POST", url, true);
	 req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	 req.onreadystatechange = funcname;
	 req.send(post_data);
}

function getresponse(req) {
     if (req.readyState == 4){
       if (req.status == 200){
			 return req.responseText;
		}else{
		   if (req.status == 404)
			 alert("Request URL does not exist");
		   else
			 alert("Error: status code is " + req.status);
		 }
	 }
	 return false;
}

function pre_change_img(path){	
	var num;
	var img = document.getElementById('ribak_img');
	var num_img = parseInt(img.getAttribute("num_img"));
	var cur_img = parseInt(img.getAttribute("cur_img"));
	num = getnum(num_img, cur_img);
	
	//alert(num_img+' '+cur_img);
	if (!req_status){
		send_data(path+"/response/change_img.php", change_img, 'num='+num, request);
		req_status = 1;
	}
}

function change_img(){
	var response = getresponse(request);
	if (response==false) return false;
	
	//alert(response);
	
	var img = document.getElementById('ribak_img');
	var num_img = parseInt(img.getAttribute("num_img"));
	var cur_img = parseInt(img.getAttribute("cur_img"));
	num = getnum(num_img, cur_img);
	img.setAttribute("cur_img", num);
	img.innerHTML = response;
	req_status = 0;
}

function getnum(num, cur){
	if (num > cur){
		return cur+1;
	}else{
		return 1;
	}
}



function search_forum(){
	if(document.search_form.search_radio[1].checked){
		document.sForm.keywords.value = document.search_form.q.value;
		document.sForm.submit();
		return false;
	}
	return true;
}

function newwin(width,height,img, title){
	var sizer;
	sizer=window.open('','','left='+(parseInt((screen.availWidth-width)/2)-3)+',top='+(parseInt((screen.availHeight-height)/2)-40)+',width='+width+',height='+height+',status=yes,toolbar=no,menubar=no,resizable=no'); 
	sizer.document.write('<html><head><title>'+title+'</title></head><body bgcolor=#ffffff rightmargin=0 bottommargin=0 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><img src="'+img+'" width="'+width+'" height="'+height+'" /></body></html>');
}
