var handlerFunc = function(t) {
   alert('Response :\r\n'+t.responseText);
  //  $('to_reply').innerHTML = t.responseText;
}
var handlerXML = function(t) {
    alert(t.responseXML);
}
var errFunc = function(t) {
    alert('Error :\r\n' + t.status + '\r\n Text: \r\n' + t.statusText);
}
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 openpopup(url, windowtarget) {
	width	= 800;
	height 	= 600;
	var sw = screen.width;
	var sh = screen.height;
	var l = (sw - width) / 2;
	var t = (sh - height) / 2;
    window.open(url,windowtarget,'width='+width+',height='+height+',top='+t+',left='+l+',status=no, resizable=no, toolbar=no, location=no');
}
function enable_id(id) {
	$('toggler_stoc_alert_'+id).onclick = function () {
		toggle_stoc_alert(id);
		return false;
	}
}
function toggle_stoc_alert(id) {
	if ( $('stoc_form_'+id).style.display == 'none' ) {
		$('toggler_stoc_alert_'+id).onclick = function() { return false ; }
		$('stoc_form_response_'+id).innerHTML = '';
		new Effect.BlindDown('stoc_form_'+id,{duration:0.3 , afterFinish:function() {
			enable_id(id); return false;
		} });
	}
	else {
		$('toggler_stoc_alert_'+id).onclick = function() { return false ; }
		new Effect.BlindUp('stoc_form_'+id,{duration:0.3 , afterFinish:function() {
			enable_id(id); return false;
		} });
	}
}




var show_in_main = function(pic) {
	$('product_main_image').src = pic;
	$('current_image').value = pic;
}

var toggle_specs_div = function(id) {
	if ( $('show_values_'+id).style.display == 'none' ) {
		new Effect.BlindDown('show_values_'+id,{duration:0.1});
		$('toggler_show_values_'+id).src = '/images/up'+ $('img_to_show_'+id).value;
	}
	else {
		new Effect.BlindUp('show_values_'+id,{duration:0.1});
		$('toggler_show_values_'+id).src = '/images/down'+ $('img_to_show_'+id).value ;
	}
}

var save_specs_div = function(id,words,description,type) {
	for ( i=0;i<document.forms[0][type].length;i++ ) {
		if ( document.forms[0][type][i].checked ) {
			value = document.forms[0][type][i].value ;
		}
	}
	url = '&act=save_specs&id='+id+'&words='+escape(words)+'&description='+escape(description)+'&type='+value;
	new Ajax.Request('http://www.airshop.ro/admin/?a=specifications&category=12', {parameters:url, method:'post',onSuccess:function(a) { if ( a.responseText != "~" ) toggle_specs_div(  a.responseText ); },onFailure:errFunc});
}


function toggle_different_markup(val) {
	if ( val == 'on') window.location = window.location+'&different_markup=on' ;
	else {
		var loc = window.location;
		var new_loc = loc.replace(/different_markup/,'aa');
	}
}

function captcha_reload(id) {
	theImg=document.getElementById(id);
	theImg.src +='?'+ Math.round(Math.random()*100000);
}
function show_hide_div(the_id) {
	if ( $(the_id).style.display == 'none' ) {
		$(the_id).style.display == '';
	}
	else {
		$(the_id).style.display == 'none'
	}
}
checked = true;


function vote(nr,stars) {
	//alert(nr+' - '+stars);
	var ss="";
	if (stars<1) stars=1;
	if (stars>5) stars=5;
	document.getElementById('form-vot-'+nr).value=stars;
	if (stars==1) ss="stea"; else ss="stele";
	document.getElementById('nrstele-'+nr).innerHTML="Ati votat "+stars+" "+ss;
}
function toggle_stoc_url(check) {
	var is_checked = (check.checked);
	loc = window.location+'';
	pos = loc.indexOf('stoc');
	if (is_checked) {
		if ( pos == -1 ) {
			window.location = window.location+'stoc/';
		}
		//alert('doar in stoc');
	}
	else {
		loc = loc.replace('/stoc/','/');
		//alert(loc);
		window.location = loc;
	}
}
function toggle_comments_listing() {
	if ( document.getElementById('comments_listing').style.display == 'none' ) {
		document.getElementById('comments_listing').style.display = '';
	}
	else {
		document.getElementById('comments_listing').style.display = 'none';
	}
}


function ajax_delete_order(id) {
	if ( confirm('Are you sure you want to delete order #'+id+' ?') ) {
		//alert(id);
		new Effect.Fade('order_'+id);
		new Ajax.Request('/admin/?a=orders&delete_order='+id,{method:'get'});
	}
}