﻿window.onload=function()
{
    $("ContactCtrl_txMessage").focus();
}

function sendContactForm()
{
    var txMessage = document.getElementById("ContactCtrl_txMessage").value;
	var txName = document.getElementById("ContactCtrl_txName").value;
    var txCompany = document.getElementById("ContactCtrl_txCompany").value;
	var txPhone = document.getElementById("ContactCtrl_txPhone").value;
	var txFax = document.getElementById("ContactCtrl_txFax").value;
	var txEmail = document.getElementById("ContactCtrl_txEmail").value;
	
    
    var error = "";
    
    if (!isNotEmpty(txName))
    {
        error += getJSPH("Contact_CompletatiNume");
    }
	
	if (!isNotEmpty(txCompany))
    {
        error += getJSPH("Contact_CompletatiCompania");
    }
	
	if (!isNotEmpty(txPhone) || !isPhoneValid(txPhone))
    {
        error += getJSPH("Contact_CompletatiTelefonValid");
    }

	if (!isNotEmpty(txEmail))
    {
		error += getJSPH("Contact_CompletatiEmailValid");
    }

    if (!isNotEmpty(txMessage))
    {
        error += getJSPH("Contact_CompletatiMesaj");
        
    }
    
    if (error.length > 0) 
    {
        error = getJSPH("Contact_VaRugamRemediati") + error;
        alert(error);
    }
    else
    {
        $("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 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";
}