function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var sizeCount = 0;
var sizePref = 0;

var textSize= new Array(1, 1.1, 1.3, 1.5)
	function textSizePref()
	{
		var textSizePref = GetCookies('ts_ygrec');
		if(textSizePref > 0)
		{
			enlargeText(textSizePref)
		}
	}

	function reduceText()
	{
		if(sizeCount != 0)
		{
			sizeCount = parseInt(sizeCount);
		}
		
		sizeCount = sizeCount-1;
		if(sizeCount <= 0)
		{
			sizeCount = 0;
		}
		
		document.getElementById("contentArea").style.fontSize = textSize[sizeCount]+"em";
		SetCookie('ts_ygrec', sizeCount);
		window.status = sizeCount;
	}
	
	function enlargeText(tSize)
	{
		if(sizeCount != 0)
		{
			sizeCount = parseInt(sizeCount);
		}
		
		var textOptLength = textSize.length-1;
		
		if(tSize != null) {
			sizeCount = tSize;
		} else {
			sizeCount = sizeCount+1;
		}
		
		if(sizeCount >= textOptLength)
		{
			sizeCount = textOptLength;
		}
		
		document.getElementById("contentArea").style.fontSize = textSize[sizeCount]+"em";
		SetCookie('ts_ygrec', sizeCount);
	}
	
function GetCookies (name) 
{  
    var arg = name + "=";  
    var i = 0;  
    while (i < document.cookie.length) 
    {
        var j = i + arg.length;    
        if (document.cookie.substring(i, j) == arg)      
        {
            return getCookieVal (j);    
        }
        i = document.cookie.indexOf(" ", i) + 1;    
        if (i == 0) break;   
    }  
    return null;
}

function SetCookie(name, value) 
{  
    var argv = SetCookie.arguments;  
    var argc = SetCookie.arguments.length;  
    var expires = (argc > 2) ? argv[2] : null;  
    var path = (argc > 3) ? argv[3] : null;  
    var domain = (argc > 4) ? argv[4] : null;  
    var secure = (argc > 5) ? argv[5] : false;  
    document.cookie = name + "=" + escape (value) + 
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
        ((path == null) ? "" : ("; path=" + path)) +  
        ((domain == null) ? "" : ("; domain=" + domain)) +    
        ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    {
        endstr = document.cookie.length;
    }
    
    return unescape(document.cookie.substring(offset, endstr));
}
function popup_open(filenev,X,Y,wondow_name){
	windowprops = "top="+(screen.height-60-Y)/2+",left="+(screen.width-10-X)/2+",status=no,scrollbars=yes,directories=no,location=no,toolbar=no,resizable=yes,menubar=no,width="+X+",height="+Y;
	window.open(filenev+'&maxx='+X+'&maxy='+Y,wondow_name,windowprops);
}

function openWin(file,w,h){
	if (!w) w = 450;
	if (!h) h = 300;
	winStatus = true;
	win = window.open(file,'help','toolbar=no,location=no,directories=no,status=no,'+
								   'menubar=no,resizable=yes,copyhistory=no,scrollbars'+
								   '=yes,width='+w+',height='+h);
	win.creator = self;
	win.focus();
}


function hideSearchDiv(div_id){
	timer[div_id] = setTimeout ("hide('" + div_id + "')", 550);
}

var timer = new Object();

function showSearchDiv(div_id){
	d = document.getElementById(div_id);
	d.style.visibility='visible';
	clearTimeout(timer[div_id]);
}

function divS(d_id){
	d = document.getElementById(d_id);
	d.style.display='block';
}

function divH(d_id){
	d = document.getElementById(d_id);
	d.style.display='none';
}


function hide(div_id){
	document.getElementById(div_id).style.visibility = "hidden";
}


function offsetLeft(o){
    var i = 0;
    while (o.offsetParent!=null) {
        i += o.offsetLeft;
        o = o.offsetParent;
    }
    return i + o.offsetLeft;
}
function offsetTop(o){
    var i = 0;
    while (o.offsetParent!=null) {
        i += o.offsetTop;
        o = o.offsetParent;
    }
    return i + o.offsetTop;
}

function gs(formname,page,action){
	mform = document.forms[formname];
	if(page) mform['page'].value=page;
	if(action) mform['action'].value=action;
	mform.submit();
}



function yes_click(){
	
}

function CreateBookmarkLink(title,url){
//	title = "Ygrec - Pagini Utile";
//	url = "http://ygrec.ro";
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
	}else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

function radio_check(obj){
	/*
	common_str = obj.name.substring(0,obj.name.lastIndexOf('['));
	var x = document.getElementsByTagName("input");
	for (i=0;x && i < x.length; i++){
		if(x[i].name.substring(0,x[i].name.lastIndexOf('['))==common_str){
			x[i].checked=false;
		}
	}
	obj.checked=true;
	*/
	var x = document.getElementsByTagName("input");
	for (i=0;x && i < x.length; i++){
		if(x[i].name==obj.name && obj.form.name==x[i].form.name){
			x[i].checked=false;
		}
	}
	obj.checked=true;

}

function oferta_get_checked_db(action,sel_color){
	var x = document.getElementsByTagName("input");
	var count=0;
	for (i=0;x && i < x.length; i++){
		switch(action){
			case 'count':
				if(x[i].name.substring(0,2)=='o['){
					if(x[i].checked){
						count++;
						document.getElementById('tr_'+x[i].id).style.backgroundColor=sel_color;
					}else{
						document.getElementById('tr_'+x[i].id).style.backgroundColor=bgcolor='';
					}
				}
			break;
			case 'disable':
				if(x[i].name.substring(0,2)=='o[' && !x[i].checked) x[i].disabled=1;
				break;
			case 'enable':
				if(x[i].name.substring(0,2)=='o[' && !x[i].checked) x[i].disabled=0;
				break;
		}
	}
	return count;
}

function oferta_count_firm(sel_color){
	d = document.getElementById('oferta_count_firm');
	x=oferta_get_checked_db('count',sel_color);
	if (x>=30){
		oferta_get_checked_db('disable');
	}else{
		oferta_get_checked_db('enable');
	}
	d.innerHTML='Firme selectate: <b>'+x+'</b> buc';
}

function checkEvaluareNU(){
	mf = document.forms.mainform;
	var chk_field = mf["fb[no_optiuni]"];
	
	ok_radio=-1;
	for(i=0;i<chk_field.length;i++){
		if(chk_field[i].checked) ok_radio=chk_field[i].value;
	}
	
	if(ok_radio==-1 || (ok_radio==5 && mf["fb[no_optiuni_altele]"].value=='')){
		alert("Te rog Selecteaza una dintre optiunile");
		return false;
	}
	return true;
}

function searchSubmit(form,lang,url){
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}

	catch(e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				return true;
			}
		}
	}

	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			location.href=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET","/ajax/urlencode.php?page=start&action=search&lang="+lang+"&cecine="+encodeURIComponent(encodeURIComponent(form.cecine.value))+"&numefirma="+encodeURIComponent(encodeURIComponent(form.numefirma.value))+"&unde="+encodeURIComponent(encodeURIComponent(form.unde.value)),true);
	xmlHttp.send(null);
	return false;
}

