$(function(){
	$('select.styled').customStyle();
	$('select.styled_mic').customStyle_mic();
	$('select.styled_cam').customStyle_Cam();
});

function validate_newsletter(){
	var b = document.getElementById("email_news").value;
	if(!echeck(b)){
		return false
	}
	getById('frm_news').submit();
	return true
}

function echeck(j){
	var h = "@";
	var g = ".";
	var k = j.indexOf(h);
	var m = j.length;
	var l = j.indexOf(g);
	//dprint('je: '+j);
	if (j == "" || !j){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	if(j.indexOf(h) == -1){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	if(j.indexOf(h) == -1 || j.indexOf(h) == 0 || j.indexOf(h) == m){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	if(j.indexOf(g) == -1 || j.indexOf(g) == 0 || j.indexOf(g) == m){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	if(j.indexOf(h,(k+1)) != -1){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	if(j.substring(k-1,k) == g || j.substring(k+1,k+2) == g){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	if(j.indexOf(g,(k+2)) == -1){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	if(j.indexOf(" ") !=- 1){
		alert("Va rugam introduceti o adresa de email valida");
		return false
	}
	return true
}
function reset_input(df_val,obj){val=$(obj).val();if(df_val==val){$(obj).val("");}
if(val==''){$(obj).val(df_val);}}

function reset_password(id,type){if(type=='focus'){$('#'+id+'_tx').hide();$('#'+id).removeClass('hidden');$('#'+id).focus();}
if(type=='blur'){if($('#'+id).val()==''){$('#'+id+'_tx').show();$('#'+id).addClass('hidden');}}}


$(document).ready(function() {
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	//pentru modificare checkbox-urilor
	$('#form_ct_transfer input[type=checkbox]').prettyCheckboxes();//,#radioDemo input[type=radio]
	//$('.inlineRadios input[type=radio]').prettyCheckboxes({'display':'inline'});
	
	//pentru modificare checkbox-urilor
	$('#frm_inreg input[type=checkbox]').prettyCheckboxes();//,#radioDemo input[type=radio]
	
	//pentru modificare radiobuton
	//$('#frm_rez input[type=radio]').prettyCheckboxes();//,#radioDemo input[type=radio]
	
	//pentru modificare radiobuton
	//$('#frm_rez input[type=checkbox]').prettyCheckboxes();//,#radioDemo input[type=radio]
});

//inregistrare ------------------------------------------------------------------
function inregistrare(){
	zonaActiva = 'inreg';
	if (getById('tab')) getById('tab').value = 'INREG';
	//alert(document.getElementById('log_inreg').style.display);
	document.getElementById('login').style.display = 'none';
	document.getElementById('am_uitat').style.display = 'none';
	//alert(document.getElementById('log_inreg').style.display);
	document.getElementById('inregistrare').style.display = getRowDisplayStyle();
	return;
}

//login ------------------------------------------------------------------
function login(){
	zonaActiva = 'login';
	if (getById('tab')) getById('tab').value = 'LOGIN';
	//alert(document.getElementById('log_inreg').style.display);
	document.getElementById('inregistrare').style.display = 'none';
	document.getElementById('am_uitat').style.display = 'none';
	//alert(document.getElementById('log_inreg').style.display);
	document.getElementById('login').style.display = getRowDisplayStyle();
	return;
}

//am uitat ------------------------------------------------------------------
function am_uitat(){
	zonaActiva = 'am_uitat';
	if (getById('tab')) getById('tab').value = 'UITAT';
	//alert(document.getElementById('log_inreg').style.display);
	document.getElementById('inregistrare').style.display = 'none';
	document.getElementById('login').style.display = 'none';
	//alert(document.getElementById('log_inreg').style.display);
	document.getElementById('am_uitat').style.display = getRowDisplayStyle();
	return;
}

//pot modifica date client ---------------------------------------------------
function modifInfoClient(){
	zonaActiva = 'modf_client';
	if (getById('tab')) getById('tab').value = 'MODIF_CLIENT';
}
//####################################################################################################################################
//setari implicite
var lastDivPlata = '';
var plataSelectata = '';
var state = 'block';

function clickPlata(sTip) {
	plataSelectata = sTip;
	if (lastDivPlata)
			changeDisplay(lastDivPlata, 'none');

	if(sTip == 'pos'){
			changeDisplay('info_plata_OP', 'none');
			changeDisplay('info_plata', 'none');
			changeDisplay('termeni_'+sTip, 'block');
			changeDisplay('info_plata_AGNT', 'none');
	}
	else if(sTip == 'posg'){
			changeDisplay('info_plata_OP', 'none');
			changeDisplay('info_plata', 'none');
			changeDisplay('termeni_'+sTip, 'block');
			changeDisplay('info_plata_AGNT', 'none');
	}
	else if(sTip == 'cash'){
			changeDisplay('termeni_'+sTip, 'block');
			changeDisplay('info_plata', (sTip == 'posg')? 'none' : 'block');
			changeDisplay('info_plata_OP', 'none');
			changeDisplay('info_plata_AGNT', 'none');
	}
	else if(sTip == 'op'){
			changeDisplay('termeni_'+sTip, 'block');
			changeDisplay('info_plata', 'none');
			changeDisplay('info_plata_OP', (sTip == 'posg')? 'none' : 'block');
			changeDisplay('info_plata_AGNT', 'none');
	}
	else if(sTip == 'agnt'){
			changeDisplay('termeni_'+sTip, 'block');
			changeDisplay('info_plata', 'none');
			changeDisplay('info_plata_OP', 'none');
			changeDisplay('info_plata_AGNT', 'block');
	}

	lastDivPlata = 'termeni_'+sTip;
	changeDisplay('tr_err_plata', 'none');

}
function showhide(layer_ref) {
	if (state == 'none') {
		state = 'block';
	}
	else {
		state = 'none';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = state;
	}
	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.display = state;
	}
}

function afiseaza_agentii(div) {
        changeDisplay(div, getRowDisplayStyle());
}

function LTrim( value ) {

        var re = /\s*((\S+\s*)*)/;
        return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim( value ) {

        var re = /((\s*\S+)*)\s*/;
        return value.replace(re, "$1");

}

// Removes leading and ending whitespaces
function trim( value ) {
        var re = /^\s+|\s+$/g;
        return value.replace(re,"");
        //return LTrim(RTrim(value));

}

