function checkForThankYou()
{ 
 if (Get_Cookie("showThankYou")!= null)
    {
         if (Get_Cookie("showThankYou") == "Yes")
         {
            var divThankYou = document.getElementById("divThankYou");
            divThankYou.style.display = "block";
            Set_Cookie( "showThankYou", "No", 1, "/", "", "" );
         }
         else
         {
             var divThankYou = document.getElementById("divThankYou");
             divThankYou.style.display = "none";
             Set_Cookie( "showThankYou", "No", 1, "/", "", "" );
         }
    }
    else
    {
        var divThankYou = document.getElementById("divThankYou");
        divThankYou.style.display = "none";
        Set_Cookie( "showThankYou", "No", 1, "/", "", "" );  
    }
    if (Get_Cookie("ContactGiven") == null)
    {
        Set_Cookie( "ContactGiven", "No", 1, "/", "", "" );
    }   
}

function checkOpenOnLoad()
{
    if (Get_Cookie("OpenOnLoad")!= "")
    {
        if (Get_Cookie("OpenOnLoad")!= null)
        {
            window.location = Get_Cookie("OpenOnLoad");
            Set_Cookie( "OpenOnLoad", "", 1, "/", "", "" );
        }
        else
        {
            Set_Cookie( "OpenOnLoad", "", 1, "/", "", "" );
        }
    }
    if (Get_Cookie("ContactGiven") == null)
    {
        Set_Cookie( "ContactGiven", "No", 1, "/", "", "" );
    } 
  
    var cvr = document.getElementById("cover")
    var dlg = document.getElementById("dialog")
    cvr.style.display = "none"
    dlg.style.display = "none"
     
}


function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );

}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function showPopUp(el)
{
    if (Get_Cookie("ContactGiven") != "Yes")
    {
        var cvr = document.getElementById("cover")
        var dlg = document.getElementById(el)
        cvr.style.display = "block"
        var x = (window.innerWidth / 2) - (dlg.offsetWidth / 2)
        var y = (window.offsetHeight / 2) - (dlg.offsetHeight / 2)              
        dlg.style.display = "block" 
        if (document.body.style.overflow = "hidden")
           {
              cvr.style.width = "100%"
              cvr.style.height = "100%"
           }
    }
    else
    {
     var txtbox = document.getElementById("retURLLocal");
     window.location =   txtbox.value;
    }
}

function closePopUp(el)
{
   var cvr = document.getElementById("cover")
   var dlg = document.getElementById(el)
   cvr.style.display = "none"
   dlg.style.display = "none"
   Set_Cookie( "ContactGiven", "No", 1, "/", "", "" );
}

function mouseOverFileName(url) 
{
 var txtbox = document.getElementById("retURLLocal");
 txtbox.value = url;
}

function checkform(hasThankYouDiv)
{

    
    
 var txtboxfn = document.getElementById("first_name")
 var txtboxln = document.getElementById("last_name")
 var txtboxemail = document.getElementById("email")

	  if (document.contactinfo.first_name.value == ""){
	  alert("First Name is required.");
	  document.contactinfo.first_name.focus()
	  return (false);
      }
      else if (document.contactinfo.last_name.value == ""){
	  alert("Last Name is required.");
	  document.contactinfo.last_name.focus()
	  return (false);
      }
      else if (validate_email(document.contactinfo.email) == false){
	  alert("Email not valid.");
	  document.contactinfo.email.focus()
	  return (false);
      }
	// If the script gets this far through all of your fields
	// without problems, it's ok and you can submit the form
	var txtbox = document.getElementById("retURLLocal");
    Set_Cookie( "ContactGiven", "Yes", 1, "/", "", "" );
    Set_Cookie( "OpenOnLoad", txtbox.value, 1, "/", "", "" );
    
    if (hasThankYouDiv == "1")
    {
       Set_Cookie( "showThankYou", "Yes", 1, "/", "", "" );
    }
    else
    {
       Set_Cookie( "showThankYou", "No", 1, "/", "", "" );
    }
    
    return true;
}
function validate_email(field)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
   return false;
  else {return true;}
  }
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
