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 nimic(){

}

function confirm_delete(url,question) {

	test = confirm(question);

	if ( test == true ){

		document.location = url;

		return false;

	}

}

var handlerFunc = function(t) {

    alert('Response :'+t.responseText);

}

var handlerXML = function(t) {

    alert(t.responseXML);

}

var errFunc = function(t) {

    alert('Error ' + t.status + ' -- ' + t.statusText);

}

function ask_delete_category(id) {

	if ( confirm('Esti sigur ca vrei sa stergi aceasta categorie?') ) {

		window.location = 'produse_categorii_stergere.php?id='+id;

		return true;

	}

	else {

		return false;

	}

}

function ask_delete_manufacturer(id) {

	if ( confirm('Esti sigur ca vrei sa stergi acest producator?') ) {

		window.location = 'produse_producatori_stergere.php?id='+id;

		return true;

	}

	else {

		return false;

	}

}

function adauga_gama(id) {

	if ( $('adauga_gama_'+id).style.display == "none" ) {

		$('adauga_gama_'+id).style.display = "" ;

	}

	else {

		$('adauga_gama_'+id).style.display = "none" 

	}

}

function populeaza_game(id_cat,id_gama) {

	

	url = '/ajax_functions_xml.php?act=arata_game&cat_id='+id_cat+'&id_gama='+id_gama;

	//document.write(url);

	new Ajax.Request(url , { onSuccess:function(a) {

		rasp = a.responseXML;

		var selObj = $('produs_gama');

		var xmldoc=rasp;

		if (!xmldoc) return false;

		var opts = xmldoc.getElementsByTagName('options')[0];

		if (!opts) {

			selObj.length=0;

			selObj[0]=new Option('-------','-1',false,false);

			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,sel,sel);

		}

		$('produs_gama').style.display = "";

	}, onFailure:errFunc});



}

function populeaza_localitati(id_judet) {

	url = '/ajax_functions_xml.php'+'?act=arata_localitati&id_judet='+id_judet

	//document.write(url);

	new Ajax.Request(url , { onSuccess:function(a) {

		rasp = a.responseXML;

		var selObj = document.getElementById('localitate');

		var xmldoc=rasp;

		if (!xmldoc) return false;

		var opts = xmldoc.getElementsByTagName('options')[0];

		if (!opts) {

			selObj.length=0;

			selObj[0]=new Option('-------','-1',false,false);

			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,sel,sel);

		}

		document.getElementById('gama').style.display = "";

	}, onFailure:errFunc});

	$('localitate').removeAttribute('disabled');

}

function selectie_tip_factura(tip) {

	if ( tip == 'persoana_fizica' ) {

		$('tabel_factura_persoana_juridica').style.display = 'none';

		$('tabel_factura_persoana_fizica').style.display = '';

	}

	else {

		$('tabel_factura_persoana_fizica').style.display = 'none';

		$('tabel_factura_persoana_juridica').style.display = '';

	}

}

function tip_livrare(tip) {

	if ( tip == 'personal') {

		$('livrare_judet').style.display = 'none';

		$('livrare_localitate').style.display = 'none';

		$('livrare_adresa').style.display = 'none';

	}

	else {

		$('livrare_judet').style.display = '';

		$('livrare_localitate').style.display = '';

		$('livrare_adresa').style.display = '';

	}

}

function sterge_gama(id) {

	if ( confirm('Esti sigur ca vrei sa stergi aceasta gama ?') ) {

		window.location = 'produse_game_stergere.php?id='+id;

	}

}



function product_list_type(name, value, checked) {

	alert(name+' '+checked);

	var location = window.location;

	if ( checked == true || checked > 0 ) {

		window.location = window.location + '&'+name+'='+value;

	}

	else if ( checked == false || checked == true )  {

		location = location.toString();

		var location = location.split('&');

		for ( i=0;i<location.length;i++ ) {

			if ( location[i].indexOf(name) == 0  ) {

				alert('Gasit : '+location[i]);

			}

		}

	}

}

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;

	}	

	if(yScroll < windowHeight){

		pageHeight = windowHeight;

	} else { 

		pageHeight = yScroll;

	}

	if(xScroll < windowWidth){	

		pageWidth = windowWidth;

	} else {

		pageWidth = xScroll;

	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;

}



var show_transparent = function() {

	size = getPageSize();

	$('background').setStyle({height: size[1]+'px'});

	$('background').style.display = '';

}

var close_transparent = function() {

	$('alert').style.display = 'none';

	$('background').style.display = 'none';

}

var stock_alert = function(id) {

	$('product_id').value = id;

	new Ajax.Updater('nume_alerta', '/ajax_functions.php?act=product_name&alert='+id, {onError:errFunc});

	show_transparent();

	Effect.BlindDown('alert', { duration: 0.3 });

	Effect.ScrollTo('alert', {duration:0.3, offset:-20});

}

var stock_alert_close = function() {

	close_transparent();

}



var stockAlertResult = function(a) {

	a  = a.responseText;

	a = a.split('|');

	if ( a[0] == 0 ) {

		$('stock_response').innerHTML = a[1];

	}

	else {

		$('stock_response').innerHTML = a[1];

		setTimeout('stock_alert_close()',4000);

	}

}

var procesare_comanda = function(response) {

	var raspuns = (response.responseText);

	if ( raspuns.substr(0,1) == '0' ) {

		$('errors').innerHTML = 'Completati urmatoarele erori :<ul>'+raspuns.substr(2,raspuns.length)+'</ul>';

		$('errors').style.display = '';

		Effect.ScrollTo('errors', {duration:0.3, offset:-20});

	}

	else {

		$('errors').style.display = 'none';

		$('listare_produse_comandate').style.display = 'none';

		$('order_details').innerHTML = '<p style="margin:15px 0;padding:15px;font-size:12px;">Va multumim.<br />Comanda dvs. va fi preluata, urmand a fi contactat in cel mai scurt timp.</p>';

		Effect.ScrollTo('order_details', {duration:0.3, offset:-20});

	}

}

function update_order_status(order_id, status) {
	new Ajax.Request('/ajax_functions.php?act=update_order_status&order_id='+order_id+'&status='+status, {onError:errFunc, onSuccess:function(t) { new Effect.Highlight('row_'+t.responseText) } });
}

