window.onload = init;
function init() {
	if (document.all) {
		document.onmousemove = getXY_IE;
	}
	else {
		if (window.Event) {
			document.captureEvents(Event.MOUSEMOVE);
		}
		document.onmousemove = getXY;
	}
}
var x_cursor;
var y_cursor;
function getXY(e) {
	x_cursor = (window.Event) ? e.pageX : event.clientX;
	y_cursor = (window.Event) ? e.pageY : event.clientY;
}
function getXY_IE(){
	var de = document.documentElement;
	var b = document.body;
	x_cursor = event.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
	y_cursor = event.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
}


function ShowImage(whatimage){
	init();
	zIndexuri++;
	document.getElementById("mouse_over_"+whatimage).style.display='block';
	document.getElementById("mouse_over_"+whatimage).style.zIndex=zIndexuri;
	if (y_cursor+280 > document.body.scrollHeight ){
		document.getElementById("mouse_over_"+whatimage).style.top=y_cursor-200+'px';
	} else {
		if (y_cursor+400 > document.body.scrollHeight ){
			document.getElementById("mouse_over_"+whatimage).style.top=y_cursor-100+'px';
		} else {
			document.getElementById("mouse_over_"+whatimage).style.top=y_cursor+14+'px';
		}
	}
	document.getElementById("mouse_over_"+whatimage).style.left=x_cursor+14+'px';
}
function HiddeImage(whatimage){
	document.getElementById("mouse_over_"+whatimage).style.display='none';
}


var fckuri=[];
function apelaereFCK(n){
	if (!fckuri[n]) {
		var oFCKeditor = new FCKeditor('content_'+n) ;
		oFCKeditor.Height=450;
		oFCKeditor.BasePath = "panou-control/includes/fckeditor/" ;
		oFCKeditor.ReplaceTextarea() ;
		fckuri[n]=true;
	}
}
// Eroare daca nu exista elementul
function ErrorNoId(cine) {
	alert(' Reporniti browsetrul \n\r elementul '+cine+' nu exista ! ');
	return false;
}
// Get By Id
function byid(id){
	try{
		return document.getElementById(id);
	}
	catch(e){
		ErrorNoId(id);
	}
}
// Get By Name
function byname(name){
	try{
		return document.getElementsByName(name);
	}
	catch(e){
		ErrorNoId(name);
	}
}


function GetXmlHttpObject() {
	var xmlHttp=null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}



var xml_refresh=GetXmlHttpObject();
var xml_refresh_bid=GetXmlHttpObject();
var valori=[];
function rewrite_vars() {
	xml_refresh.open("GET",window.siteurl+'bid.php');
	xml_refresh.onreadystatechange=function () {
		if (xml_refresh.readyState==4) {
			//alert(xml_refresh.responseText);
			eval(xml_refresh.responseText);
			//alert(xml_refresh.responseText);
			//valori=elva(xml_refresh.responseText);
			eval_json(valori);
		}
	}
	xml_refresh.send(null);
	t=setTimeout(function () { rewrite_vars(); },800);
}
function eval_json(valori) {
	//alert(valori);
	for (var i=0; i<=valori.length;i++) {
		var licitatie=valori[i];
		//alert('timp_'+licitatie[0]);

		document.getElementById('timp_'+licitatie[0]).innerHTML=licitatie[1];
		document.getElementById('user_'+licitatie[0]).innerHTML=licitatie[2];
		document.getElementById('pret_'+licitatie[0]).innerHTML='Pret: '+licitatie[3]+' Lei';
	}
}
function bid(id) {
	xml_refresh_bid.open("GET",window.siteurl+'user_bid.php?lic='+id);
	xml_refresh_bid.send(null);
}
function afImagineProd(nr) {
	for (var i=1;i<=4;i++) {
		if (i==nr) {
			document.getElementById('imgProdBig_'+i).style.display='block';
		} else {
			document.getElementById('imgProdBig_'+i).style.display='none';
		}
	}
}
//============================
function cumparaCrediteCard(inp,form) {
	if (document.getElementById(inp).value=='') {
		alerta('Va rugam alegeti un pachet de credite!',400,50);
	} else {
		document.getElementById(form).submit();
	}
}
function cumparaCrediteSMS(inp,form) {
	if (document.getElementById(inp).value=='') {
		alerta('Va rugam alegeti un pachet de credite!',400,50);
	} else {
		document.getElementById(form).submit();
	}
}
var zIndexuri=100;
function showTip(displayDiv){
	init();
	zIndexuri++;
	document.getElementById("mouse_over_"+displayDiv).style.display='block';
	document.getElementById("mouse_over_"+displayDiv).style.zIndex=zIndexuri;

	document.getElementById("mouse_over_"+displayDiv).style.top=y_cursor+14+'px';
	document.getElementById("mouse_over_"+displayDiv).style.left=x_cursor+14+'px';
}
function showTip2(displayDiv){
	init();
	zIndexuri++;
	document.getElementById("mouse_over2_"+displayDiv).style.display='block';
	document.getElementById("mouse_over2_"+displayDiv).style.zIndex=zIndexuri;

	document.getElementById("mouse_over2_"+displayDiv).style.top=y_cursor+14+'px';
	document.getElementById("mouse_over2_"+displayDiv).style.left=x_cursor+14+'px';
}
function hideTip(displayDiv){
	document.getElementById("mouse_over_"+displayDiv).style.display='none';
}
function hideTip2(displayDiv){
	document.getElementById("mouse_over2_"+displayDiv).style.display='none';
}

function ShowTab(div,nrMax) {
	for (var i=0;i<nrMax;i++) {
		if (div==i) {
			document.getElementById('tab'+i).className='active';
			document.getElementById('divContent_'+i).style.display='block';
		} else {
			document.getElementById('tab'+i).className='inactive';
			document.getElementById('divContent_'+i).style.display='none';
		}
	}
}
var nrEmailsAdd=5
function addMoreEmails(val,val2) {
	var newInput=document.createElement('div');
	newInput.id='div_'+nrEmailsAdd;
	newInput.style.marginTop='5px';
	document.getElementById(val).appendChild(newInput);
	var value='';
	value+='<div class="floatLeftScris" style="width:110px">Adresa de e-mail:</div>';
	value+='<div class="float">';
	value+='<input type="text" name="email_'+nrEmailsAdd+'" id="email_'+nrEmailsAdd+'" style="width:190px;border:1px solid #000000" />';
	value+='</div>';
	value+='<div class="clear"></div>';
	newInput.innerHTML=value;
	document.getElementById(val2).value=nrEmailsAdd;
	nrEmailsAdd=1*nrEmailsAdd+1*1;
}
/////////////////////////////////////////FUNCTII SHOP FLAX//////////////////////////////
function openGallery(prodId,image) {
	var left=(screen.width-600)/2;
	var top=(screen.height-660)/2;
	windowGallery=window.open (window.siteroot+"window-gallery-"+prodId+"-"+image+".html","windowGallery","width=600,height=680,status=0");
	windowGallery.moveTo(left,top);
}
var stock_product=0;
function buy(idp,quantInput) {
	if (quantInput==null) {
		var qaunt=1;
	} else {
		if ($val(quantInput)<1) {
			eroare('Cantitatea trebuie sa fie mai mare de 1!',260,50);
		} else {
			var quant=eurl($val(quantInput));
		}
	}
	if (stock_product<0) alerta('Acest produs nu este pe stoc');
	var is_valid=true;
	var variation='';
	number_of_option=array_of_variations.length;
	if (number_of_option>0) {
		for(var i=0;i<number_of_option;i++) {
			if (array_of_variations[i]==0) is_valid=false;
		}
		variation=array_of_variations.join('-');
	}
	if (is_valid==false) {
		eroare(' Acest produs nu poate fi cumparat fara a <br/> selecta o variatie de produs',320,100);
	} else {

		var add_get='';
		if (number_of_option>0) add_get='&variation='+variation;
		window.location=window.siteroot+'cart.html?id='+idp+add_get+'&oper=add&quant='+qaunt;

	}
}
// VARIATIONS BEGIN
var array_of_variations=new Array;
function mod_prod_variation(nr_option,value,id){

	var values_ok=tree_of_values[value];
	for(var i=(nr_option+1);i<array_of_variations.length;i++) {
		$("#select_var_"+i).html('<option value="0">Selectati</option>');
		$("#select_var_"+i).attr('disabled',true);
	}
	for (var x in values_ok) {
		var new_option=document.createElement('option');
		new_option.text=values_ok[x];
		new_option.value=x;
		try{
			document.getElementById('select_var_'+(nr_option+1)).add(new_option,null);
		}
		catch(ex){
			document.getElementById('select_var_'+(nr_option+1)).add(new_option);
		}
	}
	if (value!=0) $("#select_var_"+(nr_option+1)).attr('disabled',false);
	array_of_variations[nr_option]=value;
	var is_valid=true;
	for(var i=0;i<array_of_variations.length;i++) {
		if (array_of_variations[i]==0) is_valid=false;
	}
	if (is_valid==true) {
		var variation=array_of_variations.join('-');
		var trim='id='+id+'&variation='+variation;
		EjaxCb(window.siteroot+'includes/ajax_php/product_variation_info.php',trim,'',function (r) {
			var obj;
			eval('obj='+r);
			if (obj.price!='') $('#product_price').html(obj.price);
			if (obj.code!='') $('#product_code').html(obj.code);
			if (obj.image!='') $('#product_image').html(obj.image);
			if (obj.stock!='') $('#product_stock').html(obj.stock);
			if (obj.stock_product!='') stock_product=obj.stock_product;
		});
	}
}
// VARIATIONS END
function showSub(id) {
	document.getElementById(id+'_sub').style.display='block';
}
function hideSides(id) {
	document.getElementById(id+'_l').className='sideHover';
	document.getElementById(id+'_r').className='sideHover';
}
function expand(id) {
	if (document.getElementById(id).style.display=='none') {
		document.getElementById(id).style.display='block';
		document.getElementById('siteContent').style.height='980px';
	} else {
		document.getElementById(id).style.display='none';
		document.getElementById('siteContent').style.height='650px';
	}
}
function planSelect(fetchedInnerHTML) {
	document.getElementById('formElementPost').value=fetchedInnerHTML;
	document.getElementById('formElementPostVisible').innerHTML=fetchedInnerHTML;
	document.getElementById('postSelectExpand').style.display='none';
	document.getElementById('siteContent').style.height='650px';
}
function cexpand(id) {
	if (document.getElementById(id).style.display=='none') {
		document.getElementById(id).style.display='block';
	} else {
		document.getElementById(id).style.display='none';
	}
}
function postSelect(fetchedInnerHTML) {
	document.getElementById('formElementPost').value=fetchedInnerHTML;
	document.getElementById('formElementPostVisible').innerHTML=fetchedInnerHTML;
	document.getElementById('postSelectExpand').style.display='none';
}
