bol = true;

function checkEmptyField(div_id){
	document.getElementById(div_id).value = removeLeadingAndTrailingChar(document.getElementById(div_id),' ');
	var err_div = 'err_'+div_id;
	if(!(bol=isEmpty(document.getElementById(div_id),"")) ){
		document.getElementById(err_div).style.display = '';
		document.getElementById(div_id).focus();
		document.getElementById(div_id).select();
		return false;
	} else {
		document.getElementById(err_div).style.display = 'none';
		return true;
	} 
}

function checkFieldLength(div_id,limit){
	document.getElementById(div_id).value = removeLeadingAndTrailingChar(document.getElementById(div_id),' ');
	var old_err_div = 'err_'+div_id;
	var err_div = 'err_length_'+div_id;
	if(document.getElementById(div_id).value.length < limit && document.getElementById(div_id).value !=''){
		document.getElementById(old_err_div).style.display = 'none';
		document.getElementById(err_div).style.display = '';
		document.getElementById(div_id).focus();
		//document.getElementById(div_id).select();
		return false;
	} else {
		document.getElementById(err_div).style.display = 'none';
		return true;
	} 
}

function checkKeywords(){
	document.form1.keywords.value = removeLeadingAndTrailingChar(document.form1.keywords,' ');
		var keywords = document.form1.keywords.value;	
		var keywords_array = keywords.split(",");
		var total_words	=	keywords_array.length;		
		
	if(total_words > 4){
		document.getElementById('err_keywords').style.display = '';
		return false;
	} else {
		document.getElementById('err_keywords').style.display = 'none';
		return true;
	} 
}

function checkEmailValidation(){

	document.form1.email_address.value = removeLeadingAndTrailingChar(document.form1.email_address,' ');
	if(!(bol=isEmpty(document.form1.email_address,"")) ){
		document.getElementById('err_email_address').style.display = '';
		document.getElementById('err_email_address').innerHTML = 'Please enter your email address.';
		return false;
	} else {
		if (!(bol=echeck(document.form1.email_address)) ){
			document.getElementById('err_email_address').style.display = '';
			document.getElementById('err_email_address').innerHTML = 'Please enter a valid email address.';
			return false;
		}
		document.getElementById('err_email_address').style.display = 'none';
		return true;
	} 

}


function checkEmail(){

	//if ( checkEmailValidation() ) {
		var email = document.form1.email_address.value;
						
				var phpFilePath = '_site_contents/main/check_email_dup.php?email='+email;
				//var phpFilePath = '_site_contents/main/check_email_dup.php?email=asdf';
				var div_id = 'err_email_address';
				makeRequestReg(phpFilePath,div_id);
	//}
}

function checkPassword(){
	//if (document.getElementById('pass').disabled==false) {
		document.form1.pass.value = removeLeadingAndTrailingChar(document.form1.pass,' ');
		if(!(bol=isEmpty(document.form1.pass,"")) ){
			document.getElementById('err_pass').style.display = '';
			return false;
		} else {
			document.getElementById('err_pass').style.display = 'none';
			return true;
		}
	/*} else {
		return true;	
	}*/
}

function checkConfirmPass(){
	//if (document.getElementById('confirm_pass').disabled==false) {
		document.form1.confirm_pass.value = removeLeadingAndTrailingChar(document.form1.confirm_pass,' ');
		if(!(bol=isEmpty(document.form1.confirm_pass,"")) ){
			document.getElementById('err_confirm_pass').style.display = '';
			return false;
		} else {
			document.getElementById('err_confirm_pass').style.display = 'none';
			return true;
		} 
	/*} else {
		return true;	
	}*/
}

function checkBothPass(){
	if( checkPassword() && checkConfirmPass() ) {
		if (document.form1.confirm_pass.value!=document.form1.pass.value) {
			document.getElementById('err_confirm_pass').style.display = '';
			return false;
		}
	return true;
	} 
}


function checkDropDown(div_id){
	var question = document.getElementById(div_id).selectedIndex;
	var err_div = 'err_'+div_id;
	if(question!=0){
		document.getElementById(err_div).style.display = 'none';
		return true;
	} else {
		document.getElementById(err_div).style.display = '';
		//document.getElementById(div_id).focus();
		//document.getElementById(div_id).select();
		return false;
	} 

}

function checkCountry(){

	var country = document.form1.country.value;
	if(country!=-1){
		document.getElementById('err_country').style.display = 'none';
		return true;
	} else {
		document.getElementById('err_country').style.display = '';
		document.getElementById('country').focus();
		//document.getElementById('country').select();
		return false;
	} 

}

function checkHearAboutUs(){

	var hear = document.form1.hear_about_us.value;
	if(hear == 4 || hear == 8 || hear == 10){
		return checkEmptyField('hear_about_des');
	} else {
		return true;	
	}

}


function submitMe(){
		
	if(!checkEmptyField('username'))
		return false;
		
	if(!checkFieldLength('username',4))
		return false;
		
	if(!checkEmptyField('email_address'))
		return false;
		
	if(!checkEmptyField('pass'))
		return false;
		
	if(!checkFieldLength('pass',6))
		return false;
		
	if(!checkBothPass()) 
		return false;
		
	/*if (!checkDropDown('question'))
		return false;
	
	if(!checkEmptyField('secret_answer'))
		return false;*/
		
	if(!checkEmptyField('first_name'))
		return false;
		
	/*if(!checkEmptyField('sur_name'))
		return false;*/
	
	if (!checkCountry())
		return false;
		
	if (!checkHearAboutUs())
		return false;
		
	return true;
}

function submitMeCp2(){

	/*if(!checkEmptyField('tagline'))
		return false;*/
			
	if(!checkKeywords())
		return false;
			
	return true;
}
function submitMe_test() {
	alert(submitMe());
	return submitMe();
	}