function passCheck(status) { var password = $('l_pass'); if(status != 'in' && password.value == '') password.setStyle('background-image', 'url(images/password_bg.gif)'); else password.setStyle('background-image', '');} 
function emailCheck(status) { var login = $('l_email'); if(status != 'in' && login.value == '') login.setStyle('background-image', 'url(images/email_bg.gif)'); else login.setStyle('background-image', '');}

function signup_form(t) {
	var x = t.getElementsByTagName('input');
	var e = '';
	var f = document.getElementById('error_f');
	var p1, p2;
		
	for(i=0;i<x.length;i++) {
		if(x[i].name == "alias" && x[i].value == '') {
			e+="<br />Choose an alias";
		} else if(x[i].name == 'firstName' && x[i].value == '') {
			e+="<br />Enter your first name";
		} else if(x[i].name == 'surname' && x[i].value == '') {
			e+="<br />Enter your surname";
		} else if(x[i].name == 'email' && x[i].value == '') {
			e+="<br />Enter your email address";
		} else if(x[i].name == 'password' && x[i].value == '') {
			e+="<br />Enter your password";
		} else if(x[i].name == 'password1' && x[i].value == '') {
			e+="<br />Confirm your password";
		} else if(x[i].name == 'password') {
			p1 = x[i].value;
		} else if(x[i].name == 'password1') {
			p2 = x[i].value;
		}
	}
		
	if(e == "") {
		if(p1 == p2)
			return true;
		else {
			f.innerHTML = "Your account could not be created<br />Your passwords do not match";
			f.style.display = "";
			return false;
		}
	} else {
		f.innerHTML = "Your account could not be created, you must do the following;<br />"+e;
		f.style.display = "";	
		return false;
	}
}

function copyShipping() {
	switchValues('bi1', 'sh1');
	switchValues('bi2', 'sh2');
	switchValues('bi3', 'sh3');
	switchValues('bi4', 'sh4');
	switchValues('bi5', 'sh5');
	switchValues('bi6', 'sh6');
}
	
function switchValues(t, r) {
	document.getElementById(t).value = document.getElementById(r).value;
}
function toggleFocus(to) {
	FOCUS = to;	
	var rememberBox = document.getElementById("rememberBox");
	if(to == 'true') {
		rememberBox.style.border = "#ffffff 1px solid";
	} else {
		rememberBox.style.border = "#242424 1px solid";
	}
}
function vote(id, score) {
	var changeSpeed = 500;
	var marginChange = new Fx.Style('vote_content', 'opacity', {duration:changeSpeed});
	marginChange.start(0);
	var func = 'voteUpdate(\'vote/'+id+'/'+score+'\', \'vote_content\')';
	window.setTimeout(func, changeSpeed);
}
function quickVote(id, score) {
	var changeSpeed = 500;
	var fx = new Fx.Style('quick'+id, 'opacity', {duration:changeSpeed});
	fx.start(0);
	var func = 'voteUpdate(\'vote/'+id+'/'+score+'\', \'quick'+id+'\')';
	window.setTimeout(func, changeSpeed);
}
function upload_check(form) {
	var m = '';
	var d = document.getElementById('error_f');
	
	var v = form.getElementsByTagName('input');
	
	for(i = 0; i < v.length; i++) {
		if(v[i].name == 'design_name' && v[i].value == '') {
			m+='Design name must not be empty<br />';
		} else if(v[i].name == 'design_image' && v[i].value == '') {
			m+='Upload a design image<br />';
		} else if(v[i].name == 'design_image' && v[i].value != '') {
			var l = parseInt(v[i].value.length) - 3;
			var e = v[i].value.substring(l, l + 3);
			if(e != 'jpg')
				m+= 'Design image must be a JPG<br />';
		} else if(v[i].name == 'design_thumb' && v[i].value == '') {
			m+='Upload a thumbnail image<br />';
		} else if(v[i].name == 'design_thumb' && v[i].value != '') {
			var l = parseInt(v[i].value.length) - 3;
			var e = v[i].value.substring(l, l + 3);
			if(e != 'jpg')
				m+= 'Thumbnail image must be a JPG<br />';
		} 
	}
	
	if(m != '') {
		d.style.display = '';
		d.innerHTML = m;
		return false;
	} else {
		return true;
	}
}

function inputFileSwap(name) {
	document.getElementById(name.name+"_fake").value = name.value;	
}
function removeCart(info) {
	document.getElementById('remove'+info).submit();
}
function toggleAll(el, ul) {
	var toggle = $('checkall').checked;
	var contacts = $(ul);
	var emails = contacts.getElementsByTagName('input');
	for(var i in emails) {
		emails[i].checked = toggle;
	}
}
function toggleThisRow(row) {
	var box = $('check'+row);
	if(box.checked == true)
		box.checked = false;
	else
		box.checked = true;
	checkContacts();
}
function checkContacts() {
	var contacts = $('inviteContacts');
	var emails = contacts.getElementsByTagName('input');
	var isChecked = true;
	for(var i in emails) {
		if(emails[i].checked == false) {
			isChecked = false;
		}
	}
	$('checkall').checked = isChecked;
}