/* Create Channel */
function validateCreateChannel()
{
	if(document.frm_create.board_name.value =="" || document.frm_create.description.value == "" || document.frm_create.auto_num.value == "") {
		alert("Please fill up all the fields to continue");
		return false ;
	}
	//alert(document.form1.list.value) ;
	if(document.frm_create.list.value == "[ Select Subject ]") {
		alert("Please select a channel subject to continue");
		return false ;
	}
	return true ;
}

function remSpecialChar() {
}

/* Forgot Password */
function checkForgotPassForm() {
	if(document.getElementById("mailid").value == "") {
		alert("Please provide a valid email address to continue") ;
		return false ;
	}
	return true ;
}

/* Friendlist */
function confirmDel(friend_id) {
	return confirm("Are you sure you want to delete " + friend_id + " from your friend's list?") ;
}

/* Login */
function checkLoginForm() {
	if(document.getElementById("txtUid").value == "" || document.getElementById("txtPwd").value == "") {
		alert("Username or Password cannot be left blank") ;
		return false ;
	}
	return true ;
}

/* Most Recent */
function updateMRHF() {
	document.frm.hf_topic_ids.value = "" ;
	// if more than one checkbox
	if(document.frm.extra_cb.length) {
		for(var i=0; i < document.frm.extra_cb.length; i++){
			if(document.frm.extra_cb[i].checked) {
				document.frm.hf_topic_ids.value += document.frm.extra_cb[i].value + "," ;
			}
		}
	}
	// if only one checkbox
	if(document.frm.extra_cb.checked) {
		document.frm.hf_topic_ids.value += document.frm.extra_cb.value + "," ;
	}
}

/* Registration Form */
function checkRegisterForm() {
	if(document.frmreg.username.value.length < 6 || document.frmreg.username.value.length > 12) {
		alert("Username must be between 6 to 12 characters long.") ;
		return false ;
	}
	if(document.frmreg.password.value.length < 6 || document.frmreg.password.value.length > 18) {
		alert("Password must be between 6 to 18 characters long.") ;
		return false ;
	}
	if(document.frmreg.password.value == document.frmreg.username.value) {
		alert("Username and password cannot be the same for security reasons. \nPlease try with a different password!") ;
		return false ;
	}

	var iChars = "~`!@#$%^&*()-+=?></,\":';}{][|\\";
	for (var i = 0; i < document.frmreg.username.value.length; i++) {
		if (iChars.indexOf(document.frmreg.username.value.charAt(i)) != -1) {
			alert ("Username can containn only alphabets, numbers, \"_\" and a \".\"");
			return false;
		}
	}
	
	if(document.frmreg.username.value == "" || document.frmreg.password.value == "" || document.frmreg.first_name.value == "" || document.frmreg.last_name.value == "" || document.frmreg.address.value == "") {
		alert("Please fill up all the fields to complete your registration process") ;
		return false ;
	}
	if(document.frmreg.password.value != "" && document.frmreg.password.value != document.frmreg.password_confirm.value) {
		alert("Please confirm your password again") ;
		document.frmreg.password_confirm.value = "" ;
		document.frmreg.password_confirm.focus() ;
		return false ;
	}
	if(document.frmreg.gender.value == "N_A") {
		alert("Please specify your gender") ;
		return false ;
	}
	if(document.frmreg.year.value == 0 || document.frmreg.month.value == 0 || document.frmreg.month.value == 0) {
		alert("Please provide a valid date of birth") ;
		return false ;
	}
	return true ;
}

/* Import Contacts */
function select_all(CheckValue){
	var objCheckBoxes = document.frm_srchres.appr_email;
	if(!objCheckBoxes)
	return;

	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
	updateHF();
}

function updateHF() {
	document.frm_srchres.hf_email_appr.value = "" ;
	// if more than one checkbox
	var info = "";
	if(document.frm_srchres.appr_email.length) {
		for(var i=0; i < document.frm_srchres.appr_email.length; i++){
			if(document.frm_srchres.appr_email[i].checked) {
				info += document.frm_srchres.appr_email[i].value + "," ;
			}
		}
	}
	// if only one checkbox
	if(document.frm_srchres.appr_email.checked) {
		info += document.frm_srchres.appr_email.value + "," ;
	}
	info = info.substr(0,info.length-1) ;
	document.frm_srchres.hf_email_appr.value = info ;
	//alert(document.frm_srchres.hf_email_appr.value) ;
}

function selectDiv() {
	var cbval = document.getElementById("cbtype").value ;
	if(cbval == "import_email") {
		document.getElementById("import_email").style.display = "inline" ;
		document.getElementById("import_social").style.display = "none" ;
		document.getElementById("import_csv").style.display = "none" ;
		document.getElementById("import_manual").style.display = "none" ;
	}
	else if(cbval == "import_social") {
		document.getElementById("import_email").style.display = "none" ;
		document.getElementById("import_social").style.display = "inline" ;
		document.getElementById("import_csv").style.display = "none" ;
		document.getElementById("import_manual").style.display = "none" ;
	}
	else if(cbval == "import_csv") {
		document.getElementById("import_email").style.display = "none" ;
		document.getElementById("import_social").style.display = "none" ;
		document.getElementById("import_csv").style.display = "inline" ;
		document.getElementById("import_manual").style.display = "none" ;
	}
	else if(cbval == "import_manual") {
		document.getElementById("import_email").style.display = "none" ;
		document.getElementById("import_social").style.display = "none" ;
		document.getElementById("import_csv").style.display = "none" ;
		document.getElementById("import_manual").style.display = "inline" ;
	}
}

function checkIFData() {
	var ret_val = true ;
	var sel_val = document.getElementById("cbtype").value ;
	if(sel_val == 'import_email' || sel_val == 'import_social') {
		if(document.frm_import_friends_email.email.value == "")
			ret_val = false ;
		if(document.frm_import_friends_email.pass.value == "")
			ret_val = false ;
	}
	if(document.getElementById("is_guest").value == 1 && sel_val == 'import_csv') {
		if(document.frm_import_friends_csv.txtname.value == "")
			ret_val = false ;
		if(document.frm_import_friends_csv.txtemail.value == "")
			ret_val = false ;
	}
	if(document.getElementById("is_guest").value == 1 && sel_val == 'import_manual') {
		if(document.frm_import_friends_manual.txtname.value == "")
			ret_val = false ;
		if(document.frm_import_friends_manual.txtemail.value == "")
			ret_val = false ;
		if(document.frm_import_friends_manual.txtemails.value == "")
			ret_val = false ;
	}
	if(ret_val == false)
		alert("Please fill up all the fields to continue") ;
	return ret_val ;
}

/* Both Invite Friends And Step1 page */
function checkData() {
	var ret_val = true ;
	if(document.getElementById("email").value == "")
		ret_val = false ;
	if(document.getElementById("pass").value == "")
		ret_val = false ;
	if(ret_val == false)
		alert("Please fill up all the fields to continue") ;
		
	return ret_val ;
}

/* User Home */
function selectChannels() {
	var cbval = "" ;
	
	for (var i=0; i < document.frm_new_topic.rb_channel.length; i++) {
		if (document.frm_new_topic.rb_channel[i].checked)
			cbval = document.frm_new_topic.rb_channel[i].value;
	}
	if(cbval == "my_channels") {
		document.getElementById("my_channels").style.display = "inline" ;
		document.getElementById("all_channels").style.display = "none" ;
	}
	else if(cbval == "all_channels") {
		document.getElementById("my_channels").style.display = "none" ;
		document.getElementById("all_channels").style.display = "inline" ;
	}
}
