// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function ajax_updator(url)
{	new Ajax.Request(url, {
		 method: 'get',
		 onSuccess:function(request){window.location.reload();},
		 onFailure: function(){ alert('Unable to load states.'); },
		 onException: function(o, e){ alert(e); }
	});
}
function new_ajax_updator(url)
{	new Ajax.Request(url, {
		 method: 'get',
		 onSuccess:function(request){window.location.reload();},
		 onFailure: function(){ alert('Unable to load states.'); },
		 onException: function(o, e){ alert(e); }
	});
}
function check_file_status(){
	if($('image_loading').style.display == 'block'){
		return false;
	}
	else{
		return true;
	}
}
function change_send_to(id,type,names){
	$("feed_group_id").value = "";
	$("feed_event_id").value = "";
	$("feed_course_id").value = "";        
        $("feed_feed_type").value = "";
        var text = "";
        if (type == 'followers'){
              text = "<a href='#'>Followers</a>";
              $("feed_feed_type").value = $("feed_type_followers").value;
	}
        else if(type == 'campus')
        {     text = "<a href='#'>Campus</a>";
              $("feed_feed_type").value = $("feed_type_campus").value;
        }
        else{
              $("feed_" + type + "_id").value = id;
              text = "<a href='#'>" + names + "</a>";
	}
        $('target_feed_type').innerHTML = text;
}
function show_content(url){
	window.location = url
}

//To show messages in top notification bar
// type can be 'error' or 'notice'
function show_notification(msg, type)
{   var msg_obj = document.getElementById('message')

    msg_obj.innerHTML = "<div class=\"" + type + "\"><img src=\"images/info.png\" />&nbsp;&nbsp;<span id=\"inner_msg\">" + msg + "</span></div>";
    msg_obj.style.display = "";
    setTimeout("new Effect.Fade('message');", 4000)
}


function feed_loading(){	
	$("more_feeds_loading").style.display ='block';
	$("more_btn").innerHTML ='';
}
function feed_loaded(){		
	$("more_feeds_loading").style.display ='none';	
}

function group_loading(){
	 window.location.reload();
}


function funvalid(FormID,actiontype)
{
var hasError = false;
var inputType;
var inputname;	
var collection = $('#'+FormID);
errorlist   = $(document.createElement("ul")).attr("id","Error-list");
		$('#'+FormID+' select.required,#'+FormID+' input.required,#'+FormID+' textarea.required').each(function() {
			inputType = $(this).attr("type");
			inputname   = $(this).attr("name");
			classname   = $(this).attr("class");
			var labelText = $(this).prev('label').text().replace(':','');
			
				if(jQuery.trim($(this).val()) == ''){
					errorlist.append("<li> Invalid "+labelText+"</li>");
					hasError = true;
					$(this).attr("style","background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
				}
				
				else if($(this).hasClass('noSpecialChars')){
				var regexval = /^[0-9a-zA-Z ]+$/;
				if(!regexval.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text().replace(':','');
					errorlist.append("<li> No specialchars allowed in "+labelText+"</li>");
					hasError = true;
					$(this).attr("style","background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
				}else{
					$(this).attr("style","");
				}
			}
			else if($(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text().replace(':','');
					errorlist.append("<li> Invalid "+labelText+"</li>");
					hasError = true;
					$(this).attr("style","background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
				}else{
					$(this).attr("style","");
				}
			}
			else if($(this).hasClass('cpwd')){
				//var pwd = $('#password').val();
				//var cpwd = $('#confrimpass').val();
				var pwd= document.getElementById('password').value;
				var cpwd= document.getElementById('confrimpass').value;
				alert(pwd+"Hi"+cpwd);
				if(pwd != cpwd){
					errorlist.append("<li> Passwords doesn't not match! </li>");
					hasError = true;
					$(this).attr("style","background:none repeat scroll 0 0 #FFDBDB;border:1px solid red;");
				}else{
					$(this).attr("style","");
				}
			}
				
				
		});
				
				
		if(hasError){
		document.getElementById('displayformErrors').innerHTML = "";
		$("#displayformErrors").append(errorlist);
		//scrollTo('FormErrorClass');
		//return false;
   	 }
	 else{
		document.getElementById('displayformErrors').innerHTML = "";
		$("#displayformErrors").append("");
		if(actiontype == "ajax"){
			var postdata = $("#"+FormID).serialize();
			var success = function(t){page_Complete(response);}
			var failure = function(t){ShowOnFailure(t);}
			var url = "ajax.php";
			var pars = postdata;
			var response = $.ajax({type: "post",url:url,data: pars,success: success});
		}else{
			
			document.getElementById(FormID).submit();
			return true;
		}
	}
	return false;

}


function checkformvalidation(FormID,fActionValue){
	
	var name=document.getElementById('Contact_name').value;
	var email=document.getElementById('email').value;
	var subj=document.getElementById('subject').value;
	var messge=document.getElementById('Contact_message').value;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	
	if(name=='')
	{
		alert("Please Enter the Name Field");
		document.getElementById('Contact_name').focus();
		return false;
	}
	if(email=='')
	{
		alert("Please Enter the Email Field");
		document.getElementById('email').focus();
		return false;
	}
   if(reg.test(email) == false) {
      alert('Invalid Email Address');
      return false;
   }
	if(subj=='')
	{
		alert("Please Enter the Subject Field");
		document.getElementById('subj').focus();
		return false;
	}
	if(messge=='')
	{
		alert("Please Enter the Message Field");
		document.getElementById('messge').focus();
		return false;
	}
	else
	{
		document.getElementById(FormID).submit();
		return true;
	}
	
}


function funvalidation()
{
    var fullname=document.getElementById('user_fullname').value;
	var email=document.getElementById('user_email').value;
	var password=document.getElementById('user_password').value;
	var confirmation=document.getElementById('user_password_confirmation').value;
	var title=document.getElementById('user_title').value;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	

}

function deletecompleted(itemdiv){
	//var d = document.getElementById('feedmaindiv');
	//alert(itemdiv);
	  //var olddiv = document.getElementById(itemdiv);
	 // d.removeChild(olddiv);
	if(typeof itemdiv== 'string') itemdiv=document.getElementById(itemdiv);
    if(itemdiv && itemdiv.parentNode)itemdiv.parentNode.removeChild(itemdiv);
	var msgCnt	=	document.getElementById("msgsCnt").innerHTML;
	var newCnt	=	parseInt(msgCnt)-1;
	document.getElementById("msgsCnt").innerHTML	=	newCnt;
}

var k		=	0;
var	preId	=	'';
function change_rely(val)
{
	
	if(document.getElementById(val).innerHTML	!=''	&&	k==1 && preId==val){
		document.getElementById(val).innerHTML	=	'';
		k	=	0;
	}
	if(document.getElementById(val).innerHTML	!=''){
		k		=	1;
		if(preId	!=val && preId!=''){
			document.getElementById(preId).innerHTML	=	'';
		}
		preId	=	val;
	}
	
}
function hideDiv(divId,txtval){
	if(txtval	==''){
		document.getElementById("reply_"+divId).innerHTML	=	'';
		//k	=	0;
	}
}
