function popUp2(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=280,height=171,left = 187,top = 184');");
}
function doLogout(){						
	var ajax = new sack();
	ajax.requestFile = "logout.php";					
    ajax.runAJAX();      				    
    Effect.Fade('topLogin',{afterFinish:changeLogBox,duration:0.5});		    
}

function doLogin() {
	var ajax = new sack();
	ajax.requestFile = "login.php";					
	ajax.element = 'errorReport';
	ajax.method = "POST";
	ajax.setVar("email", document.topForm.username.value);
	ajax.setVar("password", document.topForm.password.value);
	ajax.onCompletion = loginReturn;  
	ajax.runAJAX();      		   
}

function loginReturn() {
	if(document.getElementById("errorReport").innerHTML.indexOf("The information you provided was not correct. Please try again.")>-1){
		alert(document.getElementById("errorReport").innerHTML);
	}else{
		Effect.Fade('topLogin',{afterFinish:fillLogBox,duration:0.5});		    	
	}
}

function fillLogBox(){
	document.getElementById("topLogin").innerHTML = "WELCOME, "+document.getElementById("errorReport").innerHTML+" <br /><br />\n";
	document.getElementById("topLogin").innerHTML += "<a href=\"javaScript:doLogout();\" class=\"loggedInBtn\"><img src=\"images/buttons/logout.jpg\" alt=\"Log Out\" border=\"0\" /></a>&nbsp;&nbsp;\n";
	document.getElementById("topLogin").innerHTML += "<a href=\"cart.php\" class=\"loggedInBtn\"><img src=\"images/buttons/viewCart.jpg\" alt=\"View Cart\" border=\"0\" /></a>&nbsp;&nbsp;\n";
	document.getElementById("topLogin").innerHTML += "<a href=\"changepassword.php\" class=\"loggedInBtn\"><img src=\"images/buttons/changePword.jpg\" alt=\"Change Password\" border=\"0\" /></a>\n";
	Effect.Appear('topLogin',{duration:0.5});	
}

function changeLogBox(){
	document.getElementById("topLogin").innerHTML = "USER LOGIN<br /><br />\n";
	document.getElementById("topLogin").innerHTML += "<input type=\"text\" name=\"username\" value=\"Email\" class=\"topLoginField\" onClick=\"if(this.value=='Email')this.value='';\" onBlur=\"if(this.value=='')this.value='Email';\" />&nbsp;&nbsp;\n";
	document.getElementById("topLogin").innerHTML += "<input type=\"password\" name=\"password\" value=\"Password\" class=\"topLoginField\" onClick=\"if(this.value=='Password')this.value='';\" onBlur=\"if(this.value=='')this.value='Password';\" />\n";
	document.getElementById("topLogin").innerHTML += "<a href=\"javaScript:doLogin();\" class=\"topLoginBtn\" id=\"topLoginHack\"><img src=\"images/buttons/login.jpg\" alt=\"Login\" border=\"0\" /></a><br /><a href=\"passwordrecovery.php\" class=\"forgotPword\">Forgot Password?</a>\n";
	Effect.Appear('topLogin',{duration:0.5});		    
}

function addMailingList() {
	if(emailValidate(document.topForm.mailingListEmail.value)){
		var ajax = new sack();
		ajax.requestFile = "mailingList.php";					
		ajax.element = 'errorReport';
   		ajax.method = "POST";
   		ajax.setVar("email", document.topForm.mailingListEmail.value);
   		ajax.onCompletion = mailingReturn;  
   		ajax.runAJAX();  
	}else{
		alert('You must provide a valid EMAIL address');
	}
}

function mailingReturn() {
	alert(document.getElementById("errorReport").innerHTML);
	if(document.getElementById("errorReport").innerHTML.indexOf("already")==-1){
		document.topForm.mailingListEmail.value = "Email Address";
	}
}

function changePassword() {
	document.username.setAttribute("type","text");
	document.password.setAttribute("type","text");
}

function contactSubmit(){
	errors = new Array();
	
	if(empty(document.contactForm.name)){
		errors.push('You must provide a NAME\n');
	}

	if((empty(document.contactForm.email))||(!emailValidate(document.contactForm.email.value))){
		errors.push('You must provide a valid EMAIL address\n');
	}
	
	if(empty(document.contactForm.message)){
		errors.push('You must provide a MESSAGE\n');
	}
	
	if(errors.length>0){
		errorDisplay = new String();
		for(i=0;i<errors.length;i++){
			errorDisplay += errors[i];
		}	
		alert(errorDisplay);	
	}else{
		document.contactForm.submit();
	}
}