// Index javaScript function
//-//button function
var bt=new Array("whyBt","howBt","aboutBt");
var frame=new Array("whyMain","how");
var frameArr=Array('whyMain','howMain','signMain','aboutMain');
var titleArr=Array('test1','test2','test3');

function frameShow(par){
	if(par=="whyMain"){
		showWhyFrame();	
	}else if(par=="signMain"){
		showSignAndLogin();
	}else if(par=="howMain"){
		showHowFrame();
	}else if(par=="aboutMain"){
		showAbout();
	}
}
function anchorURL(){
	var url=location.href;
	var frame=url.substr(url.search("#"));
	frame=frame.replace("#","");
	for(i=0;i<=frameArr.length;i++){
		if(frameArr[i]==frame){
			frameShow(frameArr[i]);
		}
	}
}
function showWhyFrame(){
	document.title="GoHitchhike - Why Use Us";
	var whyBt;
	var howBt;
	var aboutBt;
	var loginBt;
	var signUpBt;
	if(whyBt=document.getElementById("whyBt")){
		whyBt.id="whyBtSelected";
	}
	if(howBt=document.getElementById("howBtSelected")){
		howBt.id="howBt";
	}
	if(aboutBt=document.getElementById("aboutBtSelected")){
		aboutBt.id="aboutBt";
	}
	if(loginBt=document.getElementById("loginBtSelected")){
		loginBt.id="loginBt";
	}
	if(signUpBt=document.getElementById("signUpBtSelected")){
		signUpBt.id="signUpBt";
	}
	if(document.getElementById('tempMain')!=null){
		document.getElementById('tempMain').className="off";
	}
	document.getElementById("whyMain").className="on";
	document.getElementById("whyContent").className="on";
	document.getElementById("howMain").className="off";
	document.getElementById("howContent").className="off";
	document.getElementById("signMain").className="off";
	document.getElementById("aboutMain").className="off";
	document.getElementById("aboutContent").className="off";
}
function showHowFrame(){
	document.title="GoHitchhike - How To Use";
	var whyBt;
	var howBt;
	var aboutBt;
	var loginBt;
	var signUpBt;
	if(whyBt=document.getElementById("whyBtSelected")){
		whyBt.id="whyBt";
	}
	if(howBt=document.getElementById("howBt")){
		howBt.id="howBtSelected";
	}
	if(aboutBt=document.getElementById("aboutBtSelected")){
		aboutBt.id="aboutBt";
	}
	if(loginBt=document.getElementById("loginBtSelected")){
		loginBt.id="loginBt";
	}
	if(signUpBt=document.getElementById("signUpBtSelected")){
		signUpBt.id="signUpBt";
	}
	if(document.getElementById('tempMain')!=null){
		document.getElementById('tempMain').className="off";
	}

	document.getElementById("signMain").className="off";
	document.getElementById("whyMain").className="off";
	document.getElementById("whyContent").className="off";
	document.getElementById("howMain").className="on";
	document.getElementById("howContent").className="on";
	document.getElementById("aboutMain").className="off";
	document.getElementById("aboutContent").className="off";
}
function showSignAndLogin(){
	document.title="GoHitchhike - Login/ Sign Up";
	var whyBt;
	var howBt;
	var aboutBt;
	var loginBt;
	var signUpBt;
	if(whyBt=document.getElementById("whyBtSelected")){
		whyBt.id="whyBt";
	}
	if(howBt=document.getElementById("howBtSelected")){
		howBt.id="howBt";
	}
	if(aboutBt=document.getElementById("aboutBtSelected")){
		aboutBt.id="aboutBt";
	}
	if(loginBt=document.getElementById("loginBt")){
		loginBt.id="loginBtSelected";
	}
	if(signUpBt=document.getElementById("signUpBt")){
		signUpBt.id="signUpBtSelected";
	}
	if(document.getElementById('tempMain')!=null){
		document.getElementById('tempMain').className="off";
	}

	document.getElementById("signMain").className="on";
	document.getElementById("whyMain").className="off";
	document.getElementById("whyContent").className="off";
	document.getElementById("howMain").className="off";
	document.getElementById("howContent").className="off";
	document.getElementById("aboutMain").className="off";
	document.getElementById("aboutContent").className="off";
}
function showAbout(){
	document.title="GoHitchhike - About";
	var whyBt;
	var howBt;
	var aboutBt;
	var loginBt;
	var signUpBt;
	if(whyBt=document.getElementById("whyBtSelected")){
		whyBt.id="whyBt";
	}
	if(howBt=document.getElementById("howBtSelected")){
		howBt.id="howBt";
	}
	if(aboutBt=document.getElementById("aboutBt")){
		aboutBt.id="aboutBtSelected";
	}
	if(loginBt=document.getElementById("loginBtSelected")){
		loginBt.id="loginBt";
	}
	if(signUpBt=document.getElementById("signUpBtSelected")){
		signUpBt.id="signUpBt";
	}
	if(document.getElementById('tempMain')!=null){
		document.getElementById('tempMain').className="off";
	}

	document.getElementById("signMain").className="off";
	document.getElementById("whyMain").className="off";
	document.getElementById("whyContent").className="off";
	document.getElementById("howMain").className="off";
	document.getElementById("howContent").className="off";
	document.getElementById("aboutMain").className="on";
	document.getElementById("aboutContent").className="on";	
}
function showItemFrame(){
	var itemBt;
	var tripBt;
	var voteBt;
	if(itemBt=document.getElementById("itemBt")){
		itemBt.id="itemBtSelected";
	}
	if(tripBt=document.getElementById("tripBtSelected")){
		tripBt.id="tripBt";
	}
	if(voteBt=document.getElementById("voteBtSelected")){
		voteBt.id="voteBt";
	}
	document.getElementById("itemFrame").className="on";
	document.getElementById("tripFrame").className="off";
	document.getElementById("voteFrame").className="off";
}
function showTripFrame(){
	var itemBt;
	var tripBt;
	var voteBt;
	if(itemBt=document.getElementById("itemBtSelected")){
		itemBt.id="itemBt";
	}
	if(tripBt=document.getElementById("tripBt")){
		tripBt.id="tripBtSelected";
	}
	if(voteBt=document.getElementById("voteBtSelected")){
		voteBt.id="voteBt";
	}
	document.getElementById("itemFrame").className="off";
	document.getElementById("tripFrame").className="on";
	document.getElementById("voteFrame").className="off";
}
function showVoteFrame(){
	var itemBt;
	var tripBt;
	var voteBt;
	if(itemBt=document.getElementById("itemBtSelected")){
		itemBt.id="itemBt";
	}
	if(tripBt=document.getElementById("tripBtSelected")){
		tripBt.id="tripBt";
	}
	if(voteBt=document.getElementById("voteBt")){
		voteBt.id="voteBtSelected";
	}
	document.getElementById("itemFrame").className="off";
	document.getElementById("tripFrame").className="off";
	document.getElementById("voteFrame").className="on";
}
var emailPat=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var namePat=/[a-zA-Z]+\s{1}[a-zA-Z]+/;
var pwPat=/[a-zA-Z0-9]{6,12}/;
function checkName(){
		var msg=document.getElementById("errDiv");
	var form=document.getElementById("signUpForm");
	if(namePat.test(form.fullName.value)){
		msg.innerHTML="";
		return(namePat.test(form.fullName.value));
	}else{
		msg.innerHTML="Please Check Your Full Name.";
	}
}
function checkEmail(){
	var msg=document.getElementById("errDiv");
	var form=document.getElementById("signUpForm");
	if(emailPat.test(form.email.value)){
		msg.innerHTML="";
		var user=new Array();
		user[0]={"key":"email","value":document.getElementById("signUpForm").email.value};
		sendRequest("ajax/check_user.php",user,checkAjaxEmail);
		return(emailPat.test(form.email.value));
	}else{
		msg.innerHTML="Please Check Your Email.";
	}
}
function checkAjaxEmail(){
	if(xmlHttp.readyState==4){
		var responser=document.getElementById("errDiv");
		if(xmlHttp.responseText=="1"){
			responser.innerHTML="Someone already signed up this email. Please try another one.";
		}else{
			responser.innerHTML="";
		}
	}
}

function checkPw(){
		var msg=document.getElementById("errDiv");
	var form=document.getElementById("signUpForm");
	if(pwPat.test(form.pw.value)){
		msg.innerHTML="";
		return(pwPat.test(form.pw.value));
	}else{
		msg.innerHTML="Your length of password should be 6-12.";
	}
}
function checkBirthday(){
	var form= document.getElementById("signUpForm");
		var msg=document.getElementById("errDiv");
	if(form.year.value!="" && form.mon.value!="" && form.day.value!=""){
		msg.innerHTML="";
		return(true);
	}else{
		msg.innerHTML="Please Select Your Birthday";
		return(false);
	}
}
function checkAgree(){
	var form= document.getElementById("signUpForm");
	var msg=document.getElementById("errDiv");
	if(form.agree.checked){
		msg.innerHTML="";
		return(true);
	}else{
		msg.innerHTML='Please click the check box after reading the "Statement of Rights and Responsibilities" and "Privacy Policy".';
		return(false);
	}
}
function checkSignUpForm(){
	if(checkPw()){
		if(checkName()){
				if(checkBirthday()){
						if(checkAgree()){
							if(checkEmail()){
							document.getElementById("signUpForm").submit();
						}
				}
			}
		}
	}
}
