    function mailcheck(str) {
      if(str=="ttuleva") document.getElementById("error_msg").innerHTML = "Въведете валиден мейл";
    }
    
    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) return false;
    	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
  		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)  return false;
      if (str.indexOf(at,(lat+1))!=-1) return false;
      if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
      if (str.indexOf(dot,(lat+2))==-1) return false;
      if (str.indexOf(" ")!=-1) return false;
 		   return true;					
    }

    function validate_clients() { 
      submitOK="true";
      var notifier = document.getElementById("notifier").value;
      var mail = document.getElementById("mail").value;
      var company = document.getElementById("company").value;
      var address = document.getElementById("address").value;
      var contact_person = document.getElementById("contact_person").value;
      var phone = document.getElementById("phone").value;
      var production_title = document.getElementById("production_title").value;
      var s_title = document.getElementById("s_title").value;
      var s_info = document.getElementById("s_info").value;
      var appliance_id = document.getElementById("appliance_id").options[document.getElementById("appliance_id").selectedIndex].value;
      var usage_id = document.getElementById("usage_id").options[document.getElementById("usage_id").selectedIndex].value;
      var duration = document.getElementById("duration").value;
      var ver = document.getElementById("ver").value;
      var use_as_id = document.getElementById("use_as_id").options[document.getElementById("use_as_id").selectedIndex].value;
      var area = document.getElementById("area").value;
      var timelimit = document.getElementById("timelimit").value;
      var comment = document.getElementById("comment").value;
      var media = document.forms[0].media_type;
      var media_txt="";
      for (i=0;i<media.length;i++) {
        if (media[i].checked) media_txt = media_txt + " " + media[i].value;
      }
      var media_other = document.getElementById("media_other").value;

      var flag = notifier=="" || mail=="" || company=="" || address=="" || contact_person=="" || 
                 phone=="" || production_title=="" || s_title=="" || s_info=="" || appliance_id=="" || 
                 usage_id=="" || duration=="" || ver=="" || use_as_id=="" || area=="" || timelimit=="" ||
                 comment=="" || (media_txt=="" && media_other=="");
      if(flag) {
        if(notifier=="") document.getElementById("notifier").style.backgroundColor="lightyellow";
        if(mail=="") document.getElementById("mail").style.backgroundColor="lightyellow";
        if(company=="") document.getElementById("company").style.backgroundColor="lightyellow";
        if(address=="") document.getElementById("address").style.backgroundColor="lightyellow";
        if(contact_person=="") document.getElementById("contact_person").style.backgroundColor="lightyellow";
        if(phone=="") document.getElementById("phone").style.backgroundColor="lightyellow";
        if(production_title=="") document.getElementById("production_title").style.backgroundColor="lightyellow";
        if(s_title=="") document.getElementById("s_title").style.backgroundColor="lightyellow";
        if(s_info=="") document.getElementById("s_info").style.backgroundColor="lightyellow";
        if(duration=="") document.getElementById("duration").style.backgroundColor="lightyellow";
        if(ver=="") document.getElementById("ver").style.backgroundColor="lightyellow";
        if(area=="") document.getElementById("area").style.backgroundColor="lightyellow";
        if(timelimit=="") document.getElementById("timelimit").style.backgroundColor="lightyellow";
        if(comment=="") document.getElementById("comment").style.backgroundColor="lightyellow";
        if(appliance_id=="") document.getElementById("appliance_id").style.backgroundColor="lightyellow";
        if(usage_id=="") document.getElementById("usage_id").style.backgroundColor="lightyellow";
        if(use_as_id=="") document.getElementById("use_as_id").style.backgroundColor="lightyellow";
        if(media_txt=="" && media_other=="") document.getElementById("media_other").style.backgroundColor="lightyellow";
        document.getElementById("error_msg").innerHTML = "Всички полета са задължителни";
        submitOK="false";
      } else {
        if(echeck(mail)===false)  {
          document.getElementById("error_msg").innerHTML = "Error: Incorrect e-mail!";
          document.getElementById("mail").style.backgroundColor="lightyellow";
          submitOK="false";
        }
      }
      if (submitOK=="false")  return false;
    }

    function validate_performers() { 
      submitOK="true";
      var notifier = document.getElementById("notifier").value;
      var mail = document.getElementById("mail").value;
      var phone = document.getElementById("phone").value;
      var desc = document.getElementById("desc").value;
      var pf = document.getElementById("pf").checked;
      var au = document.getElementById("au").checked;
      var pr = document.getElementById("pr").checked;
      var pic_1 = document.getElementById("pic_1").value;
      var pic_2 = document.getElementById("pic_2").value;
      var pic_3 = document.getElementById("pic_3").value;
      var mp3_1 = document.getElementById("mp3_1").value;
      var mp3_2 = document.getElementById("mp3_2").value;
      var mp3_3 = document.getElementById("mp3_3").value;
      var flag = notifier=="" || mail=="" || phone=="" || desc=="" || 
                 (!pf && !au && !pr) || 
                 (pic_1=="" && pic_2=="" && pic_3=="") || (mp3_1=="" && mp3_2=="" && mp3_3=="");
      if(flag) {
        if(notifier=="") document.getElementById("notifier").style.backgroundColor="lightyellow";
        if(mail=="") document.getElementById("mail").style.backgroundColor="lightyellow";
        if(phone=="") document.getElementById("phone").style.backgroundColor="lightyellow";
        if(desc=="") document.getElementById("desc").style.backgroundColor="lightyellow";
        if(pic_1=="" && pic_2=="" && pic_3=="") {
          document.getElementById("pic_1").style.backgroundColor="lightyellow";
          document.getElementById("pic_2").style.backgroundColor="lightyellow";
          document.getElementById("pic_3").style.backgroundColor="lightyellow";
        }
        if(mp3_1=="" && mp3_2=="" && mp3_3=="") {
          document.getElementById("mp3_1").style.backgroundColor="lightyellow";
          document.getElementById("mp3_2").style.backgroundColor="lightyellow";
          document.getElementById("mp3_3").style.backgroundColor="lightyellow";
        }
        document.getElementById("error_msg").innerHTML = "Всички полета са задължителни";
        submitOK="false";
      } else {
        if(echeck(mail)===false)  {
          document.getElementById("error_msg").innerHTML = "Error: Incorrect e-mail!";
          document.getElementById("mail").style.backgroundColor="lightyellow";
          submitOK="false";
        }
        if(pic_1!="") { 
          var ext = pic_1.substring(pic_1.lastIndexOf('.') + 1);
          if(ext!="gif" && ext!="GIF" && ext!="JPEG" && ext!="jpeg" && ext!="jpg" && ext!="JPG") {
            document.getElementById("error_msg").innerHTML = "Error: Invalid filename!";
            submitOK="false";
          } 
        }
        if(pic_2!="") { 
          var ext = pic_2.substring(pic_2.lastIndexOf('.') + 1);
          if(ext!="gif" && ext!="GIF" && ext!="JPEG" && ext!="jpeg" && ext!="jpg" && ext!="JPG") {
            document.getElementById("error_msg").innerHTML = "Error: Invalid filename!";
            submitOK="false";
          } 
        }
        if(pic_3!="") { 
          var ext = pic_3.substring(pic_3.lastIndexOf('.') + 1);
          if(ext!="gif" && ext!="GIF" && ext!="JPEG" && ext!="jpeg" && ext!="jpg" && ext!="JPG") {
            document.getElementById("error_msg").innerHTML = "Error: Invalid filename!";
            submitOK="false";
          } 
        }
        if(mp3_1!="") { 
          var ext = mp3_1.substring(mp3_1.lastIndexOf('.') + 1);
          if(ext!="mp3" && ext!="MP3" && ext!="ogg" && ext!="OGG") {
            document.getElementById("error_msg").innerHTML = "Error: Invalid filename!";
            submitOK="false";
          } 
        }
        if(mp3_2!="") { 
          var ext = mp3_2.substring(mp3_2.lastIndexOf('.') + 1);
          if(ext!="mp3" && ext!="MP3" && ext!="ogg" && ext!="OGG") {
            document.getElementById("error_msg").innerHTML = "Error: Invalid filename!";
            submitOK="false";
          } 
        }
        if(mp3_3!="") { 
          var ext = mp3_3.substring(mp3_3.lastIndexOf('.') + 1);
          if(ext!="mp3" && ext!="MP3" && ext!="ogg" && ext!="OGG") {
            document.getElementById("error_msg").innerHTML = "Error: Invalid filename!";
            submitOK="false";
          } 
        }
      }
      if (submitOK=="false")  return false;
    }

    function validate_signup() { 
      submitOK="true";
      var mail = document.getElementById("mail").value;
      var name = document.getElementById("name").value;
      var pass = document.getElementById("pass").value;
      var confirmpass = document.getElementById("confirmpass").value;
      var code = document.getElementById("code").value;

      var vvcode = document.getElementById("n<?php echo crypt($_SESSION['secureImage'], "is"); ?>").value;
      
      var flag = (name=="" || mail=="" || pass=="" || confirmpass=="" || code=="" || code==vvcode);
      if(flag) {
        if(mail=="") document.getElementById("mail").style.backgroundColor="lightyellow";
        if(name=="") document.getElementById("name").style.backgroundColor="lightyellow";
        if(pass=="") document.getElementById("pass").style.backgroundColor="lightyellow";
        if(confirmpass=="") document.getElementById("confirmpass").style.backgroundColor="lightyellow";
        if(code=="") document.getElementById("code").style.backgroundColor="lightyellow";
        document.getElementById("error_msg").innerHTML = "Всички полета са задължителни";
        submitOK="false";
      } else {
        if(echeck(mail)===false)  {
          document.getElementById("error_msg").innerHTML = "Error: Incorrect e-mail!";
          document.getElementById("mail").style.backgroundColor="lightyellow";
          submitOK="false";
        }
      }
      return "slkdlskdfc";
      if (submitOK=="false")  return false;
    }

