/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("E-mail je v chybném formátu.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("E-mail je v chybném formátu.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("E-mail je v chybném formátu.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("E-mail je v chybném formátu.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("E-mail je v chybném formátu.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("E-mail je v chybném formátu.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("E-mail je v chybném formátu.")
		    return false
		 }

 		 return true					
	}

function strtr (str, from, to) {
    // http://kevin.vanzonneveld.net
    // +   original by: Brett Zamir (http://brett-zamir.me)
    // +      input by: uestla
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Alan C
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: $trans = {'hello' : 'hi', 'hi' : 'hello'};
    // *     example 1: strtr('hi all, I said hello', $trans)
    // *     returns 1: 'hello all, I said hi'
    // *     example 2: strtr('äaabaåccasdeöoo', 'äåö','aao');
    // *     returns 2: 'aaabaaccasdeooo'
    // *     example 3: strtr('ääääääää', 'ä', 'a');
    // *     returns 3: 'aaaaaaaa'
    // *     example 4: strtr('http', 'pthxyz','xyzpth');
    // *     returns 4: 'zyyx'
    // *     example 5: strtr('zyyx', 'pthxyz','xyzpth');
    // *     returns 5: 'http'
 
    var fr = '', i = 0, j = 0, lenStr = 0, lenFrom = 0;
    var tmpFrom = [];
    var tmpTo   = [];
    var ret = '';
    var match = false;
 
    // Received replace_pairs?
    // Convert to normal from->to chars
    if (typeof from === 'object') {
        for (fr in from) {
            tmpFrom.push(fr);
            tmpTo.push(from[fr]);
        }
 
        from = tmpFrom;
        to   = tmpTo;
    }
    
    // Walk through subject and replace chars when needed
    lenStr  = str.length;
    lenFrom = from.length;
    for (i = 0; i < lenStr; i++) {
        match = false;
        for (j = 0; j < lenFrom; j++) {
            if (str.substr(i, from[j].length) == from[j]) {
                match = true;
 
                // Fast forward
                i = (i + from[j].length)-1;
                
                break;
            }
        }
        
        if (false !== match) {
            ret += to[j];
        } else {
            ret += str[i];
        }
    }
 
    return ret;
}

function ValidateFormm(){
  var email = document.getElementById('eemail');
  if ((email.value==null)||(email.value=="")||(email.value=="Váš e-mail")){
		alert("Zadejte prosím váš e-mail.");
		email.focus();
		return false;
	}
	if (echeck(email.value)==false){
		//emailID.value=""
		email.focus();
		return false;
	}
	return true;
	// nejak nefunguje :(
	//var from = 'áäčďéěëíňóöřšťúůüýž';
	//var to = 'aacdeeeinoorstuuuyz';
	//document.getElementById('newsletter').r[name].value = strtr (document.getElementById('newsletter').r[name].value, from, to);
 }
 function ValidateFormmm(){
	//var emailID=document.getElementById('newsletter').eemail
	
	if ((document.getElementById('newsletter').email.value==null)||(document.getElementById('newsletter').email.value=="")||(document.getElementById('newsletter').email.value=="Váš e-mail")){
		alert("Zadejte prosím váš e-mail.")
		document.getElementById('newsletter').email.focus()
		return false
	}
	if (echeck(document.getElementById('newsletter').email.value)==false){
		//emailID.value=""
		document.getElementById('newsletter').email.focus()
		return false
	}
	return true
 }

function ValidateForm(){
	var emailID=document.newsletter.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Zadejte prosím váš e-mail.")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		//emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

