/*--------------------------------------------------------------------
JAVASCRIPT
Version: 	2.0 - 2010
author: 	Burocratik (alexandre gomes)
email: 		alex@burocratik.com
website: 	http://www.burocratik.com
-----------------------------------------------------------------------*/
/* =WINDOW.onload
-----------------------------------------------------------------------*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != "function") {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/*-----------------------------------------------------------------------
=Limpar Formulario de Pesquisa
-----------------------------------------------------------------------*/
function limparForms(qualform) {
  for (var i=0; i<qualform.elements.length; i++) {
    var element = qualform.elements[i];
    if (element.type == "submit")continue; //se o elemento for um submit passa a proxima iteracao do loop
	  if (element.type == "button") continue; //se o elemento for um button passa a proxima iteracao do loop
    if (!element.defaultValue) continue;
    element.onfocus = function() {
    if (this.value == this.defaultValue) {
      this.value = "";
     }
    }
    element.onblur = function() {
      if (this.value == "") {
        this.value = this.defaultValue;
      }
    }
  }
}
//passar cada object form para a funcao limparForms()
function iniciarForms() {
	formId = document.forms["newsletter-form"]; //forms k quero que possam ser limpos
  for (var i=0; i<document.forms.length; i++) {
    if (document.forms[i]!= formId) continue; //se nao e' o form k defini, sai do loop
    var thisform = document.forms[i];
    limparForms(thisform);
  }
}

/*-----------------------------------------------------------------------
 =NEWSLETTER VALIDACAO: without jquery
-----------------------------------------------------------------------*/
function iniciarNewsletter() {
  if (!document.getElementById) return false;
	if (!document.getElementById("newsletter-form")) return false;
  var form = document.getElementById("newsletter-form");
	var email = document.getElementById("dhkilt-dhkilt");
  //
	email.onblur=function(){validateEmail();}
	//On Submitting
	form.onsubmit = function(){
		if(validateEmail()){
     return true;
		}else {
     return false;
		}
	};
  //
	function validateEmail(){
  	var a = email.value;
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
  	if(filter.test(a)){
  	  email.style.color ="#30a7c5";
     	return true;
  	}else{
      email.style.color ="red";
			return false;
  	}
	};
}
/* =Preparar Eventos
-----------------------------------------------------------------------*/
addLoadEvent(iniciarForms);
addLoadEvent(iniciarNewsletter);

