var ie = document.all;
var dom = document.getElementById;
var ns4 = document.layers;

function  GetElement(id) { 
	return document.getElementById(id); 
	//if ( !dom && !ie && !ns4 ) return null;
	//return (dom) ? document.getElementById(id) : ie ? document.all.id : document.id;
}

function BOver(but) { but.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=2,opacity=35,finishOpacity=100,startX=0,finishX=0,startY=0,finishY=50)"; }
function BOut(but) { but.style.filter=""; }

function MOver(td, v) { if ( td ) { td.style.backgroundImage = 'url(/assets/menusep'+v+'_over.gif)'; td.style.color = '#FF0000';}}

function MOut(td, v) {if ( td ){ td.style.backgroundImage = 'url(/assets/menusep'+v+'.gif)'; td.style.color = '#CF063A';}}

function createShadow() 
{
  if ( screen.width > 800 )
  {    
	left = GetElement('shadow_left');
	if ( left )
	  left.innerHTML = '<img src="/assets/bg_shadow_left.jpg"/>';

	right = GetElement('shadow_right');
	if ( right )
	  right.innerHTML = '<img src="/assets/bg_shadow_right.jpg"/>';
  }
}

function EmailValid( email ) { return filter.test(email); }

function TestField(field_id, regex, message) {
	field = GetElement(field_id);
	if ( !field ) { alert('Camp invalid!'); return false; };
	if ( field.value.search(regex) == -1 ) {  alert(message); field.focus(); return false; }
	return true;
}

var email_filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var submit = 0;

function SubmitLoginForm(action	) 
{	
	form = GetElement('form_login_user');
	if ( !form ) return false;
	
	if ( submit > 0 ) { alert('Te rugam sa astepti ...'); return false; }
	
	if ( form.auth_action.value == "login" || action == "reset_parola" ) {
		if ( !TestField('cdata_email', '^(.+)$', 'Te rugam sa introduci adresa ta de email!') ) return false;
		if ( !TestField('cdata_email', email_filter, 'Adresa de email nu pare corecta!') ) return false;
	}
	
	if ( action != "reset_parola" && form.auth_action.value == "login" && !TestField('cdata_parola', '^(.+)$', 'Te rugam sa introduci parola!') ) return false;
	
	submit++; 
	if ( action == "reset_parola" ) {
		form.auth_action.value = action;
		form.submit();
	}

	return true; 
}

function SubmitAfiliatForm() 
{	
	form = GetElement('form_login_afiliat');
	if ( !form ) return false;
		
	if ( submit > 0 ) { alert('Te rugam sa astepti ...'); return false; }
	 
	if ( form.auth_action.value == "login_afiliat" )
	{
		if ( !TestField('afil_user', '^(.+)$', 'Te rugam sa introduci numele contului!') ) return false;
		if ( !TestField('afil_pas', '^(.+)$', 'Te rugam sa introduci parola!') ) return false;
	}
		
	submit++; 			
	return true;
}

function SubmitNewsletterForm()
{
	if ( submit > 0 ) { alert('Te rugam sa astepti ...'); return false; }
	 
	if ( !TestField('n_email', '^(.+)$', 'Te rugam sa introduci adresa ta de email!') ) return false;
	if ( !TestField('n_email', email_filter, 'Adresa de email nu pare corecta!') ) return false;
	
	submit++;
	return true;
}
