﻿var Start=0;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
var BorderShow=false;

function ShowTip()
{
    ShowBorder();
    Start=1;
    if(getObj('Name').value=="")
    {
        getObj('Name').focus();
        return false;
    }
    
    if(getObj('FromEmail').value=="")
    {
        getObj('FromEmail').focus();
        return false;
    }
    
    if (!filter.test(getObj('FromEmail').value))
	{
        getObj('FromEmail').focus();
        return false;
	}
	
	if(getObj('ToEmail').value=="")
    {
        getObj('ToEmail').focus();
        return false;
    }
    
    if (!filter.test(getObj('ToEmail').value))
	{
        getObj('ToEmail').focus();
        return false;
	}
	
    if(getObj('Subject').value=="")
    {
        getObj('Subject').focus();
        return false;
    }
    DisableTip();	
  
     var ok = 0;
	  if(confirm('Your email has been sent!  Would you like to subscribe to our hotel e-newsletter to receive updates on specials happening in and around our hotel?'))
	  {
	        ok = 1
    	  //window.getObj("hidMail").value = 1;
	  }        
	 
	 window.getObj("hidMail").value = ok;
	  
		return true;	
}

function ShowSub()
{

    ShowBorder();
    Start=1; 
    if(getObj('Name').value=="")
    {
        getObj('Name').focus();
        return false;
    }
    
    if(getObj('FromEmail').value=="")
    {
       
        getObj('FromEmail').focus();
        return false;
    }
    
     if (!filter.test(getObj('FromEmail').value))
	{
	   
        getObj('FromEmail').focus();
        return false;
	}
    
   
}

function ShowUnSub()
{

//    ShowBorder();
    BorderShow=false;
    getObj('Name').style.borderColor="#C1A478";
    Start=1;
    if(getObj('FromEmail').value=="")
    {
        getObj('FromEmail').focus();
        getObj('FromEmail').style.borderColor="#FF0000";
        return false;
    }
    
    if (!filter.test(getObj('FromEmail').value))
	{
        getObj('FromEmail').focus();
        getObj('FromEmail').style.borderColor="#FF0000";
        return false;
	}
}

function EnableTip(Id)
{

    DisableTip();
    if(Start==1)
    {
	    if(Id.value=="")
	    {
	        Id.parentNode.getElementsByTagName("div")[0].style.display = "inline";
	    }
	    else
	        if (Id.parentNode.getElementsByTagName("div")[2])
	            if(!filter.test(Id.value))
		            Id.parentNode.getElementsByTagName("div")[2].style.display = "inline";
	    if(Id.selectedIndex==0)
            Id.parentNode.getElementsByTagName("div")[0].style.display = "inline";
	}
	Start=1;
}
function DisableTip()
{

    if(BorderShow)
        ShowBorder();		

    var inputs = document.getElementsByTagName("input");
    for (var i=0; i<inputs.length; i++)
    {
		if (inputs[i].parentNode.getElementsByTagName("div")[0])
		    if(inputs[i].parentNode.getElementsByTagName("div")[0].getAttribute("text")=="Validator")
		        inputs[i].parentNode.getElementsByTagName("div")[0].style.display = "none";
		if (inputs[i].parentNode.getElementsByTagName("div")[2])
		    if(inputs[i].parentNode.getElementsByTagName("div")[2].getAttribute("text")=="Validator")
		        inputs[i].parentNode.getElementsByTagName("div")[2].style.display = "none";
    }
	
	var TextAreas = document.getElementsByTagName("textarea");
    for (var i=0; i<TextAreas.length; i++)
    {
		if (TextAreas[i].parentNode.getElementsByTagName("div")[0])
		    if(TextAreas[i].parentNode.getElementsByTagName("div")[0].getAttribute("text")=="Validator")
		        TextAreas[i].parentNode.getElementsByTagName("div")[0].style.display = "none";
    }
    
    var Selects = document.getElementsByTagName("select");
    for (var i=0; i<Selects.length; i++)
    {
		if (Selects[i].parentNode.getElementsByTagName("div")[0])
		    if(Selects[i].parentNode.getElementsByTagName("div")[0].getAttribute("text")=="Validator")
		        Selects[i].parentNode.getElementsByTagName("div")[0].style.display = "none";
    }
    
}


function ShowBorder()
{
    BorderShow=true;
    var inputs = document.getElementsByTagName("input");
    for (var i=0; i<inputs.length; i++)
    {
    
    	if (inputs[i].parentNode.getElementsByTagName("div")[0])
		    if(inputs[i].parentNode.getElementsByTagName("div")[0].getAttribute("text")=="Validator")
		        if(inputs[i].value=="")
                    inputs[i].style.borderColor="#FF0000";
	            else
	                inputs[i].style.borderColor="#C1A478";
	                
		if (inputs[i].parentNode.getElementsByTagName("div")[2])
		    if(inputs[i].parentNode.getElementsByTagName("div")[2].getAttribute("text")=="Validator")
                if(!filter.test(inputs[i].value))
                    inputs[i].style.borderColor="#FF0000";
	            else
	                inputs[i].style.borderColor="#C1A478";
    }
}

function HideBorder()
{
//    if(getObj('FromEmail').value=="")
//        getObj('FromEmail').style.borderColor="#FF0000";
//    else
//        if (!filter.test(getObj('FromEmail').value))
//            getObj('FromEmail').style.borderColor="#FF0000";
//        else
//            getObj('FromEmail').style.borderColor="#7F9DB9";
}


    
//        if(inputs[i].getAttribute("validator"))
//        {
//            if(inputs[i].value=="")
//                inputs[i].style.borderColor="#FF0000";
//	        else
//	            inputs[i].style.borderColor="#7F9DB9";
//        }
function blockSpace(ctrl,e) 
{  

  var isIE = document.all?true:false;
  var isNS = document.layers?true:false;	 
  var key = (isIE) ? window.event.keyCode : e.which; 
  var position =ctrl.value.charAt(0);

   if(key == 32 &&  ctrl.value.length == 0 && position=='') 
    { 
      return false;
    }
  
   else
   {  
     return true;  
  } 
}