function gei(x){ return document.getElementById(x); }
function jump(x){window.location=x;}
function apad(x){gei('actionpad').src=x;}
function newCookie(name,value,days){var days = 30;if(days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}
function eraseCookie(name) {newCookie(name,"",1); }
function readCookie(name){var nameSG = name + "=";var nuller = '';if (document.cookie.indexOf(nameSG) == -1)return nuller;var ca = document.cookie.split(';');for(var i=0; i<ca.length; i++) {var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length); }return null; }
function rememberSave(val){newCookie('rememberName', val);}
function rememberDel(){eraseCookie('rememberName');}
function rememberLoad(){return readCookie('rememberName');}
function loader(func){if (window.attachEvent) {window.attachEvent('onload', new Function(func));}else if (window.addEventListener) {window.addEventListener('load', new Function(func), false);}else {document.addEventListener('load',new Function(func), false);}}
function loginBtn(loginFrm){gei(loginFrm).remember.checked ? rememberSave(gei(loginFrm).username.value) : rememberDel();gei(loginFrm).submit();}
function forgotPassword(){y=prompt('Enter your email address or username:');if(y){apad('/forgot.html?ue='+y);}}
function init(){
	gei('logo').onclick=function(){jump('/');};
}
loader("init();");



function toggleFAQ(i){
	if(gei('a'+i).style.display == 'none' || gei('a'+i).style.display == '') gei('a'+i).style.display='block';
	else gei('a'+i).style.display='none';
}


function verifySignup(){
	f = gei('signup');
	
	var m ='';
	if(!f.fullName.value || f.fullName.value.indexOf(' ')<0 || f.fullName.length < 3) m += '\nEnter your first and last name into the full name box.';
	if(!f.user.value) m+= '\nEnter a username.';
	if(!f.pass.value || !f.cpass.value || f.cpass.value != f.pass.value) m+= '\nPassword and confirm pass need to be the same.';
	if(!f.email.value || f.email.value.indexOf('@')<=0 || f.email.value.indexOf('.') <=0 ) m += '\nYour email appears to be invalid.';
	if(!f.phone.value || f.phone.length < 10) m+= '\nPlease enter your full phone number including country and area code.';
	if(!f.agree.checked) m+= '\nYou must agree to our terms to signup.';
	switch(f.payMethod.value){
		case 'check':
			if(!f.checkName.value) m+= '\nPayment Info: Enter your pay-to name';
			if(!f.checkAddress.value) m+= '\nPayment Info: Enter your street address';
			if(!f.checkCity.value) m+= '\nPayment Info: Enter your city';
			if(!f.checkState.value) m+= '\nPayment Info: Enter your state or province, if you do not have one enter \'none\'';
			if(!f.checkZip.value) m+= '\nPayment Info: Enter your zip or postal code.';
			if(!f.checkCountry.value) m+= '\nPayment Info: Enter your country.';
		break;
		case 'wire':
			if(!f.wireName.value) m+= '\nPayment Info: Enter the name on your bank account';
			if(!f.wireAccount.value) m+= '\nPayment Info: Enter your bank account number';
			if(!f.wireRouting.value) m+= '\nPayment Info: Enter your bank routing number';
			if(!f.wireBankName.value) m+= '\nPayment Info: Enter the name of your bank';
			if(!f.wireBankAddress.value) m+= '\nPayment Info: Enter the address of your bank';
		break;
		case 'paypal':
			if(!f.paypal.value || f.paypal.value.indexOf('@')<0 || f.paypal.value.indexOf('.')<0) m+= '\nPayment Info: Your Paypal address looks invalid.';
		break;
		case 'epass':
			if(!f.epass.value) m+= '\nPayment Info: Your ePassporte address looks invalid.';
		break;
	}
	
	if(!m) f.submit();
	else alert('Fix the following errors to continue:\n'+m);
}
function toggleMethod(x){
	gei('check').style.display='none';
	gei('wire').style.display='none';
	gei('paypal').style.display='none';
	gei('epass').style.display='none';
	gei(x).style.display='block';
}
