// Clares functions

$(document).ready(function(){           
			
			  $('a[rel*=facebox]').facebox() 
		
		var vt;
			$(".togglevt").click(function(){
				clearTimeout(vt) 
				$("#vt_content").slideToggle(300);
				$("#login").css("z-index","45");
				$("#nhs_login").css("z-index","45");
				$("#bvt").css("z-index","45");
				$("#vt").css("z-index","50");
				vt = setTimeout(function() {$("#accountName").focus();},1000);
				return false;
			});
			$("#vt_login_close").click(function(){
				$("#vt_content").slideToggle(300);							  
			});
			/*$(".togglevt").mouseout(function(){
				if($("#vt_content").css('display') == "block")
				{ vt = setTimeout(function() {$("#vt_content").slideToggle(300);return false;}, 2000); }
			});
			$("#vt_content").mouseout(function(){
			vt = setTimeout(function() {$("#vt_content").slideToggle(300);return false;}, 2000); 		
			});
			$("#vt_content").mouseover(function(){
			clearTimeout(vt) 	
			});	
			$(".togglevt").mouseover(function(){
			clearTimeout(vt) 	
			});	*/
			
			var t;
			$(".toggle").click(function(){
				clearTimeout(t) 
				$("#login_content").slideToggle(300);
				$("#vt").css("z-index","45");
				$("#nhs_login").css("z-index","45");
				$("#login").css("z-index","50");
				t = setTimeout(function() {$("#email").focus();},1000);
				return false;
				
			});
			$("#login_close").click(function(){
				$("#login_content").slideToggle(300);							  
			});
			
		var nhs;
			$(".nhs_toggle").click(function(){
				clearTimeout(nhs) 
				$("#nhs_login_content").slideToggle(300);
				$("#vt").css("z-index","45");
				$("#login").css("z-index","45");
				$("#bvt").css("z-index","45");
				$("#nhs_login").css("z-index","50");
				nhs = setTimeout(function() {$("#nhs_email").focus();},1000);
				return false;
				
			});
			$("#nhs_login_close").click(function(){
				$("#nhs_login_content").slideToggle(300);							  
			});
			
			
		var bvt;
			$(".togglebvt").click(function(){
				clearTimeout(bvt) 
				$("#bvt_content").slideToggle(300);
				$("#login").css("z-index","45");
				$("#nhs_login").css("z-index","45")
				$("#vt").css("z-index","45");
				$("#bvt").css("z-index","50");
				bvt = setTimeout(function() {$("#bvt_accountName").focus();},1000);
				return false;
			});
			$("#bvt_login_close").click(function(){
				$("#bvt_content").slideToggle(300);							  
			});	
			
			
			

			
			
		
		}); //end the document ready


$(function()  
{ 
	$("#mainmenu li a").mouseout(function() 
	{ 
		window['t'];
		var thesplit = $(this).attr("id").split("_")[1];
		$(this).removeClass("goblack");
		window['t'] = setTimeout(function() { $("#sub_"+thesplit).css("z-index",30); $("#sub_"+thesplit).slideUp(200); return false;}, 200); 		
		
	});
	$("#cat_1").hover(function()
	{ 
		var thesplit = $(this).attr("id").split("_")[1];
		var x = $(this).offset().left;	
		var y = $(this).offset().top + 48;
		var navwidth = $(this).width() + 26;
		
		var subwidth = $("#sub_"+thesplit).width() + 20;
		var winwidth = $(window).width();
		var totals = subwidth + x; 
		var realign = x - subwidth; 
		realign = realign + navwidth;
		var theclass = $(this).attr('class');
		
		if(totals > winwidth)
		{
			if(theclass == "double last")
			{
				realign = realign + 7;	
			}
			$("#sub_"+thesplit).css("left",realign);	
			$("#sub_"+thesplit).css("top",y);
		}
		else
		{
			$("#sub_"+thesplit).css("left",x);
			$("#sub_"+thesplit).css("top",y);
		}
		
		if($("#sub_"+thesplit).css('display') == "none")
		{	$("#sub_"+thesplit).slideDown(400); $("#sub_"+thesplit).css("z-index",30); }
		
	$("#sub_"+thesplit).hover(function() {  $("#cat_"+thesplit).addClass("goblack");clearTimeout(window['t']);	}
	,function() {
		$("#cat_"+thesplit).removeClass("goblack");
		$("#sub_"+thesplit).css("z-index",30);
		$("#sub_"+thesplit).slideUp(200);
	});	
	
	});
});
function checkform()
{	
	var errors = "";
	$(".required").each(function (i) 
	{
		if(this.val() == "")
		{
			errors += this.attr('title')+'<br />';
			this.css('border-color','#FF0000');			
			$('#label_name').css('color', '#FF0000');
		}
	
	});
	if(errors!="")
	{
		$('#error').css('display', 'block');
		$('#error').html(errors);
		return false;	
	}
	else
	{
		
	}
}

function checknhs()
{
	var errors = "";
	
	if($('#nhs_accountName').val() == "") 
	{ 
		errors += "Missing Account Name<br />";	
		$('#nhs_accountName').css('border-color', '#FF0000');
		$('#label_nhs_accountName').css('color', '#FF0000');
	}				
	if($('#nhs_username').val() == "") 
	{ 
		errors += "Missing Username<br />";	
		$('#nhs_username').css('border-color', '#FF0000');
		$('#label_nhs_username').css('color', '#FF0000');
	}		
	if($('#nhs_password').val() == "") 
	{ 
		errors += "Missing Password";
		$('#nhs_password').css('border-color', '#FF0000');
		$('#label_nhs_password').css('color', '#FF0000');
	}	
	if(errors!="")
	{
		$('#nhs_login_error').css('display', 'block');
		$('#nhs_login_error').html(errors);		
		return false;	
	}
	else
	{
		$("#nhs_login_success").css('display','block');
		$("#nhs_login_content p.info").css('display','none');
		$("#nhs_login_error").css('display','none');
	}
}

function checkbvt()
{
	var errors = "";
	
	if($('#bvt_accountName').val() == "") 
	{ 
		errors += "Missing Account Name<br />";	
		$('#bvt_accountName').css('border-color', '#FF0000');
		$('#label_bvt_accountName').css('color', '#FF0000');
	}				
	if($('#bvt_username').val() == "") 
	{ 
		errors += "Missing Username<br />";	
		$('#bvt_username').css('border-color', '#FF0000');
		$('#label_bvt_username').css('color', '#FF0000');
	}		
	if($('#bvt_password').val() == "") 
	{ 
		errors += "Missing Password";
		$('#bvt_password').css('border-color', '#FF0000');
		$('#label_bvt_password').css('color', '#FF0000');
	}	
	if(errors!="")
	{
		$('#login_bvt_error').css('display', 'block');
		$('#login_bvt_error').html(errors);		
		return false;	
	}
	else
	{
		$("#bvt_success").css('display','block');
		$("#bvt_content p.info").css('display','none');
		$("#login_bvt_error").css('display','none');
		
		
		
	}
	
}



function checkvtlogin()
{
	var errors = "";
	
	if($('#accountName').val() == "") 
	{ 
		errors += "Missing Account Name<br />";	
		$('#accountName').css('border-color', '#FF0000');
		$('#label_accountName').css('color', '#FF0000');
	}				
	if($('#username').val() == "") 
	{ 
		errors += "Missing Username<br />";	
		$('#username').css('border-color', '#FF0000');
		$('#label_username').css('color', '#FF0000');
	}		
	if($('#vt_password').val() == "") 
	{ 
		errors += "Missing Password";
		$('#vt_password').css('border-color', '#FF0000');
		$('#label_vt_password').css('color', '#FF0000');
	}	
	if(errors!="")
	{
		$('#login_vt_error').css('display', 'block');
		$('#login_vt_error').html(errors);		
		return false;	
	}
	else
	{
		$("#vt_success").css('display','block');
		$("#vt_content p.info").css('display','none');
		$("#login_vt_error").css('display','none');
	}
	
}
function checklogin()
{
	var errors = "";
	
	if($('#email').val() == "") 
	{ 
		errors += "Missing Email<br />";	
		$('#email').css('border-color', '#FF0000');
		$('#label_email').css('color', '#FF0000');
	}				
	if($('#password').val() == "") 
	{ 
		errors += "Missing Password<br />";	
		$('#password').css('border-color', '#FF0000');
		$('#label_password').css('color', '#FF0000');
	}		
	
	if(errors!="")
	{
		$('#login_error').css('display', 'block');
		$('#login_error').html(errors);	
		return false;	
	}
	else
	{
		$("#login_success").css('display','block');		
		$("#login_error").css('display','none');
		
	}
	
}

function vtselect()
{
	$('#login_form_data').html('<label id="label_accountName" for="accountName">Account name:</label><input type="text" name="accountName" id="accountName" /><br class="clear" /><label id="label_username" for="username">Username:</label><input type="text" name="username" id="username" /><br class="clear" /><label id="label_password" for="password">Password:</label><input type="password" name="password" id="password" /><br class="clear" /><input type="hidden" value="logon" name="submit_action" /><input type="submit" onclick="return checkvtlogin()" class="submit" name="submit" value="" />');		
	$("#login_form").attr("action","http://clares.opweb.co.uk/logon.asp"); 
	$("#login_error").css('display','none');
	$("#accountName").focus();
}
function neworder()
{	
	$("#cards_login_form").attr("action","http://clares.opweb.co.uk/logon.asp"); 	
}
function reorder()
{
	$("#cards_login_form").attr("action","http://clares.opweb.co.uk/logon.asp"); 	
}
function checkcardslogin()
{
	var errors = "";
	
	if($('#cards_company').val() == "") 
	{ 
		errors += "Missing Company Name<br />";	
		$('#cards_company').css('border-color', '#FF0000');
		$('#label_cards_company').css('color', '#FF0000');
	}				
	if($('#cards_user_name').val() == "") 
	{ 
		errors += "Missing Username<br />";	
		$('#cards_user_name').css('border-color', '#FF0000');
		$('#label_cards_user_name').css('color', '#FF0000');
	}		
	if($('#cards_password').val() == "") 
	{ 
		errors += "Missing Password<br />";	
		$('#cards_password').css('border-color', '#FF0000');
		$('#label_cards_password').css('color', '#FF0000');
	}	
	if($('#order_new:checked').val() == null && $('#order_re:checked').val() == null)
	{
		errors += "Is this a new or re-order?<br />";	
		
		$('#label_order_new').css('color', '#FF0000');
		
		$('#label_order_re').css('color', '#FF0000');
	}
	if(errors!="")
	{
		$('#cards_login_error').css('display', 'block');
		$('#cards_login_error').html(errors);	
		return false;	
	}
	
	
}
function neworder()
{
	$("#cards_login_form").attr("action","http://www.printplatform.co.uk/cgi-bin/displayDesign.pl"); 
	$("#whattodo").val('DISPLAYDESIGN');
}
function reorder()
{
	$("#cards_login_form").attr("action","http://www.printplatform.co.uk/cgi-bin/displayControls.pl"); 
	$("#whattodo").val('SELECTPREVIOUSORDER');		
}
function resetform()
{
	$('#login_form_data').html('<label id="label_email" for="email">Email address:</label><input type="text" name="email" id="email" /><br class="clear" /><label id="label_password" for="password">Password:</label><input type="password" name="password" id="password" /><br class="clear" /><input type="submit" onclick="return checklogin()" class="submit" name="submit" value="" />');		
	$('#c_vt').attr("checked",false);
	$('#c_bvt').attr("checked",false);
	$("#login_form").attr("action","other/easyorder.php");
	$("#login_error").css('display','none');
	$("#email").focus();
}
function printme()
{
	$('#facebox').css('top','0px');
	$('#facebox').css('left','0px');
 	window.print();
	
}
function direct_me(page) { window.location = page }

function checksuform()
{	
	var errors = "";	
	if($('#su_name').val() == "") 
	{ 
		errors += "Please enter your first name<br />";	
		$('#su_name').css('border-color', '#FF0000');
		$('#label_su_name').css('color', '#FF0000');
	}		
	
	if($('#su_email').val() == "") 
	{ 
		errors += "We need your email!<br />";	
		$('#su_email').css('border-color', '#FF0000');
		$('#label_su_email').css('color', '#FF0000');
	}		
	
	if(errors!="")
	{
		$('#su_error').css('display', 'block');
		$('#su_error').html(errors);
		return false;	
	}
	else
	{
		var thename = $("#su_name").val();
		var theemail = $("#su_email").val();
		$.ajax({
				type: "POST",
				url: "submit_subscribe.php",
				data: 	"name=" + thename +"&email=" + theemail,
				success: function(html)
				{
					$("#signup_popup").html(html);
				}
				});	
		return false;
	}
}