document.onmousedown = function()
{
	for (a in document.links) document.links[a].onfocus = document.links[a].blur;
}


function validate(address) 
{
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  return reg.test(address) 
}

function trimite()
{
  if ($('#nume').val()==""||$('#email').val()=="")
  {
    alert('Toate campurile sunt obligatorii!');
    return false;
  }

  if (!validate($('#email').val()))
  {
    alert("Adresa de email este invalida!")
    return false;
  }  

  var randomnumber=Math.floor(Math.random()*11)
  $('#nwlform').load('newsletter.php?nume='+ encodeURIComponent($('#nume').val()) +'&email='+ encodeURIComponent($('#email').val()) +"&frecventa="+ $("input[name='option']:checked").val()+"&random="+randomnumber);
}

function inapoi()
{
  $('#nwlform').html('<form method="post"><table border="0" cellpadding="0" cellspacing="0"><tr><td class="nume_formular">Nume:</td><td><input type="text" class="camp_formular" id="nume" name="nume" value="" /></td></tr><tr><td class="nume_formular">Email:</td><td class="padding_camp"><input type="text" class="camp_formular"id="email" name="email" value="" /></td></tr><tr><td></td><td align="right"><input type="image" src="images/btn_abonare.gif" name="submit" value="" onclick="trimite();return false;"/></td></tr></table></form>');
}

if (/msie/i.test (navigator.userAgent)) //only override IE
{
  document.nativeGetElementById = document.getElementById; 
  document.getElementById = function(id)
  {
	var elem = document.nativeGetElementById(id);
	if(elem)
	{
	  //make sure that it is a valid match on id
	  if(elem.attributes['id'].value == id)
	  {
		return elem;
	  }
	  else
	  {
		//otherwise find the correct element
		for(var i=1;i<document.all[id].length;i++)
		{
		  if(document.all[id][i].attributes['id'].value == id)
		  {
			return document.all[id][i];
		  }
		}
	  }
	}
	return null;
  }
}

function checkNavPage(element, total){
	var introdus = document.getElementById(element).value;
	//alert(introdus+" "+total);
	if(Math.ceil(introdus) > Math.ceil(total)){
		alert("Te rugam sa introduci un numar mai mic de "+total);
		return false;
	}
	else if(Math.ceil(introdus) <= 0){
		alert("Te rugam sa introduci un numar mai mare de 0");
		return false;
	}
	else{
		return true;
	}
}