// JavaScript Document

function getcity_id(id)
{
	if(id!='')
	{
		var cookie_city			=	'';
		var city_id_split		=	id.split('_');
		if($.cookie("city")!=null)
		{
			cookie_city			=	$.cookie("city").toLowerCase();
		}
		var selected_city		=	city_id_split[1].toLowerCase();
		if(cookie_city==selected_city)
		{
			$.cookie("city", null);
			var date = new Date();  
			date	 = (date.getTime() + (60 * 60));
			$.cookie("city", city_id_split[1],{path:'/'});//,{ path: '/',expires: date}	
			var selected_city	=	$.cookie("city").toLowerCase();
			//window.location.href=	site_url+"cities/"+selected_city;
			parent.window.location.href = top.window.location.href;
		}
		else
		{
			if($.cookie("city")=='' || $.cookie("city")==null)
			{
				$.cookie("city", null);
				var date = new Date();  
				date	 = (date.getTime() + (60 * 60));
				$.cookie("city", city_id_split[1],{path:'/'});//,{ path: '/',expires: date}	
				var selected_city		=	$.cookie("city").toLowerCase();
				//window.location.href 	=	site_url+"cities/"+selected_city;
				parent.window.location.href = top.window.location.href;
			}
			else
			{
				$("#set_city_selected").val(id);
				$(".error_div").css("display","block");
				$(".cityList").css("display","none");	
			}	
		}
	}
}


$(document).ready(function(){
   $(".error_div").css("display","none");
   $("#set_flag").val(0);
});

function setNew_cookie()
{
	//$.session("cart_string",null);
	delete_set_session();
}

function cancel_city()
{
	$("#set_flag").val(0);
	$(".error_div").css("display","none");
	$(".cityList").css("display","block");	
	$.prettyPhoto.close();
}

function delete_set_session()
{
	$.ajax({
			type	: "POST",
			url		: site_url+"ajaxforms/delete-session-ajax.php",
			data	: 'action=delete_session',
			success	: function(msg)
					{
						var city_id_split	=	$("#set_city_selected").val().split('_');
						$.cookie("city", null);
						var date = new Date();  
						date	 = (date.getTime() + (60 * 60));
						$.cookie("city", city_id_split[1],{path:'/'});//,{ path: '/',expires: date}
						var selected_city		=	$.cookie("city").toLowerCase();
						//window.location.href =site_url+"cities/"+selected_city;
						parent.window.location.href = top.window.location.href;
					}
	});
}


function showErrorMessage(formId,msg)
{
	var errorData,i,errVal;
	errorData=msg.split('#');
	
	$("#"+formId+" :input").each(function(){
		var id= this.id;			
		if(id)
		{
			$("#"+id).removeClass("error");
			$("#li_"+id).removeClass("bg_error");
		}
	});
	
	$("#"+formId+" div").each(function(){									   
		if(this.id.indexOf("error_") != "-1")
		{			
			this.style.display="none";
		}
	});
	first_msg = 0;
	
	var counter		= 0;
	var first_error	= "";
	
	for(i=1; i<errorData.length; i++){			
		errVal = errorData[i].split('@@');			
		if(errVal[0]	!=	"")
		{
			$("#"+errVal[0]).addClass("error");
			$("#li_"+errVal[0]).addClass("bg_error");
			$("#error_"+errVal[0]).css("display","block");			
			$("#error_"+errVal[0]).html(errVal[1]);
			//$('input[type="text"]').addClass("error");  
			if(first_error == "")
			{				
				counter 	= 1;
				first_error	= errVal[0];
				if(first_error	==	'common')
				{
					first_error	=	'error_'+first_error;
				}
					 
			}
		}
	}
} 

function show_msg(status,dbid)
{
	if(status=="add")
		{
			$("#err_box").html("<p>Record successfully Added.</p>");
		}
	else if(status=="update")
		{
			$("#err_box").html("<p>Record successfully Updated.</p>");
		}
	else if(status=="delete")
		{
			$("#err_box").html("<p>Record successfully Deleted.</p>");
		}
	else if(status=="sortedit")
		{
			$("#err_box").html("<p>Sort Order successfully Upadted.</p>");
		}
	else if(status=="Activate")
		{
			$("#err_box").html("<p>User successfully Activated.</p>");
		}	
	else if(status=="Deactivate")
		{
			$("#err_box").html("<p>User successfully Deactivated.</p>");
		}
	else if(status=="search")
		{
			$("#err_box").html("<p>Search results Found.</p>");
		}
	else if(status=="useradd")
		{
			$("#err_box").html("<p>User successfully added to the team.</p>");
		}
	else if(status=="approval")
		{
			$("#err_box").html("<p>Changes are pending for superuser approval.</p>");	
		}
	else if(status=="approved")
		{
			$("#err_box").html("<p>Master record updated sucessfully.</p>");	
		}
	else if(status=="unapporved")
		{
			$("#err_box").html("<p>Change unapproved.</p>");	
		}
	else if(status=="pending")
		{
			$("#err_box").html("<p>Change has moved to pending list.</p>");	
		}
	$("#err_box").highlightFade({color:'#e8fdd3',speed:1000,iterator:'exponential'});
	if(dbid!="NoEffect")
		{
			$("#rec_"+dbid).highlightFade({color:'#e8fdd3',speed:1000,iterator:'exponential'});
		}
	//$("#err_box").fadeIn("slow");
	/*$("#err_box").css("background","#E9E9E9");*/
	$("#err_box").css("display","block");
	$("#err_box").addClass("success_box");
	/*$("#err_box").css("color","#009900");*/
}

