

function exp_col(id) {
	
	var menu_item = (document.getElementById) ? document.getElementById('sub_'+id) : eval("document.all['sub_'+id]");
	var plus_min_img = (document.getElementById) ? document.getElementById('exps_'+id) : eval("document.all['exps_'+id]");
	
	if (menu_item!=undefined && plus_min_img!=undefined) {
		
		var new_state = (menu_item.className=="menu_sub") ? "hidden" : "visible";
		
		var new_class = (new_state=="visible") ? "menu_sub" : "menu_sub_hidden";
		var new_url = (new_state=="visible") ? "minus" : "plus";
		
		menu_item.className = new_class;
		plus_min_img.src = "images/icon_"+new_url+".jpg";
		
	} else {
		return 0;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


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 = getCookie('user');

	if(!uid){
		var m = 1000;
		var n = 999999;
		uid = Math.floor(Math.random()*(n-m+1))+m;//'121212';
		save_cooks('user',uid);
	}

	document.getElementById('user_id2').value=uid;

	var lang = document.getElementById('languages_id').value;
	var req = 'products_id='+id+'&user_id='+uid+'&language_id='+lang;
	if(mode){
		req += '&mode=full';	
	}
	//alert(req);
	post_ajax_compare_request('','',req,id,mode);
}


///////////////////
//var working;
function post_ajax_compare_request(self_id,response,request,id,mode){
//	var http = false;
    var http;
    var working = false;
    if(!http){
      http = get_http();
      working = false;
    }

//    if(!this.http){
//      this.http = get_http();
//      this.working = false;
//    }
//	if(!http){
//		http = get_http();
//		working = false;
//	}
//    if (!this.working && this.http) {
	if (!working && http){
//      var http = this.http;
      url  = 'http://mtmalta.com/compare_list_ajax.php?'+request;
//alert(url);
//      this.http.open('GET', url, true);
			http.open('GET', url, true);
//alert('posted');
//      this.http.onreadystatechange = function() {
			http.onreadystatechange = function() {
                                                  if (http.readyState == 4) {
																										if(mode == 'full'){
//alert('full response'+ http.responseText);
																											document.getElementById('compare_list_full').innerHTML = http.responseText;
																										}else{
//alert(http.responseText);
																											document.getElementById('compare_list').innerHTML = http.responseText;
																										}
//                                                    this.working = false;
																										working = false;
                                                  }else{
                                                    //loading_process();
                                                  }
                                                }
      //loading_process();
//      this.http.send(null);
			http.send(null);	
    }
//    if(!this.http){
		if(!http){
      alert('error  XMLHTTP request !')
    }
		
}

function sub_del_from_compare_list(){

	var req = 'products='+document.getElementById('products').value+'&user_id='+document.getElementById('user_id2').value+'&action=cdelete&language_id='+document.getElementById('languages_id').value;

	var http;
	var working = false;
	if(!http){
		http = get_http();
		working = false;
	}
	
	if (!working && http){
		url  = 'http://mtmalta.com/compare_list_ajax.php?'+req;
		http.open('GET', url, true);
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
					document.getElementById('compare_list').innerHTML = http.responseText;
				working = false;
			}
		}
		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'
        }
}





