﻿window.onload=function()
{
    $("ContactCtrl_txMessage").focus();
}
//function changeForm()
//{
   // var domeniuInteres = document.getElementById("ContactCtrl_ddAddressee").value;
   // if(domeniuInteres == "1" || domeniuInteres == "2")
   // {
   //     document.location.href="/rezervare.aspx?s="+domeniuInteres;
   // }
   // if(domeniuInteres == "7")
   // {
   //     document.location.href="/ContactCursuri.aspx";
   // }
//}
function sendContactForm()
{
    var txName = document.getElementById("ContactCtrl_txName").value;
    var txPrenumeName = document.getElementById("ContactCtrl_txPrenume").value;
    var txEmail = document.getElementById("ContactCtrl_txEmail").value;
    var txPhone = document.getElementById("ContactCtrl_txPhone").value;
    var txMessage = document.getElementById("ContactCtrl_txMessage").value;
    
    
    var error = "";
//     try{
//	    if(document.getElementById("ContactCtrl_ddAddressee").selectedIndex==0)
//	    {
//	        error += getJSPH("Contact_SelectatiDomeniu");
//	    }
//	   
//    }
//    catch (Err){}
    if (!isNotEmpty(txMessage))
    {
        error += getJSPH("Contact_CompletatiMesaj");
        
    }
    if (!isNotEmpty(txName))
    {
        error += getJSPH("Contact_CompletatiNume");
    }
    if (!isNotEmpty(txPrenumeName))
    {
        error += getJSPH("Contact_CompletatiPrenume");
    }
    if (!isNotEmpty(txEmail))
    {
        error += getJSPH("Contact_CompletatiEmail");
    }
    if (isNotEmpty(txEmail) && !isEmail(txEmail))
    {
         error += getJSPH("Contact_EmailValid");
    }
     if (!isNotEmpty(txPhone))
    {
        error += getJSPH("Contact_CompletatiTelefon");
    }
    if (isNotEmpty(txPhone) && !isPhoneValid(txPhone))
    {
        error += getJSPH("Contact_TelefonValid");
    }
   
    
   
	
	
//	if (!document.getElementById("ContactCtrl_ckTermeni").checked)
//    {
//        error += "- Pentru a continua trebuie sa acceptati \"Termenii si conditiile\"\n";//getJSPH("Contact_CompletatiNume");
//    }
//    
    if (error.length > 0) 
    {
        error = getJSPH("Contact_RemediatiProblemele") + error;
        alert(error);
    }
    else
    {
        document.getElementById("ContactCtrl_hAction").value = "SaveContact";
        document.getElementById("frmMain").submit();
    }
}
function isNotEmpty(val)
{
  return ((trim(val)).length>0);
}

function isEmail(val)
{
    if (!isNotEmpty(val)) {
        return true;
    }
	else {
	    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	  
	  //  var m = val.match(/\w+[.]?\w*@\w+[.]\w+/g); //orig.
	    var m = val.match(emailRegEx);
	  
	    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";
}
