// JavaScript Document
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return "Whoops! Looks like you entered an invalid email address";
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return "Whoops! Looks like you entered an invalid email address"
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return "Please enter a valid E-mail Address.";	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
		return "Whoops! Looks like you entered an invalid email address";	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return "Whoops! Looks like you entered an invalid email address";	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
		return "Whoops! Looks like you entered an invalid email address";	 }
	
	 if (str.indexOf(" ")!=-1){
		return "Whoops! Looks like you entered an invalid email address";	 
	}
	
	 return true;					
}

function next_page(is_splash){
  var email;
  email=document.getElementById('email').value;
  email = email.replace(/\+/, "%2B");
  $.fn.colorbox({href:"/second.php?email="+email, open:true, width:"675px", height:"580px", scrolling:false, iframe:true});
  
  if (is_splash) {
    $().bind('cbox_closed', function(){
      document.location.href = $.cookie("onm_splash_original_url");
    });
  }
	//alert("next page");

}

function validate_form(val, is_splash)
{	
	//alert("validation fn def");
	id=document.getElementById(val);
	document.getElementById('emailh').style.display='none';
	if(id.value=='')
	{
		document.getElementById('emailh').style.display='';
		document.getElementById('emailh').innerHTML='Whoops! Looks like you entered an invalid email address';
		id.focus();
		return false;
	}
	
	if(echeck(id.value)!=true)
	{
		document.getElementById('emailh').style.display='';
		document.getElementById('emailh').innerHTML=echeck(id.value);
		id.focus();
		return false;
	}
	
	next_page(is_splash);
	

}

function checkKey(event)
    {


var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if(Key==13) 
	validate_form('email');
  else 

return false;
      
    }



function handleKeyPress(e,form){
var key=e.keyCode || e.which;
	if (key==13)
	{
	form.submit();
	}
}


document.onkeyup = keyCheck;

function keyCheck(e) {
var e = e || window.event;
document.getElementById('email').innerHTML = e.keyCode;
}



function checkEnter(e){ //e is event object passed from function invocation
var characterCode;
//alert(characterCode);
if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
document.forms[0].submit() //submit the form
return false 
}
else{
return true 
}

}

function checkEnter(e){ //e is event object passed from function invocation
var characterCode;
alert(characterCode);
if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
document.forms[0].submit() //submit the form
return false 
}
else{
return true 
}

}

function set_focus()
{
	document.getElementById('email').focus();
}

