var contor=5;
var timp;

function create_popup_form_produs() {
	var container = document.createElement('div');
	container.innerHTML = '<form name="fprodus" id="fprodus" method="post" onSubmit="return false;"</form>';
}

function functie() {
	document.getElementById('afisare').value=contor;
	if (contor == 0) { parent.location.href="index.php?page=acchome" }
	contor=contor-1
	timp=setTimeout("functie()",1000)
}

function clear_span(form_id) {
	var span = document.getElementsByTagName('span');
	var input = document.forms[form_id];
	for (var i = 0, n = span.length; i < n; ++i) {
		span[i].innerHTML = "";
	}
	
	for (var i = 0, n = input.length; i < n; ++i) {
		input[i].style.backgroundColor = 'transparent';
	}

	return 0;
}

function returnSearchValues(fields, values) {
	for(var i=0;i<fields.length;i++) {
		if(document.getElementById(fields[i]))
		{
			document.getElementById(fields[i]).value = values[i];
		}
	}
}

function returnSearchValuesProdus(fields, values) {
	for(var i=0;i<fields.length;i++)
	{
		if(document.getElementById(fields[i]))
		{
			document.getElementById(fields[i]).value = values[i];
		}
	}
}

function checkAll(t) {
	var theForm = document.form1;
    for (i=0; i<theForm.elements.length; i++) {
        if (theForm.elements[i].name == 'mes[]'){
            theForm.elements[i].checked = t.checked;
		}
	}
};
function checkAllSend(t) {
	var theForm = document.form2;
    for (i=0; i<theForm.elements.length; i++) {
        if (theForm.elements[i].name == 'mes_s[]') {
            theForm.elements[i].checked = t.checked;
		}
    }
};

function checkButton(el) {
	if (el == document.getElementById('tip1')) {
		if (el.checked == true) {
		    if (document.getElementById('tip2').checked == true)
				el.checked = false;
		} else {
			 if (document.getElementById('tip2').checked == true)
				el.checked = true;
		}
	}
	if (el == document.getElementById('tip2')) {
		if (el.checked == true) {
		    if (document.getElementById('tip1').checked == true)
				el.checked = false;
		} else {
			 if (document.getElementById('tip1').checked == true)
				el.checked = true;
		}
	}
};

function schimbaPaginatia(p, u) {
	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	http.open("GET", "lista.php?field=paginatie&nr=" + p + "&user=" + u, true);	
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) {
			x = http.responseText;	
			window.location.reload(true);
		}
	}
	http.send(null);	
};

function tellAFriend() {
//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {

	if(navigator.appName == "Microsoft Internet Explorer") {
		document.getElementById("wrapper").style.width = "auto";
		document.getElementById("wrapper").style.height = "auto";
		document.getElementById("wrapper").style.position = "static";
	}

    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

	if ( dim.length > 1 ) {
	
		document.getElementById("url").value = dim[1].split('=')[1];

	}
    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="common/graphics/close-icon.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
	window.location.reload();
	return false;
});
}

function detaliiProdus() {

if (document.getElementById("detalii_produs") == null) {
	} else {
		var http = false;
		var val = document.getElementById("produs").value;
		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
		http.open("GET", "lista.php?field=detalii_produs&val=" + val);	
		http.onreadystatechange = function() {
			if(http.readyState == 4 && http.status == 200) {
				x = http.responseText;	
				document.getElementById("detalii_produs").innerHTML = "";
				document.getElementById("detalii_produs").innerHTML = x;
			}
		}
		http.send(null);	
	}

}

function stergeComentarii(i, n) {
	for (c=0;c<=n;c=c+1) {
		if (c != i) {
			document.getElementById("comentariu" + c).innerHTML = "";
		}
	}
}

function showToolTip(e){
	if(document.all)e = event;
	
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj.style.display = 'block';
	
		var http = false;
		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}
		http.open("GET", "lista.php?field=anunturi_personale");	
		http.onreadystatechange = function() {
			if(http.readyState == 4 && http.status == 200) {
				x = http.responseText;	
				obj2.innerHTML = x;
			}
		}
		http.send(null);	
		
	
}	

function hideToolTip()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	http.open("GET", "lista.php?field=ascunde_mp");	
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) {
			x = http.responseText;
		}
	}
	http.send(null);
}

function activeazaButon( check ) {

	if ( document.getElementById("agree").checked == true ) {
	
		document.forms[1].submit.disabled = false;
	
	} else {
	
		document.forms[1].submit.disabled = true;
	
	}

}
