// JavaScript Document
function open_Small_Window(page,width,height,query_String)
{
	
	var open_This_Page = page + ".asp?qid=" + query_String
	newWindow = open(open_This_Page, page, "width="+width+",height="+height);
}

function open_Small_Window_Privacy(page,width,height)
{
	
	var open_This_Page = page + ".asp"
	newWindow = open(open_This_Page, page, "scrollbars,width="+width+",height="+height);
}

//Sidebar quick login scripts
function focusTxtBox(thisField)
{
	if ( (document.getElementById( thisField ).value == "username") || (document.getElementById( thisField ).value == "password") )
	{
		document.getElementById( thisField ).value = "";	
	}
}

function blurTxtBox(thisField,thisValue)
{
	if ( document.getElementById( thisField ).value == "" )
	{
		document.getElementById( thisField ).value = thisValue;
	}
}

function isQuickLoginOk()
{
	//alert(document.getElementById( thisField ).value.length);
	if ( (document.getElementById( "fld_Quick_Username" ).value.length < 8) || (document.getElementById( "fld_Quick_Password" ).value.length < 8) )
	{
		alert("Error: Fields must be between 8 and 16 characters!");
		return false;
	}
	else
	{
		return true;
	}
}

//Registration Form Validation
function remove_Error(fieldName)
{
	document.getElementById( fieldName ).style.visibility = 'hidden';	
}

function step_One_Completed()
{
	var username = document.getElementById( "fld_Username" ).value;
	var password = document.getElementById( "fld_Password" ).value;
	var cPassword = document.getElementById( "fld_Con_Password" ).value;
	
	//Are fields empty?
	if ( !fields_Filled_S1(username,password,cPassword) )
	{
		alert("Please fill in the fields marked.  Hover over the marks to see the error!")
		return false;
	}
	
	//Are fields long enough?
	if ( !field_Lengths_Ok_S1(username,password,cPassword) )
	{
		alert("Marked fields were not long enough!")
		return false;
	}
	
	//Do Passwords Match?
	if ( !passwords_Match(password,cPassword) )
	{
		alert("The passwords that were entered do not match!");
		document.getElementById( "fld_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Password_Error" ).alt = 'Password did not match the password confirmation';
		document.getElementById( "fld_C_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_C_Password_Error" ).alt = 'Password confirmation did not match the password';
		document.getElementById( "fld_Password" ).value = "";
		document.getElementById( "fld_Con_Password" ).value = "";		
		return false;
	}
	
	//Any illegal chars?
	if ( !no_Illegal_Chars(username,password,cPassword) )
	{
		alert("Use of illegal characters in marked fields!");
		return false;
	}
	
	//return false;		//This false is for testing only - to be deleted
}

function step_Two_Completed()
{
	var name = document.getElementById( "fld_Name" ).value;
	var address = document.getElementById( "fld_Address_1" ).value;
	var town = document.getElementById( "fld_Town" ).value;
	var county = document.getElementById( "fld_County" ).value;
	var postcode_1 = document.getElementById( "fld_Postcode_1" ).value;
	var postcode_2 = document.getElementById( "fld_Postcode_2" ).value;
	var email = document.getElementById( "fld_Email_Address" ).value;

	
	//Are fields empty?
	if ( !fields_Filled_S2(name,address,town,county,postcode_1,postcode_2,email))
	{
		alert("Please fill in the marked fields!");
		return false;
	}
	//Are postcode fields long enough?
	else if ( !field_Lengths_Ok_S2(postcode_1,postcode_2) )
	{
		alert("Marked fields were not long enough");
		return false;
	}
	//Is email address valid?
	else if ( !valid_Email_Address(email) )
	{
		alert("The email address you entered invalid!");
		return false;
	}
	else
	{
		return true;
	}
	
	//return false;		//This false is for testing only - to be deleted
}

function step_Three_Completed()
{
	var paypal = document.getElementById( "fld_Paypal_Username" ).value;
	var mail_List_Yes = document.getElementById( "fld_Mailing_List_Yes" ).checked;
	var mail_List_No = document.getElementById( "fld_Mailing_List_No" ).checked;
	var t_And_C = document.getElementById( "fld_T_And_C" ).checked;
	
	//Are fields empty?
	if ( !fields_Filled_S3(mail_List_Yes,mail_List_No,t_And_C) )
	{
		alert("Required fields were blank. See markings!");
		return false;
	}
	
	//Has the paypal address field been filled?
	else if ( paypal != "" )
	{
		if ( !valid_Paypal_Address(paypal) )
		{
			alert("Paypal username is invalid!");
			return false;
		}
	}
	
	else
	{
		return true;
	}
	
	//return false;		//This false is for testing only - to be deleted
}

function field_Lengths_Ok_S1(username,password,cPassword)
{
	var err_Count = 0;
	
	if ( username.length < 8 )
	{
		document.getElementById( "fld_Username_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Username_Error" ).alt = 'Username field was not long enough!';
		document.getElementById( "fld_Username" ).value = "";
		err_Count++;
	}
	if ( password.length < 8 )
	{
		document.getElementById( "fld_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Password_Error" ).alt = 'Password field was not long enough!';
		document.getElementById( "fld_Password" ).value = "";
		err_Count++;
	}
	if ( cPassword.length < 8 )
	{
		document.getElementById( "fld_C_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_C_Password_Error" ).alt = 'Password confirmation field was not long enough!';
		document.getElementById( "fld_Con_Password" ).value = "";
		err_Count++;
	}
	
	if ( err_Count > 0 )
	{
		return false
	}
	else
	{
		return true;
	}
}

function field_Lengths_Ok_S2(postcode_1,postcode_2)
{
	var err_Count = 0;
	
	if ( postcode_1.length < 3 )
	{
		document.getElementById( "fld_Postcode_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Postcode_Error" ).alt = "The first part of the postcode you entered is too short!";
		err_Count++;
	}
	
	if ( postcode_2.length < 3 )
	{
		document.getElementById( "fld_Postcode_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Postcode_Error" ).alt = "The second part of the postcode you entered is too short!";
		err_Count++;
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function fields_Filled_S1(username,password,cPassword)
{
	var err_Count = 0;
	
	if ( username == "" )
	{
		document.getElementById( "fld_Username_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Username_Error" ).alt = 'Username field was blank!';
		err_Count++;
	}
	if ( password == "" )
	{
		document.getElementById( "fld_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Password_Error" ).alt = 'Password field was blank!';
		err_Count++;
	}
	if ( cPassword == "" )
	{
		document.getElementById( "fld_C_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_C_Password_Error" ).alt = 'Password confirmation field was blank!';
		err_Count++;
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function fields_Filled_S2(name,address,town,county,postcode_1,postcode_2,email)
{
	var err_Count = 0;
	
	if ( name == "" )
	{
		document.getElementById( "fld_Name_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Name_Error" ).alt = "Name field was empty!"
		err_Count++;
	}
	
	if ( address == "" )
	{
		document.getElementById( "fld_Address_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Address_Error" ).alt = "Address 1 field was empty!"
		err_Count++;	
	}
	
	if ( town == "" )
	{
		document.getElementById( "fld_Town_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Town_Error" ).alt = "Town field was empty!"
		err_Count++;	
	}
	
	if ( county == "" )
	{
		document.getElementById( "fld_County_Error" ).style.visibility = "visible";
		document.getElementById( "fld_County_Error" ).alt = "County field was empty!"
		err_Count++;	
	}
	
	if ( (postcode_1 == "")&&(postcode_2 == "") )
	{
		document.getElementById( "fld_Postcode_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Postcode_Error" ).alt = "Postcode fields were empty!"
		err_Count++;	
	}
	else if ( postcode_1 == "" )
	{
		document.getElementById( "fld_Postcode_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Postcode_Error" ).alt = "Postcode (part 1) field was empty!"
		err_Count++;	
	}
	else if ( postcode_2 == "" )
	{
		document.getElementById( "fld_Postcode_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Postcode_Error" ).alt = "Postcode (part 2) field was empty!"
		err_Count++;	
	}
	
	if ( email == "" )
	{
		document.getElementById( "fld_Email_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Email_Error" ).alt = "Email field was empty!"
		err_Count++;	
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}		
}

function fields_Filled_S3(mail_List_Yes,mail_List_No,t_And_C)
{
	var err_Count = 0;	
	
	if ( (!mail_List_Yes) && (!mail_List_No) )
	{
		document.getElementById( "fld_Mailing_List_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Mailing_List_Error" ).alt = "Please select whether you would like to join the mailing list!";
		err_Count++;
	}
	
	if ( !t_And_C )
	{
		document.getElementById( "fld_T_And_C_Error" ).style.visibility = "visible";
		document.getElementById( "fld_T_And_C_Error" ).alt = "Please accept the terms and conditions to proceed!";
		err_Count++;
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function passwords_Match(password,cPassword)
{
	if (password == cPassword)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function no_Illegal_Chars(username,password,cPassword)
{
	var alphaExp = /^[0-9a-zA-Z]+$/;
	var err_Count = 0;
	
	if(!username.match(alphaExp))
	{
		document.getElementById( "fld_Username_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Username_Error" ).alt = 'Illegal characters used in username. Please use only letters and numbers!';
		document.getElementById( "fld_Username" ).value = "";
		err_Count++
	}
	if(!password.match(alphaExp))
	{
		document.getElementById( "fld_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Password_Error" ).alt = 'Illegal characters used in password. Please use only letters and numbers!';
		document.getElementById( "fld_Password" ).value = "";
		err_Count++
	}
	if(!cPassword.match(alphaExp))
	{
		document.getElementById( "fld_C_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_C_Password_Error" ).alt = 'Illegal characters used in password confirmation. Please use only letters and numbers!';
		document.getElementById( "fld_Con_Password" ).value = "";
		err_Count++
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function valid_Email_Address(email)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	
	if ( email.match(emailExp) )
	{
		return true;
	}
	else
	{
		document.getElementById( "fld_Email_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Email_Error" ).alt = "The email address you provided is invalid!";
		return false;
	}
	
}

function valid_Paypal_Address(paypal)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	
	if ( paypal.match(emailExp) )
	{
		return true;
	}
	else
	{
		document.getElementById( "fld_Paypal_Username_Error" ).style.visibility = "visible";
		document.getElementById( "fld_Paypal_Username_Error" ).alt = "Paypal username is invalid!";
		return false;
	}
	
}

//Login Form Validation
function login_Ok()
{
	var username = document.getElementById( "fld_Username" ).value;
	var password = document.getElementById( "fld_Password" ).value;
	
	//alert(username.length);		//DEBUG
	//alert(password.length);		//DEBUG
	
	if ( !fields_Filled_Login(username,password) )
	{
		alert("The login fields are empty. Please correct this error!");
		return false;
	}
	else if ( !fields_Are_Long_Enough(username,password) )
	{
		alert("The fields that you entered were not long enough!")
		return false;
	}
	else
	{
		return true;
		//return false;	//For testing only, to be commented out
	}
}

function fields_Are_Long_Enough(username,password)
{
	var err_Count = 0;
	
	if ( username.length < 8 )
	{
		//alert("Username Not Long Enough");		//DEBUG
		err_Count++;
		//alert(err_Count);	//DEBUG
	}
	
	if ( password.length < 8 )
	{
		//alert("Password Not Long Enough");		//DEBUG
		err_Count++;
		//alert(err_Count);	//DEBUG
	}
		
	if ( err_Count > 0 )
	{
		//alert("False");	//DEBUG
		return false;
	}
	else
	{
		//alert("True");	//DEBUG
		return true;
	}
}

function fields_Filled_Login(username,password)
{
	var err_Count = 0;
	
	if ( username = "" )
	{
		err_Count++;
	}
	
	if ( password == "" )
	{
		err_Count++;
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function validate_New_Password()
{
	var err_Count = 0;	
	var password = document.getElementById( 'fld_Password' ).value;
	var cPassword = document.getElementById( 'fld_Con_Password' ).value;
	
	if ( password == "" )
	{
		document.getElementById( "fld_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Password_Error" ).alt = 'Password field was blank!';
		err_Count++;
	}
	if ( cPassword == "" )
	{
		document.getElementById( "fld_C_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_C_Password_Error" ).alt = 'Password confirmation field was blank!';
		err_Count++;
	}
	
	if ( (password.length < 8) || (password.length > 16) )
	{
		document.getElementById( "fld_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Password_Error" ).alt = 'Password must be between 8 - 16 characters!';
		err_Count++;
	}
	if ( (cPassword.length < 8) || (cPassword.length > 16) )
	{
		document.getElementById( "fld_C_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_C_Password_Error" ).alt = 'Password confirmation must be between 8 - 16 characters!';
		err_Count++;
	}
	
	if ( !passwords_Match(password,cPassword) )
	{
		alert("The passwords that were entered do not match!");
		document.getElementById( "fld_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_Password_Error" ).alt = 'Password did not match the password confirmation';
		document.getElementById( "fld_C_Password_Error" ).style.visibility = 'visible';
		document.getElementById( "fld_C_Password_Error" ).alt = 'Password confirmation did not match the password';
		document.getElementById( "fld_Password" ).value = "";
		document.getElementById( "fld_Con_Password" ).value = "";		
		return false;
	}
	
	if ( err_Count > 0 )
	{
		alert("There were errors. Please see markings!");
		return false;
	}
	else
	{
		return true;
	}
}

//Control Panel Scripts
function disable_Account()
{
	var disable = confirm("Are you sure you want disable your account?")
	if ( disable )
	{
		return true;
	}
	else
	{
		return false
	}
}

function enable_Account()
{
	var enable = confirm("Are you sure you want enable your account?")
	if ( enable )
	{
		return true;
	}
	else
	{
		return false
	}
}

function update_Details()
{
	var add_Line_1 = document.getElementById( 'fld_Add_Line_1' ).value;
	var add_Line_2 = document.getElementById( 'fld_Add_Line_2' ).value;
	var town = document.getElementById( 'fld_Town' ).value;
	var county = document.getElementById( 'fld_County' ).value;
	var postcode = document.getElementById( 'fld_Postcode' ).value;
	var email_Address = document.getElementById( 'fld_Email_Address' ).value;
	var paypal_Address = document.getElementById( 'fld_Paypal_Address' ).value;
	var mailing_List_Yes = document.getElementById( 'fld_Mailing_List_Yes' ).checked;
	var mailing_List_No = document.getElementById( 'fld_Mailing_List_No' ).checked;
	
	//alert(add_Line_1 + " " + add_Line_2 + " " + town + " " + county + " " + postcode + " " + email_Address + " " + paypal_Address + " " + mailing_List_Yes + " " + mailing_List_No);
	//alert(county);
	
	//Are the required fields empty?
	if ( !fields_Are_Filled_User_Details(add_Line_1,town,county,postcode,email_Address,mailing_List_Yes,mailing_List_No) )
	{
		alert("There was a problem! See Error Marking!");
		return false;
	}
	
	//Are fields that need to be a certain length within the range?
	if ( !fields_Long_Enough_User_Details(postcode) )
	{
		alert("There was a problem! See Error Marking!");
		return false;
	}
	
	//Is the email address valid?
	if ( !valid_Email_Address(email_Address) )
	{
		alert("There was a problem! See Error Marking!");
		return false;
	}
	
	//Is paypal entered and is it valid
	if ( !paypal_Address.length == 0 )
	{
		if ( !valid_Paypal_Address(paypal_Address) )
		{
			alert("There was a problem! See Error Marking!");
			return false;
		}
	}

	return true;
//	return false;	//DEBUG - DELETE/COMMENT OUT
}

function fields_Are_Filled_User_Details(add_Line_1,town,county,postcode,email_Address,mailing_List_Yes,mailing_List_No)
{
	var err_Count = 0;
	
	if ( add_Line_1.length == 0 )
	{
//		alert("Address line 1 empty");
		document.getElementById( 'fld_Add_Line_1_Details_Error' ).style.visibility = "visible";
		document.getElementById( 'fld_Add_Line_1_Details_Error' ).alt = "Please enter the first line of your address!"
		err_Count ++;
	}
	if ( town.length == 0 )
	{
//		alert("Town empty");
		document.getElementById( 'fld_Town_Details_Error' ).style.visibility = "visible";
		document.getElementById( 'fld_Town_Details_Error' ).alt = "Please enter the town where you live!"
		err_Count ++;
	}
	if ( county.length == 0 )
	{
//		alert("county empty");
		document.getElementById( 'fld_County_Details_Error' ).style.visibility = "visible";
		document.getElementById( 'fld_County_Details_Error' ).alt = "Please enter the county where you live!"
		err_Count ++;
	}
	if ( postcode.length == 0 )
	{
//		alert("postcode empty");
		document.getElementById( 'fld_Postcode_Details_Error' ).style.visibility = "visible";
		document.getElementById( 'fld_Postcode_Details_Error' ).alt = "Please enter your postcode!"
		err_Count ++;
	}
	if ( email_Address.length == 0 )
	{
//		alert("Email Address empty");
		document.getElementById( 'fld_Email_Error' ).style.visibility = "visible";
		document.getElementById( 'fld_Email_Error' ).alt = "Please enter your email address!"
		err_Count ++;
	}
	if ( (!mailing_List_Yes) && (!mailing_List_No) )
	{
//		alert("Mailing List empty");
		document.getElementById( 'fld_Mail_List_Details_Error' ).style.visibility = "visible";
		document.getElementById( 'fld_Mail_List_Details_Error' ).alt = "Please enter the first line of your address!"
		err_Count ++;
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}	
}

function fields_Long_Enough_User_Details(postcode)
{
	if ( (postcode.length < 6) || (!postcode.length > 8) )
	{
		document.getElementById( 'fld_Postcode_Details_Error' ).style.visibility = "visible";
		document.getElementById( 'fld_Postcode_Details_Error' ).alt = "The postcode you entered wasnt valid!"
		return false;
	}
	else
	{
		return true;
	}
}

function update_Password()
{
	var old_Password = document.getElementById( 'fld_Old_Password' ).value;
	var new_Password = document.getElementById( 'fld_New_Password' ).value;
	var confirm_New_Password = document.getElementById( 'fld_Confirm_New_Password' ).value;
	
//	alert(old_Password.length + " " + new_Password.length + " " + confirm_New_Password.length);

	//Are the fields Filled?
	if ( !fields_Are_Filled_Details(old_Password,new_Password,confirm_New_Password) )
	{
		alert("Please correct the highlighted errors!");
		return false;	
	}
	
	//Are the fields long enough
	if ( !fields_Are_Long_Enough_Details(old_Password,new_Password,confirm_New_Password) )
	{
		alert("Please correct the highlighted errors!");
		return false;	
	}
			
	//Do new passwords match?
	if ( !passwords_Match(new_Password,confirm_New_Password) )
	{
		alert("Your new passwords don't match!");
		document.getElementById( 'fld_New_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_New_Password_Error' ).alt = "This password doesn't match the confirmation below!";
		document.getElementById( 'fld_Confirm_New_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Confirm_New_Password_Error' ).alt = "This confirmation doesn't match the password entered above!";
		return false;
	}
	
	return true;
//	return false;	//DEBUG - REMOVE/COMMENT OUT
}

function fields_Are_Filled_Details(old,newP,cNewP)
{
	var err_Count = 0;
	
//	alert(old.length);
//	alert(newP.length);
//	alert(cNewP.length);
	
	if ( old.length == 0 )
	{
//		alert("You must enter your current password!");
		document.getElementById( 'fld_Old_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Old_Password_Error' ).alt = "Please enter your old password!";
		err_Count ++;
	}
	if ( newP.length == 0 )
	{
//		alert("You must enter a new password!");
		document.getElementById( 'fld_New_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_New_Password_Error' ).alt = "Please enter a new password!";
		err_Count ++;
	}
	if ( cNewP.length == 0 )
	{
//		alert("You must confirm your new password!");
		document.getElementById( 'fld_Confirm_New_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Confirm_New_Password_Error' ).alt = "Please confirm your new password!";
		err_Count ++;
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function fields_Are_Long_Enough_Details(old,newP,cNewP)
{
	var err_Count = 0;
	
	if ( old.length < 8 )
	{
//		alert("You must enter your current password!");
		document.getElementById( 'fld_Old_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Old_Password_Error' ).alt = "Your current password is between 8 and 16 characters!";
		err_Count ++;
	}
	if ( newP.length < 8 )
	{
//		alert("You must enter a new password!");
		document.getElementById( 'fld_New_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_New_Password_Error' ).alt = "Password length must be between 8 and 16 characters!";
		err_Count ++;
	}
	if ( cNewP.length < 8 )
	{
//		alert("You must confirm your new password!");
		document.getElementById( 'fld_Confirm_New_Password_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Confirm_New_Password_Error' ).alt = "Password length must be between 8 and 16 characters!";
		err_Count ++;
	}
	
	if ( err_Count > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function set_Forms_To_Hidden()
{
	//document.getElementById( 'details_Form' ).style.dispaly = "none";
	document.getElementById( 'password_Form' ).style.dispaly = "none";
}

//History Scripts
function hide_History()
{
	document.getElementById( 'listed_History' ).style.display = "none";
	document.getElementById( 'bought_History' ).style.display = "none";
	document.getElementById( 'swapped_History' ).style.display = "none";
}

function show_Listed_History()
{
	document.getElementById( 'listed_History' ).style.display = "block";
	document.getElementById( 'bought_History' ).style.display = "none";
	document.getElementById( 'swapped_History' ).style.display = "none";
}

function show_Bought_History()
{
	document.getElementById( 'listed_History' ).style.display = "none";
	document.getElementById( 'bought_History' ).style.display = "block";
	document.getElementById( 'swapped_History' ).style.display = "none";
}

function show_Swapped_History()
{
	document.getElementById( 'listed_History' ).style.display = "none";
	document.getElementById( 'bought_History' ).style.display = "none";
	document.getElementById( 'swapped_History' ).style.display = "block";
}

//Buy Credits Scripts
function is_Options_Selected()
{
	var form_Value_1 = document.getElementById( 'fld_Credits_1' ).checked;
	var form_Value_6 = document.getElementById( 'fld_Credits_6' ).checked;
	var form_Value_15 = document.getElementById( 'fld_Credits_15' ).checked;
	
//	alert(form_Value_1);	//DEBUG
//	alert(form_Value_6);	//DEBUG
//	alert(form_Value_15);	//DEBUG
	
	if ( (!form_Value_1) && (!form_Value_6) && (!form_Value_15) )
	{
		alert("There was no value selected!");
		return false;
	}
	else
	{	
		return true;	
//		alert("Return True");
	}
	
//	return false;	//DEBUG REMOVE?COMMENT OUT
}

//Proudct Info Scripts
function set_Divs()
{
	document.getElementById( 'questions' ).style.display = "none";
	document.getElementById( 'ask_Question' ).style.display = "none";
}

function is_Shown(this_Field)
{
	if ( document.getElementById( this_Field ).style.display == "none" )
	{
		document.getElementById( this_Field ).style.display = "block";
		document.getElementById( this_Field + '_Img' ).src = "Images/colapse.gif";
		document.getElementById( this_Field + '_Img' ).alt = "Colapse";
	}
	else if ( document.getElementById( this_Field ).style.display == "block" )
	{
		document.getElementById( this_Field ).style.display = "none";
		document.getElementById( this_Field+'_Img' ).src = "Images/expand.gif";
		document.getElementById( this_Field + '_Img' ).alt = "Expand";
	}
}

function question_Box_Focus(text_Area,original_Message)
{
	if ( document.getElementById( text_Area ).value == original_Message )
	{
		document.getElementById( text_Area ).value = "";
		document.getElementById( text_Area ).style.color = "#666666";
	}
}

function question_Box_Blur(text_Area,original_Message)
{
	if ( document.getElementById( text_Area ).value == "" )
	{
		document.getElementById( text_Area ).value = original_Message;
		document.getElementById( text_Area ).style.color = "#999999";
	}
}

function is_Textarea_Filled_in(this_Field,start_Value)
{
	if ( (document.getElementById ( this_Field ).value == start_Value) || document.getElementById( this_Field ) == "" )
	{
		alert("You are not allowed to submit this box without filling it in!");
		return false;
	}
	else
	{
		return true;
	}
}

//Buy Scripts
function is_Search_Filled()
{
	if ( document.getElementById( 'fld_Search' ).value == "" )
	{
		return false;
	}
	else
	{
		return true;
	}
}

//Listing Scripts
function check_Price_Format()
{
	if ( isNaN(document.getElementById( 'fld_Item_Price' ).value) )
	{
		return false;	
	}	
	else
	{
		return true;
	}
}

function hide_Trs()
{
	document.getElementById( 'upload_Image_Tr' ).style.display = "none";
	document.getElementById( 'list_Item_For_1' ).style.display = "none";
	document.getElementById( 'list_Item_For_2' ).style.display = "none";
}

function hide_Image_Box()
{
	document.getElementById( 'upload_Image_Tr' ).style.display = "none";
}

function show_Image_Box()
{
	document.getElementById( 'upload_Image_Tr' ).style.display = "block";
}

function check_List_For()
{
	if ( document.getElementById( 'list_Item_For_1' ).style.display == "none" )
	{
		document.getElementById( 'list_Item_For_1' ).style.display = "block";
		document.getElementById( 'fld_Sell' ).checked = true;
		document.getElementById( 'list_Item_For_2' ).style.display = "block";
	}
	else
	{
		document.getElementById( 'list_Item_For_1' ).style.display = "none";
		document.getElementById( 'list_Item_For_2' ).style.display = "none";
		document.getElementById( 'fld_Sell' ).checked = false;
		document.getElementById( 'fld_Swap' ).checked = false;
	}
}

function check_Sell()
{
	if ( document.getElementById( 'fld_Sell' ).checked )
	{
		document.getElementById( 'fld_Sell' ).checked = false;
	}		
}

function check_Swap()
{
	if ( document.getElementById( 'fld_Swap' ).checked )
	{
		document.getElementById( 'fld_Swap' ).checked = false;
	}		
}

function list_Details_1()
{
	var item_Title = document.getElementById( 'fld_Item_Title' ).value;
	var item_Description = document.getElementById( 'fld_Item_Description' ).value;
	var item_Price = document.getElementById( 'fld_Item_Price' ).value;
	
//	alert(item_Title + " " + item_Description + " " + item_Price)
	
	//Check if the fields are filled in
	if ( list_Fields_Filled(item_Title,item_Description,item_Price) )
	{
		if ( check_Price_Format() )
		{
//			return false;	//DEBUG - To be removed/commented out
			return true;
		}
		else
		{
			alert("Please enter a valid price in the price field!");
			document.getElementById( 'fld_Item_Price_Error' ).style.visibility = 'visible';
			document.getElementById( 'fld_Item_Price_Error' ).alt = 'Please enter a valid price!';
			return false;
		}
	}
	else
	{
		alert("Please fill in the fields marked.  Hover over the marks to see the error!");
		return false;
	}
}

function list_Fields_Filled(title,desc,price)
{
	var errCnt = 0
	
	if ( title == "" )
	{
		document.getElementById( 'fld_Item_Title_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Item_Title_Error' ).alt = 'Please enter a title for your item!';
		errCnt++;
	}
	if ( desc == "" )
	{
		document.getElementById( 'fld_Item_Description_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Item_Description_Error' ).alt = 'Please describe your item!';
		errCnt++;
	}
	if ( price == "" )
	{
		document.getElementById( 'fld_Item_Price_Error' ).style.visibility = 'visible';
		document.getElementById( 'fld_Item_Price_Error' ).alt = 'Please enter the price of your item!';
		errCnt++;
	}
	
	if ( errCnt > 0 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function is_Item_Selected()
{
	if ( document.getElementById( 'fld_Swap' ).checked == false	)
	{
		alert("Please select one of your items to propose a swap with!");
		return false;
	}
}
