var site_url_booster = "http://www.htb.ro/";
function get_game(cat_id,prd_id,gama_id) {
	cat_id = cat_id.split("|");
	cat_id = cat_id[0];	
	url = site_url_booster+'admin/newsletter_functions_xml.php'+'?act=arata_game&cat_id='+cat_id+'&prd_id='+prd_id+'&gama_id='+gama_id;
	//document.write(url);
	new Ajax.Request(url , { onSuccess:function(a) {
		rasp = a.responseXML;
		var selObj = document.getElementById('prd_id_gama');
		var xmldoc=rasp;
		if (!xmldoc) return false;
		var opts = xmldoc.getElementsByTagName('options')[0];
		if (!opts) {
			selObj.length=0;
			selObj[0]=new Option('-------','-1');
			return false;
		}
		var elems = opts.getElementsByTagName('option');
		selObj.length=0;
		var val=-1;
		var txt='error';
		var opt;
		for(i=0;i<elems.length;i++) {
			val=elems[i].getAttribute("value");
			txt=elems[i].getAttribute("text");
			sel=elems[i].getAttribute("select");
			dis=elems[i].getAttribute("disable");
			selObj[i]=new Option(txt,val,'false',sel);
		}
		document.getElementById('lista_game').style.display = "";
	}, onFailure:errFunc});
}
function schimba_clase_producatori() {
	elemente = getElementsByClassName(document,"*","pic_prod");
	for ( i=0;i<elemente.length;i++ ) {
		elemente[i].onmouseover = function() { this.className = 'pic_prod_over'}
		elemente[i].onmouseout = function() { this.className = 'pic_prod'}
	}
}
function AttachEvent(elementObj, eventName, eventHandlerFunctionName)
{
  if (elementObj.addEventListener) 
  { 
    elementObj.addEventListener(eventName, eventHandlerFunctionName, false);		
  } 
  else if (elementObj.attachEvent) 
  { 
    elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);
  } 
  else 
  { 
    var currentEventHandler = elementObj['on' + eventName];
    if (currentEventHandler == null) 
    {
      elementObj['on' + eventName] = eventHandlerFunctionName;
    } 
    else 
    {
      elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }
    }
  }
}
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}
function captcha_reload(id) {
	theImg=document.getElementById(id);
	theImg.src +='?'+ Math.round(Math.random()*100000);
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function nimic(){
}
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_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_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];}
}
function confirm_delete(url,question) {
	test = confirm(question);
	if ( test == true ){
		document.location = url;
		//alert(url);
		return false;
	}
}
function sterge_comanda(url,id,question) {
	test = confirm(question);
	if ( test == true ){
		//
		new Ajax.Request(site_url_booster + 'admin/comenzi_delete.php', {parameters:'com_id='+id, method:'get'});
		document.location = url;
		return false;
	}
}
var handlerFunc = function(t) {
    alert(t.responseText);
}
var handlerXML = function(t) {
    alert(t.responseXML);
}
var errFunc = function(t) {
    alert('Error ' + t.status + ' -- ' + t.statusText);
}
var schimba_producator = function(nume_producator) {
	nume = nume_producator.split("|");
	if ( nume[0] != 0 ) window.location = site_url_booster+"producatori/"+nume[0]+'-'+nume[1];
	else  window.location = site_url_booster+"producatori/";
}
var open_window = function(url,height,width) {
	
	window.open(url,'','scrollbars=yes,menubar=no,height='+height+',width='+width+',resizable=yes,toolbar=no,location=no,status=no');
}
function resizeOuterTo(width,height) {
	if (window.outerWidth) {
		window.outerWidth = width;
		window.outerHeight = height;
	}
	else if (window.resizeTo) {
		window.resizeTo(width,height);
	}
}
function moveWindowTo(w,h) {
	sw = screen.width;
	sh = screen.height;
	l = (sw - 800) / 2;
	t = (sh - 800) / 2;
	//alert(t);
	moveTo(w,h)
}

var change_large = function(id,path) {
	$('main_pic').src = path;
}

var arata_erori = function(r) {
	rasp = r.responseText;
	$('error_display').innerHTML = rasp;
	//alert(rasp.substr(1,7));
	if ( rasp.substr(1,7) == "success" ) {
		new Effect.Fade('add_review');
		$('error_display').innerHTML = rasp.substr(9,rasp.length)
	}
	else {
		$('error_display').innerHTML = "Erori :"+rasp;
		captcha_reload('captcha','lnk_securitycode');
		$('lnk_securitycode').value="";
	}
	new Effect.ScrollTo('error_display',{offset: -50});
	new Effect.Appear('error_display');
}
function arata_produse(val) {
	//alert(val);
	val = val.split("|");
	new Ajax.Request('produs_functii_xml.php', {parameters:'act=arata_produse&prod_id='+val[0]+'&cat_id='+val[1]+'&pid='+val[2], onSuccess:populeaza_produse, onFailure:errFunc});
}
var populeaza_produse = function(a) {
	rasp = a.responseXML;
	var selObj = document.getElementById('lista_produse');
	var xmldoc=rasp;
	if (!xmldoc) return false;
	var opts = xmldoc.getElementsByTagName('options')[0];
	if (!opts) {
		selObj.length=0;
		selObj[0]=new Option('-------','-1');
		return false;
	}
	var elems = opts.getElementsByTagName('option');
	selObj.length=0;
	var val=-1;
	var txt='error';
	var opt;
	for(i=0;i<elems.length;i++) {
		val=elems[i].getAttribute("value");
		txt=elems[i].getAttribute("text");
		sel=elems[i].getAttribute("select");
		dis=elems[i].getAttribute("disable");
		selObj[i]=new Option(txt,val,'false',sel);
	}
	document.getElementById('lista_produse').style.display = "";
}
function get_detalii(pid,container) {
	new Ajax.Updater(container, 'produs_functii.php',{parameters:'act=detalii_produs&pid='+pid ,asynchronous:true, evalScripts:true,onComplete:function(){ new Effect.Highlight(container,{startcolor:'#EEEEEE',endcolor:'#FFFFFF'});}});
}
function update_status(com_id,status) {
	new Ajax.Request(site_url_booster+'produs_functii.php',{parameters:'act=update_comanda&com_id='+com_id+'&status='+status ,asynchronous:true,onComplete:function(t){$('update_status').innerHTML=t.responseText; new Effect.Highlight('update_status');}});
}
function update_dist_activ(did,status) {
	new Ajax.Request(site_url_booster+'produs_functii.php',{parameters:'act=update_distribuitor&did='+did+'&status='+status ,asynchronous:true,onComplete:function(t){$('update_status').innerHTML=t.responseText; new Effect.Highlight('update_status');}});
}
var form_do_login = function(r) {
	rasp = r.responseText;
	if ( rasp != 1 ) {
		new Effect.Shake('login_form');
	}
	else {
		new Effect.Fade('login_form',{afterFinish:function() {
			new Ajax.Updater('div_info', site_url_booster+'functii.php',{parameters:'act=arata_login_box' ,asynchronous:true,onComplete:function(){
				new Effect.Appear('div_info');
				document.location = document.location;
			}});
		}});
		
	}
}
function toggle_div(id) {
	if ( $(id).style.display == "none")  $(id).style.display = "";
	else $(id).style.display = "none";
}
var erori_newsletter = function(t) {
	rasp = t.responseText;
	if ( rasp.substr(1,7) == "success" ) {
		new Effect.Fade('tbl_newsletter');
		display_message(rasp.substr(9,rasp.length));
		setTimeout("new Effect.Appear('tbl_newsletter');",5000);
	}
	else{	
		display_message(rasp);
		setTimeout("new Effect.Appear('tbl_newsletter');",5000);
	}
}




var labels_counter = 0;
function add_label() {
	labels_counter++;
	var place 	= $('to_insert');
	var the_tr = document.createElement('tr');
	var the_td_1 = document.createElement('td');
	var the_content_1 = document.createElement('input');
	the_content_1.setAttribute('class','regular_form_input');
	the_content_1.setAttribute('name','label[]');
	the_td_1.setAttribute('width','140');
	the_td_1.appendChild(the_content_1);
	the_tr.appendChild(the_td_1);
	place.appendChild(the_tr);
}


var change_newsletter_type = function(disp_what,h1) {
	$(h1).style.display = "none";
	if ( disp_what == "newsletter_produse_list" ) {
		new Ajax.Updater('newsletter_produse_list',site_url_booster+'admin/newsletter_functions.php',{asynchronous:true,evalScripts:true,parameters:'act=listare_produse'});
	}
	$(disp_what).style.display = "";	
}
function arata_produse_categorie(val) {
	url = site_url_booster+'admin/newsletter_functions_xml.php?act=arata_produse&cat_id='+val;

	new Ajax.Request(site_url_booster+'admin/newsletter_functions_xml.php', {parameters:'act=arata_produse&cat_id='+val, onSuccess:populeaza_produse_categorie, onFailure:errFunc});
}
var populeaza_produse_categorie = function(a) {
	rasp = a.responseXML;
	var xmldoc=rasp;
	if (!xmldoc) return false;
	var selObj = $('prod_list');
	var opts = xmldoc.getElementsByTagName('options')[0];
	if (!opts) {
		selObj.length=0;
		selObj[0]=new Option('---------','-1');
		return false;
	}
	var elems = opts.getElementsByTagName('option');
	selObj.length=0;
	var val=-1;
	var txt='error';
	var opt;
	for(i=0;i<elems.length;i++) {
		val=elems[i].getAttribute("value");
		txt=elems[i].getAttribute("text");
		sel=elems[i].getAttribute("select");
		dis=elems[i].getAttribute("disable");
		selObj[i]=new Option(txt,val,dis,sel);
	}
	$('prod_list').style.display = "";
}

var magic_f = pas_f = 1;
function moveForward_f(container, element){
	pasi_max_f = Math.round(elemente_f/1);
	if(pas_f < pasi_max_f){
		pas_f++;
		magic_f = magic_f+1;
		element_f = 'scroll_galerie_'+magic_f;
		Position.prepare();
		container_x = Position.cumulativeOffset($(container))[0]
		element_x = Position.cumulativeOffset($(element_f))[0]
		new Effect.Scroll(container, {x:(element_x-container_x), y:0});
		return false;
	}
}
function moveBack_f(container, element){
	if(magic_f > 1){
		magic_f = magic_f-1;
		element_f = 'scroll_galerie_'+magic_f;
		Position.prepare();
		container_x = Position.cumulativeOffset($(container))[0]
		element_x = Position.cumulativeOffset($(element_f))[0]
		new Effect.Scroll(container, {x:(element_x-container_x), y:0});
		pas_f--;
		return false;
	}
}
