// LILIA HIV PRO TRADE Default JavaScript Document :: By ITN Solutions

function shb(what) {
   if(document.getElementById(what).style.display=="none") {
     document.getElementById(what).style.display="block";
   } else {
     document.getElementById(what).style.display="none";
   }   
}

function contacts_hideAll() {
	document.getElementById("location1").style.display='none';
	document.getElementById("location2").style.display='none';
	document.getElementById("location3").style.display='none';
	document.getElementById("location4").style.display='none';
	document.getElementById("location5").style.display='none';
}

function contacts_show(what) {
	var el_id = "location"+what;
	document.getElementById(el_id).style.display='block';
}

function contacts_toggle(what) {
	var el_id = "location"+what;
	contacts_hideAll()
	document.getElementById(el_id).style.display='block';
}

function submitReqForm(wtd) {
	form_el = document.getElementById('formOnlineRequest');
	if(wtd=='update') {
		if( (form_el.pr_add_name.value=='име на продукт') || (form_el.pr_add_name.value=='') ) { alert("Полето 'име на продукт' не може да бъде празно !"); form_el.pr_add_name.focus(); return false;}
		if( (form_el.pr_add_amount.value=='количество') || (form_el.pr_add_amount.value=='') || (form_el.pr_add_amount.value<1) ) { alert("Полето 'количество' не може да бъде празно или по-малко от 1 !"); form_el.pr_add_amount.focus(); return false;}
		form_el.act.value='form.update';
	} else if(wtd=='save') {
		form_el.act.value='form.save';
	} else {
		// if( (form_el.delivery_of.value=='име на фирма') || (form_el.delivery_of.value=='') ) { alert("Полето 'За доставяне на' не може да бъде празно. Моля попълнете го !"); form_el.delivery_of.focus(); return false;}
		if( (form_el.needs_of.value=='лице за контакт') || (form_el.needs_of.value=='') ) { alert("Полето 'за нуждите на' не може да бъде празно. Моля попълнете го !"); form_el.needs_of.focus(); return false;}
		if( (form_el.contact_phone.value=='') ) { alert("Моля въведете телефон за обратна връзка в полето 'телефон за връзка' !"); form_el.contact_phone.focus(); return false;}
		form_el.act.value='form.submit';
	}
	form_el.submit();
}


function submitNewsLetterForm() {
	inp_val = document.getElementById('nlEmail').value;
	if(isValidEmail(inp_val)) {
		return true;	
	} else {
		alert('Въвели сте невалиден E-mail адрес.');
		return false;
	}
}
 
function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function check_is_email_available(email)
{	
  if(checkemail(email))
  {
  	document.getElementById("is_email").innerHTML="&nbsp;&nbsp;ok";		  
  }else
  {
  	document.getElementById("is_email").innerHTML="&nbsp;&nbsp;невалиден";  	
  }
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
} 

function checkemail(email){
var str=email
var filter=/^.+@.+\..{2,5}$/ 
	if (filter.test(str))
	{
		return false;
	}
	else
	{
	return true;
	}
}
function checkphone(numer){
var phonenumber=new RegExp("\\d{10}", number)

	if (phonenumber)
	{
		alert("true");
		return true;
	}
	else
	{
		alert("false");
	return false;
	}
}

function isvalid_request()
{
	if (checkphone(document.getElementById("tel_num").value)) 
	{
		return false;
	}else
	{
		return false;
	}
	return false;
}
