﻿// JScript File
function toggleAnaliza(subl)
{
    var i=1;
	if ($(subl).className=='lisub dB') 
	{
		$(subl).className='lisub dN';
	}
	else if ($(subl).className!='lisub dB')
	{
		$(subl).className='lisub dB';		
	}
}

function toggleContactForm(sub)
{
	if ($(sub).style.display!='block')
	{
		$(sub).style.display='block';		
	}
	else if ($(sub).style.display=='block') 
	{
		$(sub).style.display='none';
	}
}

function sendContactForm()
{
    var txName = document.getElementById("txName").value;
    var txEmail = document.getElementById("txEmail").value;
    var txPhone = document.getElementById("txPhone").value;
	var txFax = document.getElementById("txFax").value;
    
    var error = "";
    
    if (!isNotEmpty(txName))
    {
       error += getJSPH("Contact_CompletatiNume ");
    }
    
    if (isNotEmpty(txEmail))
    {
        if (!isEmail(txEmail))
        {
             error += getJSPH("Contact_EmailValid");
        }
    }
    else
    { 
        error += getJSPH("Contact_CompletatiEmail");
    }
    
	if (isNotEmpty(txPhone))
    {
        if (!isPhoneValid(txPhone))
        {
           error +=getJSPH("Contact_TelefonValid ");
        }
    }
    else
    { 
        error +=getJSPH("Contact_CompletatiTelefon ");
    }
	if (isNotEmpty(txFax))
    {
        if (!isPhoneValid(txFax))
        {
            error +=getJSPH("Contact_FaxValid ");
        }
    }
  
    
    if (error.length > 0) 
    {
        error = getJSPH("Contact_RemediatiProblemele ") + error;
        alert(error);
    }
    else
    {  
        $("hAction").value = "SaveContact";
        //alert('before submit: hAction = ' + $("hAction").value);
        document.getElementById("frmMain").submit();
    }
}
function isNotEmpty(val)
{
  return ((trim(val)).length>0);
}

function isEmail(val)
{
    if (!isNotEmpty(val)) {
        return true;
    }
	else {
	    var m = val.match(/\w+[.]?\w*@\w+[.]\w+/g);
	    return ((m!=null)&&(m.length>0));
	}
}

function isValidPhoneChar(c)
{
	if((c == "0")||(c == "1")||(c == "2")||(c == "3")||(c == "4")) return true;
	if((c == "5")||(c == "6")||(c == "7")||(c == "8")||(c == "9")) return true;
	if((c == '/')||(c == '-')||(c == '+')) return true;
	if((c == '(')||(c == ')')||(c == ' ')) return true;
	return false;
}

function isPhoneValid(value)
{
	var i=0;
	var s = new String();
	var c='';
	s = value.toString()
	for(i=0;i<s.length;i++)
	{
		c = s.substring(i,i+1);
		if(!isValidPhoneChar(c))
		{
			return false;
		}
	}
	return true;
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function goToHome()
{
    document.location.href = "Default.aspx";
}

