/*
 * function    : submit_form
 * description : function will ajax response
 *
 * @param 		ajax_url		URL where call ajax call is to be made 
 * @param 		form 			id of 'form' from which data is to be serialized and submitted
 * @param 		form_div 		id of 'form' where ajax response is loaded
 */
function form_submit(ajax_url, form, form_div)
{	
	//$('#divload').html('<img src="http://192.168.0.2/bbw/ui/images/admin/ajaxLoader.gif" />') ;	
	//alert(form_div);
	$.ajax({
			type	: "POST",
			url		: ajax_url,
			data	: $("#"+form).serialize(),
			success	: function(response) {
						//alert(response);
					  $("#"+form_div).html(response);//$("#state").chosen();
					  var notification = $('#hidden_notification').val();
					  $('#notification').html(notification) ;
					}
	});
	
	
}	
/*
 * submit register form
 */
function form_register(ajax_url, form, form_div, success_url)
{	 
	$.ajax({
			type	: "POST",
			url		: ajax_url,
			data	: $("#"+form).serialize(),
			success: function(response)
			{	
				var response_split = response.split("@#success#@");
				response_split_length = response_split.length;
				
				if (response_split_length >= 2) 
				{
					$("#content_box").html(response_split[1]);
					// on success	
					 	
					// if(response_split[1]==6)
					// alert("Registration successful, Mail sent successfully to ur mail id.");
					// else
					// alert("Registration successful, Mail couldn't be sent.")			 
					//window.location.href = success_url; 
				}
				else 
				{
					//on failure			 	
					$("#" + form_div).html(response);
				}
			}
	});
	
	
}
/*
 * function    : cancel_form_submit
 * description : Do not submit  the form only load the response in perticular div
 *
 * @param 		ajax_url		URL where call ajax call is to be made 
 * @param 		form_div 		id of 'form' where ajax response is loaded
 */

function cancel_form_submit(ajax_url, form_div)
{	
	$('#divload').html('<img src="http://192.168.0.2/bbw/ui/images/admin/ajaxLoader.gif" />') ;	
	$.ajax({
			
			url		: ajax_url,
			success	: function(response) {		
					  $("#"+form_div).html(response);
					   
					}
	});
	
}
/*  written to support jquery.greybox.js
 * 
 */
function save_form(ajax_url, form, form_div)
{
	form_submit(ajax_url, form, form_div);
}

function cancel_form(ajax_url, form, form_div)
{	
	form_submit(ajax_url, form, form_div);
	 
}

function confirm_and_submit(message, ajax_url, form, form_div)
{	  
	if(confirm(message))
	{		
		form_submit(ajax_url, form, form_div);								
	}	
}

/*** Code for auto save starts here ***/
var auto_save_time = 50;
function auto_save(url, form, editor_id, textbox_id) 
{	
	if((typeof(tinyMCE.getInstanceById(editor_id)) != "undefined"))
	{	
		var content = tinyMCE.get(editor_id);
		$("#hidden_description").val(content.getContent());
		
		$("#auto_save_id").html("Saving ....");
		
		$.ajax({
			url: url, // the path/name that will process our request
			type: "POST", 
			data: $("#"+form).serialize(), 
			success: function(response) {
			var response_split 	= response.split("@#message#@");
				$("#auto_save_id").html("Auto saved");
				$("#auto_save_pre_id").html(response_split[1]);
				
				$("#cancel_div_id").html(response_split[2]);
				
				seconds = auto_save_time + 1;
				setTimeout("display('"+ url + "')",1000);
			}
		});
	}	
}

var seconds = auto_save_time + 1;
function display(url)
{ 
	seconds = seconds - 1 ;
	
	if (seconds > 0)
	{ 
		var seconds_text = (seconds == 1 ? 'second' : 'seconds');
	    $('#auto_save_id').text("Auto save in " + seconds + " " + seconds_text);
	    setTimeout("display('" + url + "')",1000) ;
	}
	else
    {	
		auto_save(url, 'postdata', 'description', 'text_content');
    }
} 
function disable_submit()
{		 
   $("#operate").attr("disabled", "true");
}
function redirect(url)
{
	  
	  $("#frmpaidreg").attr("action",url);  
	   
	   
}

function hide_div(id)
{
	
	$("#"+id).slideUp("slow");
	
}
function show_div(id)
{		
	if ($("#"+id).css("display")=="none")
	{		
        $("#"+id).slideDown("slow");
		 
    }
	else
	{
       	$("#"+id).slideUp("slow");
		 
    }
 }
/*** Code for auto save ends here ***/


	/*
	 * function    : ajax_submit
	 * description : function will ajax response using json
	 *
	 * @param 		ajax_url				URL where call ajax call is to be made 
	 * @param 		form 						id of 'form' from which data is to be serialized and submitted
	 * @param 		form_div 				id of 'form' where ajax response is loaded
	 */
	function ajax_submit(ajax_url, form, form_div)
	{	
		$.ajax({
			type	: "POST",
			url		: ajax_url,
			data	: $("#"+form).serialize(),
			success	: function(response) {
				var json_data_object 	= eval("(" + response + ")");
				var success_flag  		= json_data_object['flag'];	
							
				if((success_flag == '@#success#@') || (success_flag == '@#sorry#@'))
				{
					var view 			= json_data_object['view'];
					if(view == "redirect")
					{
						var url 			= json_data_object['url'];
						
						$("#"+form).attr("action", url);
						$("#"+form).removeAttr('onsubmit');
						$('#'+form)[0].submit();
					}
					else
					{
						var view 			= json_data_object['view'];
						$("#"+form_div).html(view);
					}						
				}
				else if(success_flag == '@#error#@')
				{
					var view 			= json_data_object['view'];
					$("#"+form_div).html(view);
				}										 
			}
		});
	}
	

		function div_animate(obj,pHeight,lText,link1,link2,class1,class2,class3)
		{
				obj.parent().find('.read').animate({height:pHeight+'px'},"slow");	
				obj.removeClass(link1).addClass(link2).text(lText);
				obj.parent().parent().find('.'+class1).removeClass(class1).addClass(class2);
				if(typeof class3 != 'undefined')
				{
						//add class3 as function using class name between []....
					obj.parent().find('.fade_shadow')[class3]();
				}
		}	
		
		function read_more_text(obj)
		{
			$(obj).toggle(function(){
					var totalheight = 	$(this).parent().find('.read').children().height();
					var shownheight = 	$(this).parent().find('.read').height();
					if(shownheight == totalheight)
					{
						var shownheight = 	$('#shownheight_div').val();
						div_animate($(this),shownheight,'Read More','link_up','link','minus','add','fadeIn');
					}
					else
					{
						div_animate($(this),totalheight,'Close','link','link_up','add','minus','fadeOut');			
					}
					
					$('#shownheight_div').val(shownheight);
					$('.read_more').not(this).each(function(){					
						div_animate($(this),shownheight,'Read More','link_up','link','minus','add','fadeIn');				
					});
			},function(){
					var totalheight = 	$(this).parent().find('.read').children().height();
					var shownheight = 	$('#shownheight_div').val();
					var p_shownheight = 	$(this).parent().find('.read').height();
					if(p_shownheight != shownheight)
					{
						div_animate($(this),shownheight,'Read More','link_up','link','minus','add','fadeIn');
					}
					else
					{
						$('.read_more').not(this).each(function(){
							div_animate($(this),shownheight,'Read More','link_up','link','minus','add','fadeIn');
						});
						div_animate($(this),totalheight,'Close','link','link_up','add','minus','fadeOut');			
					}
			});
		}
		
		
		// Pause autoscrolling if the user moves with the cursor over the clip.
		function partnersCarousel_initCallBack (carousel) {
			carousel.clip.hover(function() {
				carousel.stopAuto();
			}, function() {
				carousel.startAuto();
			});
		}
		// Pause autoscrolling if the user moves with the cursor over the clip.
		
		
		
function callback(obj) {
	$(obj).addClass('active');
}

function callback1 (obj) {
	$(obj).removeClass('active');
}	

