nav = navigator.appName.indexOf("Microsoft")!= -1 ? 1 : 2;

function popup(url, name, width, height, scroll, modal, resizable) {
	width=Math.min(screen.availWidth,width);
	height=Math.min(screen.availHeight-40,height);
	var poz_x=(screen.availWidth-width)/2;
	var poz_y=(screen.availHeight-height-30)/2;
	newwin=window.open(url, name, 'scrollbars='+scroll+', menubar=no, width='+width+', height='+height+', resizable=no,toolbar=no, left='+poz_x+', top='+poz_y+', location=no, status=no');
	if(modal){
		popInt=setInterval(function(n){
			if(typeof(newwin.name)=="string"){
				if(newwin.document.body){
					openerfocus=function(){
						if(typeof(newwin.name)=="string"){
							newwin.focus();
						}else{
							document.body.onfocus=null;
						}
					}
					document.body.onfocus=openerfocus;
					newwin.window.document.body.onunload=function(){alert(66)}
					newwin.focus();
					/*with(newwin){
						self.focus()
						opener.document.body.onfocus=function(){self.focus();opener.alert(4);}
						self.document.body.onunload=function(){opener.document.body.onfocus=null}
					}*/
					clearInterval(popInt);
				}
			}else{
				clearInterval(popInt)
			}
		},1)
	}
}

function ajax_lista_comparator(elementdeschimbat,cod_produs,resetComparator,scoateProdus){
	var ajaxRequest;
	var queryString="";
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(document.getElementById("ajax_feed_verify")){
				document.getElementById("ajax_feed_verify").value = ajaxRequest.responseText;
			}
			if(document.getElementById(elementdeschimbat)){
				document.getElementById(elementdeschimbat).innerHTML=ajaxRequest.responseText;
				if(strpos(ajaxRequest.responseText,'<!-- estedeja -->')){
					if(document.getElementById('comparatoreroare2')){
						document.getElementById('comparatoreroare1').style.display='none';
						document.getElementById('comparatoreroare2').style.display='';
						window.setTimeout('flashMesaj(\"comparatoreroare2\")',3000);
					}
				}else if(strpos(ajaxRequest.responseText,'<!-- nepotrivire -->')){
					document.getElementById('comparatoreroare1').style.display='';
					document.getElementById('comparatoreroare2').style.display='none';
					window.setTimeout('flashMesaj(\"comparatoreroare1\")',3000);
				}else{
					document.getElementById('comparatoreroare1').style.display='none';
					document.getElementById('comparatoreroare2').style.display='none';
					if(scoateProdus!=1&&cod_produs&&document.getElementById('boxbutonComparare'+cod_produs)){
//						document.getElementById('boxbutonComparare'+cod_produs).style.display='none';
					}
				}
			}
		}
	}
	if(elementdeschimbat){
		var queryString=queryString + "&elementdeschimbat=" + elementdeschimbat;
	}
	if(cod_produs){
		var queryString=queryString + "&cod_produs=" + cod_produs;
	}
	if(resetComparator){
		var queryString=queryString + "&resetComparator=" + resetComparator;
	}
	if(scoateProdus){
		var queryString=queryString + "&scoateProdus=" + scoateProdus;
	}
	ajaxRequest.open("GET", "util/ajax_lista_comparator.php?" + queryString, true);
	ajaxRequest.send(null);
}

function flashMesaj(idElement){
	document.getElementById(idElement).style.display='none';
}

function strpos (haystack, needle, offset) {
    // Finds position of first occurrence of a string within another  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/strpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack + '').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}
