//validate the email and url
function valPayments(){
	var userEmail = document.frmPayments.os0.value;
	var atLoc = userEmail.indexOf("@",1);
	var dotLoc = userEmail.indexOf(".",atLoc+2);
	var len = userEmail.length;
	var url = document.frmPayments.os1.value;
	url = url.toLowerCase();
	url = url.substr(0, 7)
	if(!document.frmPayments.os0.value){
		alert("Please enter your email in case we need to contact you.");
		document.frmPayments.os0.focus();
		return false;
	}else if(atLoc<=0){
		alert("Please enter a valid email in case we need to contact you.");
		document.frmPayments.os0.focus();
		return false;
	}else if(!document.frmPayments.os1.value){
		alert("Please enter the website you want to link to.");
		document.frmPayments.os1.focus();
		return false;
	}else if(url != "http://"){
		alert("Please enter a valid website you want to link to e.g., http://www.thebigwordproject.com");
		document.frmPayments.os1.focus();
		return false;
	}else{
		return true;
	}
}

function valComp(){
	if(!document.frmComp.reason_name.value){
		alert("Please enter your name.");
		document.frmComp.reason_name.focus();
		return false;
	}else if(!document.frmComp.reason_word.value){
		alert("Please enter the word you purchased.");
		document.frmComp.reason_word.focus();
		return false;
	}else if(!document.frmComp.reason_reason.value){
		alert("Please tell us why you bought your word.");
		document.frmComp.reason_reason.focus();
		return false;
	}else{
		return true;
	}
}

function prepareFaq(){
	//faq check
	if(document.getElementById("faq")){
		//get faq list
		var faq = document.getElementById("faq");
		//get questions
		var allQuestions = faq.getElementsByTagName("h4");
		//loop through q's
		for(var i=0;i<allQuestions.length;i++){
			//hide ans
			allQuestions[i].parentNode.getElementsByTagName("div")[0].style.display = "none";
		}
	 }
}

function faq(div){
	//faq check
	if(document.getElementById("faq")){
		//do function
		var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
		if(IE6 == true){
			Effect.toggle(div,'appear',{ duration: 0.5 });
		}else{
			Effect.toggle(div,'slide',{ duration: 0.5 });
		}
	}
}


//setup the terms
function terms(){
	//terms check
	if(document.getElementById("terms")){
		//get terms
		var terms = document.getElementById("terms");
		//hide terms
		terms.style.display = "none";
	}
}

//setup gift
function gift(){
	//gift check
	if(document.getElementById("custom")){
		//get gift
		var gift = document.getElementById("custom");
		var email = document.getElementById("email");
		//gift.onClick = function(){
			if(gift.checked){
					email.innerHTML = "Friend's email <span>e.g., jane@doe.com</span>";
			}else{
					email.innerHTML = "Your email <span>e.g., john@doe.com</span>";
			}
		//}
	}
}

//tip fade out
function tipFade(){
	if(document.getElementById("homewords")){
		$element = document.getElementById("tip")
		if($element){
			new Effect.Fade($element,{duration:2});
		 }
	}
}

//prepare tip
function prepareTip(){
	$element = document.getElementById("tip")
	if ($element){
		if(document.getElementById("homewords")){
			if($element){
				$element.style.display = "block"
			}
		}else{
			$element.style.display = "none"
		}
	}
}

//record stats
function clk(id,theLink){
	var trackImg = new Image();
	trackImg.src = "/record_stat?id="+id;
	trackImg.onload=new function() {document.location.href=theLink.href;};
  return false;
}

//on page load
function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			if(oldonload){
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(terms);
addLoadEvent(prepareFaq);
addLoadEvent(prepareTip);