function vote(post_id,str){
	new Ajax.Updater('div_for_'+post_id, '/session/post_vote?pid='+post_id+'&vote='+str, {asynchronous:true, evalScripts:true});
}

function create_user(){
	document.getElementById('login_error').innerHTML="";
	document.getElementById('name_error').innerHTML="";
	document.getElementById('password').innerHTML="";
	document.getElementById('confirm_password').innerHTML="";
	var no_error=true;
	
	if(trim(document.getElementById('name').value) ==""){
		document.getElementById('name_error').innerHTML = "Please enter name."
		no_error = false;
	}
	if(trim(document.getElementById('login').value) ==""){
		document.getElementById('login_error').innerHTML = "Please enter login / email."
		no_error = false;
	}else if(!isemail(trim(document.getElementById('login').value))){
		document.getElementById('login_error').innerHTML = "Please enter valid email address."
		no_error = false;
	}
	if(trim(document.getElementById('password').value) ==""){
		document.getElementById('password_error').innerHTML = "Please enter password."
		no_error = false;
	}else if(trim(document.getElementById('password').value).length <6){
		document.getElementById('password_error').innerHTML = "Please enter at least 6 characters for password."
		no_error = false;
	}
	if(trim(document.getElementById('confirm_password').value) ==""){
		document.getElementById('confirm_password_error').innerHTML = "Please enter confirm password."
		no_error = false;
	}else if(trim(document.getElementById('password').value) != trim(document.getElementById('confirm_password').value)){
		document.getElementById('confirm_password_error').innerHTML = "Confirm password should match password."
		no_error = false;
	}
    if (no_error==true){
		
       var form = document.getElementById("create_user");
	   
		if(form.action!=""){
			form.submit();
			form.action=""
			return true;
		}
			
    }
	return false;
}
function update_user(){
	document.getElementById('name_error').innerHTML="";
	var no_error=true;
	
	if(trim(document.getElementById('name').value) ==""){
		document.getElementById('name_error').innerHTML = "Please enter name."
		no_error = false;
	}
	if (no_error==true){
		
       var form = document.getElementById("create_user");
	   
		if(form.action!=""){
			form.submit();
			form.action=""
			return true;
		}
			
    }
	return false;
}
function login_form(){
	
	document.getElementById('login_error').innerHTML="";
	document.getElementById('password_error').innerHTML="";
	var no_error=true;
	
	if(trim(document.getElementById('login').value) ==""){
		document.getElementById('login_error').innerHTML = "Please enter login / email."
		no_error = false;
	}else if(!isemail(trim(document.getElementById('login').value))){
		document.getElementById('login_error').innerHTML = "Please enter valid email address."
		no_error = false;
	}
	if(trim(document.getElementById('password').value) ==""){
		document.getElementById('password_error').innerHTML = "Please enter password."
		no_error = false;
	}else if(trim(document.getElementById('password').value).length<5){
		document.getElementById('password_error').innerHTML= "Password should be at least 5 characters long."
		no_error = false;
	}
    if (no_error==true){
		var form = document.getElementById("login_form");
	   
		if(form.action!=""){
			form.submit();
			form.action=""
			return true;
		}   
		return true;
	}
	return false;
}
function forgot_password(){
	
	document.getElementById('login_error').innerHTML="";
	var no_error=true;
	
	if(trim(document.getElementById('login').value) ==""){
		document.getElementById('login_error').innerHTML = "Please enter login / email."
		no_error = false;
	}else if(!isemail(trim(document.getElementById('login').value))){
		document.getElementById('login_error').innerHTML = "Please enter valid email address."
		no_error = false;
	}
	
    if (no_error==true){
		var form = document.getElementById("forgot_password_form");
	   
		if(form.action!=""){
			form.submit();
			form.action=""
			return true;
		}   
		return true;
	}
	return false;
}
function change_user_password(){
	document.getElementById('confirm_password_error').innerHTML="";
	document.getElementById('password_error').innerHTML="";
	var no_error=true;
	if(trim(document.getElementById('password').value) ==""){
		document.getElementById('password_error').innerHTML = "Please enter password."
		no_error = false;
	}else if(trim(document.getElementById('password').value).length<5){
		document.getElementById('password_error').innerHTML= "Password should be at least 5 characters long."
		no_error = false;
	}
	if(trim(document.getElementById('confirm_password').value) ==""){
		document.getElementById('confirm_password_error').innerHTML = "Please enter confirm password."
		no_error = false;
	}else if (trim(document.getElementById('confirm_password').value)!= trim(document.getElementById('password').value)){
		document.getElementById('confirm_password_error').innerHTML = "confirm password should be same as password."
		no_error = false;
	}
	if (no_error==true){
		var form = document.getElementById("password_form");
	   
		if(form.action!=""){
			form.submit();
			form.action=""
			return true;
		}   
		return true;
	}
	return false;
}
function clear_post_messages(){
	document.getElementById('pmessage_error').innerHTML="";
	document.getElementById('pemail_error').innerHTML ="";
	document.getElementById('pthumbnail_error').innerHTML ="";
	document.getElementById('paudio_error').innerHTML ="";
	document.getElementById('info_div_for_post').innerHTML="Please wait...";

}
function add_text(){
	clear_post_messages();
	//	Video: asf, avi, flv, mov, mpg, mpeg, mp4, qt, smil, swf, wmv, 3g2, 3gp
 	//	Audio: aif, aac, au, gsm, mid, midi, mov, mp3, m4a, snd, rm, wav, wma
 	//	Other: bmp, html, pdf, psd, qif, qtif, qti, tif, tiff, xaml
	var audio = ["aif","aac","au","gsm","mid","midi","mov","mp3","m4a","snd","rm","wav","wma"]
	var photo = ["jpg","jpeg","gif","png"]
	var no_error=true;
	var m = document.getElementById('pmessage').value;
	var e = null;
	if(document.getElementById('entry_email').style.display!='none')
	{
		e = document.getElementById('pemail').value;
	}
	var aud = document.getElementById('audio').value;
	var thumb = document.getElementById('thumbnail').value;
	var age = document.getElementById("age");
	var a = age.options[age.selectedIndex].value;
	var cat = document.getElementById("cat");
	var c = cat.options[cat.selectedIndex].value;
	if(trim(m) ==""){
		document.getElementById('pmessage_error').innerHTML = "Please enter your story."
		no_error = false;
	}
	if(document.getElementById('entry_email').style.display!='none' && e!=null && trim(e)==""){
		document.getElementById('pemail_error').innerHTML = "Please enter Email Address."
		no_error = false;
	}else if(document.getElementById('entry_email').style.display!='none' && e!=null && !isemail(trim(e))){
		document.getElementById('pemail_error').innerHTML = "Please enter valid Email Address."
		no_error = false;
	}
	
	if (!thumb == ""){
		var photo_format=thumb.split('.')[1].toLowerCase();
		var valid = false;
		for(var i=0;i<photo.length;i++){
			if (photo_format==photo[i]){
				valid=true;
				break;
			}
		}
		if(!valid){
			document.getElementById('pthumbnail_error').innerHTML ="Please upload .gif, .jpg or .png photo.";
			no_error=false;
		}
	}
	if (!aud == ""){
		var audio_format=aud.split('.')[1].toLowerCase();
		var valid = false;
		for(var i=0;i<audio.length;i++){
			if (audio_format==audio[i]){
				valid=true;
				break;
			}
		}
		if(!valid){
			document.getElementById('paudio_error').innerHTML ="Please upload .aif, .aac, .au, .gsm, .mid, .midi, .mov, .mp3, .m4a, .snd, .rm, .wav or .wma file";
			no_error=false;
		}
	}
	
    if (no_error == true) {
//		new Ajax.Updater('info_div_for_post', '/post/add?message=' + m + '&cat=' + c + '&email=' + e + '&age=' + a, {
//			asynchronous: true,
//			evalScripts: true
//		});
		document.getElementById('post_form').submit();
		show_loading('post');
		document.getElementById('pmessage').value="";
	}
	else {
		document.getElementById('info_div_for_post').innerHTML = "";
		return false;
	}
}
function character_limits(ele, max, info_ele){
	if (ele){
		if(ele.value.length > max){
			ele.value = ele.value.substring(0, max);
			info_ele.innerHTML = "Charater limit is only "+max
			
		}
	}
}
function post_comment_form(){
	if(post_comment()==true){
		var form = document.getElementById("comment_form");
		show_loading('comment');
		form.submit();
	}
	
}
function post_comment(){
	document.getElementById('comment_error').innerHTML="";
	if(document.getElementById('comment_entry_email').style.display!='none')
	{ 
		document.getElementById('email_error').innerHTML="";
	}	
	var no_error=true;
	
	if(trim(document.getElementById('comment').value) ==""){
		document.getElementById('comment_error').innerHTML = "Please enter your Comment."
		no_error = false;
	}
	if(document.getElementById('comment_entry_email').style.display!='none' && trim(document.getElementById('email').value) ==""){
		document.getElementById('email_error').innerHTML = "Please enter your Email Address."
		no_error = false;
	}else if(document.getElementById('comment_entry_email').style.display!='none' && !isemail(trim(document.getElementById('email').value))){
		document.getElementById('email_error').innerHTML = "Please enter a valid Email Address."
		no_error = false;
	}
    if (no_error==true){		
		return true;
	}
	return false;
}