

function Okienko()
{
	this.imagePath = "imageFiles/Okienko.png";
	this.closeButton = "imageFiles/close.png";
	this.signUp = "imageFiles/signup.png";
	this.emailTextArea="imageFiles/emailTextArea.png";
}

function onCloseButtonClick() 
{
	closeDocument();
}

 function onSignUpButtonClick(textID)
{
	var textObject = document.getElementById(textID);
	if (textObject)
	{
		PostEmailAddresstoConstantContact(textObject.value);
	}
	
}

function PostEmailAddresstoConstantContact(emailAddress)
{
//Do some posting here.	
}


function closeDocument()
{
	document.close();
}

function onLoadMainWindow()
{
	
}

function checkEmailAddress()
{     
		var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
		     if (document.getElementById("id_inputField").value.search(emailRegEx) == -1) {
		          return false;
		     }
		     else {
		          return true;
		     }
}

function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}

function postEmailAddress()
{
	var obj = document.getElementById("id_inputField");
	if (obj)
	{
		var mypostrequest=new ajaxRequest();
		mypostrequest.onreadystatechange=function(){
		if (mypostrequest.readyState==4){
			if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
				document.getElementById("result").innerHTML=mypostrequest.responseText;
				}
			else{
				alert("An error has occured making the request");
			}
			}
		}	
	var emailAddress=obj.value;
	var contactList =encodeURIComponent("KidsExpressTrainLightBox");
	var parameters="emailAddress="+emailAddress+"&contactListName="+contactList;
	mypostrequest.open("POST", "scripts/update.php", true);
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	mypostrequest.send(parameters);
	}
}

function submitEmailAddressToConstantContact(address)
{


//		mypostrequest.onreadystatechange=function(){
//		if (mypostrequest.readyState==4){
//			if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
//				document.getElementById("result").innerHTML=mypostrequest.responseText;
//				}
//			else{
//				alert("An error has occured making the request");
//			}
//			}
//		}	
	var mypostrequest=new ajaxRequest();
	var emailAddress=address;
	var contactList =encodeURIComponent("KidsExpressTrainLightBox");
	var parameters="emailAddress="+emailAddress+"&contactListName="+contactList;
	mypostrequest.open("POST", "scripts/update.php", true);
	mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	mypostrequest.send(parameters);
}


function getBaseUpdateURL()
{
	return "scripts/update.php";
}

function getProtocol()
{
	return document.location.protocol;
}

$(document).ready(function(){
	this.imagePath = "imageFiles/Okienko.png";
	this.closeButton = "imageFiles/close.png";
	this.signUp = "imageFiles/signup.png";
	this.emailTextArea="imageFiles/emailTextArea.png";
	$("#lightbox, #lightbox-panel").fadeIn(300);
   
   
	$("#okienko").click(function(){
		var obj = document.getElementById("id_inputField");
		   if (obj.value != "Enter Email Address!!")
		   {
				if (!checkEmailAddress())
				{
					obj.value = "";
				}
		   }
		   if (obj.value == "") {
			   obj.value = "Enter Email Address!!";
		   }
	});

		   
	   $("a#close").click(function(){
	   $("#lightbox, #lightbox-panel").fadeOut(300);});
	   
	   $("a#signup").click(function(){
		   if (checkEmailAddress() == true)
		   {
			   $("#lightbox, #lightbox-panel").fadeOut(300);
			   postEmailAddress();
			   
		   }
		   else
		   {
			   alert("Please Enter valid Email address");
		   }
		   });
	   
	   $("#id_inputField").hover(
			   function(){
		   $(this).addClass("overTextArea");
	   },
	   function() {
		   $(this).removeClass("overTextArea");
	   }
);
	   $("#id_inputField").click(function(){
		   var obj = document.getElementById("id_inputField");
		   if (obj.value == "Enter Email Address!!")
		   {
			   obj.value = "";
		   }
	   });
});

