
function elem(id) {
 return (document.getElementById) ? document.getElementById(id) : eval("document.all['"+id+"']");
}

function exp_col(id) {
	
	var menu = elem("menu_wrap");
	var submenus = menu.getElementsByTagName("div");
	
	for (var i=0;i<submenus.length;i++) {
		if (submenus[i].id.substr(0,4)=="sub_") {
			if (submenus[i].id=="sub_"+id) {
				var new_state = (submenus[i].className=="menu_sub") ? "hidden" : "visible";
				var new_class = (new_state=="visible") ? "menu_sub" : "menu_sub_hidden";
				var new_url = (new_state=="visible") ? "minus" : "plus";
			
				submenus[i].className = new_class;
				elem("exps_"+id).src = "images/icon_"+new_url+".jpg";
			} else {
				submenus[i].className = "menu_sub_hidden";
				elem("exps_"+submenus[i].id.substr(4,submenus[i].id.length)).src = "images/icon_plus.jpg";
			}
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function sub_explain_compare_button(what,id){

	if(what == 1){
		document.getElementById('help_'+id).innerHTML = 'Add product to <br>`compare list`';
		document.getElementById('help_'+id).style.display = 'block';
	}else{
		document.getElementById('help_'+id).style.display = 'none';
	}

}

/////////////////////////////

function sub_add_product_to_compare_list(id,mode){

//	alert("GOT DATA id:"+id+' mode:'+mode);
	var uid = '';
	uid = document.getElementById('user_id').value;
//	uid = getCookie('user');
//	if(!uid){
//		var m = 1000;
//		var n = 9999999999;
//		uid = Math.floor(Math.random()*(n-m+1))+m;//'121212';
//		save_cooks('user',uid);
//	}
	var lang = document.getElementById('languages_id').value;
	if(lang == ''){ lang = 1;}
	var req = 'products_id='+id+'&user_id='+uid+'&language_id='+lang+'&rand='+Math.floor(Math.random()*(999-1+1))+1;
	if(mode){
		req += '&mode=full';	
	}
//	alert(req);
//	alert(uid);
	post_ajax_compare_request('','',req,id,mode);
//	alert('+');
}


///////////////////

function post_ajax_compare_request(self_id,response,request,id,mode){

//		alert("request start");
		var http;		
		var working = false;
    if(!http){
      http = get_http();
      working = false;
    }
    if (!working && http) {
//      var http = this.http;
      url  = '/compare_list_ajax.php?'+request;
//			alert(request);			
//			alert('Compare:'+url);			
      http.open('GET', url, true);
//			alert('opened');
      http.onreadystatechange = function() {
	//																								alert('sub function');
                                                  if (http.readyState == 4) {
//																										alert('reaqdystate = 4 ');
																										if(mode == 'full'){
		//																									alert('full');
																											document.getElementById('compare_list_full').innerHTML = http.responseText;
																										}else{
	//																										alert('response:'+http.responseText);																										
																											document.getElementById('compare_list').innerHTML = http.responseText;
																											document.getElementById('user_id').value=document.getElementById('new_uid').value;
																											//alert(document.getElementById('user_id').value);
																										}
                                                    working = false;
                                                  }else{
			//																							alert('waiting');
                                                    //loading_process();
                                                  }
                                                }
      //loading_process();
//			this.working = true;
      http.send(null);
    }
    if(!http){
      alert('error  XMLHTTP request !')
    }
		
}

//////////////////////////////

function get_http(){
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new
                ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
    @else
        xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

/////////////////////////////

function save_cooks(name,value){
  var myDate = new Date();
  setCookie(name,value,(myDate.getTime()*1+60*10));
}

/////////////////////////////

function setCookie(name, value, expires, path, domain, secure) {
        var curCookie = name + '=' + escape(value) +
                ((expires) ? '; expires=' + expires.toLocaleString() : '') +
                ((path) ? '; path=' + path : '') +
                ((domain) ? '; domain=' + domain : '') +
                ((secure) ? '; secure' : '')
        if ( (name + '=' + escape(value)).length <= 4000)
                document.cookie = curCookie
        else
                if (confirm('Cookie are more than 4Kb and will be ignored ! '))
                        document.cookie = curCookie
}

/////////////////////////////

function getCookie(name) {
        var prefix = name + '='
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(';', cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

/////////////////////////////

function deleteCookie(name, path, domain) {
        if (getCookie(name)) {
                document.cookie = name + '=' +
                ((path) ? '; path=' + path : '') +
                ((domain) ? '; domain=' + domain : '') +
                '; expires=Thu, 01-Jan-70 00:00:01 GMT'
        }
}






function toggledesc() {

	if (elem("desc_short").style.display=="none") {
		elem("desc_short").style.display = "";
		elem("desc_long").style.display = "none";
	} else {
		elem("desc_short").style.display = "none";
		elem("desc_long").style.display = "";
	}


}
