<!--

	var url_ajax = "/ajax.php";
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	/*
	$().ajaxStart(function(){ $.blockUI('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="178" height="178"><param name="movie" value="/images/loading_.swf" /><param name="quality" value="high" /><param name="SCALE" value="noborder" /><param name="wmode" value="transparent" /><embed src="/images/loading_.swf" width="178" height="178" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" scale="noborder" wmode="transparent"></embed></object>',{"border":"0px","background":"none"});});
	$().ajaxStop(function(){ $.unblockUI()})
	*/

	$().ajaxStart(function(){ $.blockUI('<img src="/images/ajax-loader.gif" />',{"border":"0px"});});
	$().ajaxStop(function(){ $.unblockUI()})

	/**
	*	Trim a string
	**/
	function trimAll(sInString)
	{
	  	sInString = sInString.replace( /^\s+/g, "" );// strip leading
  		return sInString.replace( /\s+$/g, "" );// strip trailing

	}

	/**
	*	Trim spaces
	**/
	function  trimSpaces(string){
		var spacefix = / /gi;
		return string.replace(spacefix,"");		
	}
	
	
	/**
	*	Redirect function
	**/
	function go2url(url){
		window.location = url;
	}
	

	/**
	*	Close open div's with categories
	**/
	function CloseOpen(id){
		var display = $("#display_"+id).val();
		if (display=='closed'){
			$("#"+id).slideDown(400);
			$("#display_"+id).attr({value:'open'});
			$("#img_"+id).attr({ src: '/images/arrow_d.gif'});
		}else{
			$("#id="+id).slideUp(400);
			$("#display_"+id).attr({value:'closed'});
			$("#img_"+id).attr({ src: '/images/arrow_r.gif'});
		}
			
	}

	/**
	*	refresh check image
	**/
	function RefreshCheck(id){
		var id = (id == null) ? "check_image" : id;	
		$("img[id*="+id+"]").attr({"src":"/images/check.jpg?"+Math.random()})
	}		
	
	
	/**
	*	Login with ajax
	**/
	function Login(){
		var RE = /ok/;
		var login 	= $("#login").val()
		var pwd	 	= $("#pwd").val()
		var code 	= $("#code").val()
		var lang = '/'+$("#lang").val()+'/';
		var url = $("#redirect_url").val();
		
		var error = '';
		if (login=='')				{error='empty_login';	field = 'login'}
		if (error=='' && pwd=='')	{error='empty_pwd';		field = 'pwd'}
		if (error=='' && code=='')	{error='empty_code';	field = 'code'}
		if (error==''){
			$.post(url_ajax,
				  {
					action : "login",
					login  : login,
					pwd	   : pwd,
					code   : code
				  },
				  function(data){
					  var arr=data.split('|');
						if (arr[0].match(RE)) {
							AlertMsg($("#loged_in").val(),'ok');
							 setTimeout (function (){go2url(url)}, 2000);
						}else{
							$("#"+arr[2]).addClass("error");
							AlertMsg($("#"+arr[1]).val(),'error');
							$("#code").val("")
							RefreshCheck();
						}
				  }
				);
		}else{
			$("#"+field).addClass("error");
			AlertMsg($('#'+error).val(),'error');
			RefreshCheck();
		}
		
	}


	/**
	*	Forgot with Ajax
	**/
	function ForgotPaswword(){
		var RE = /ok/;
		var email 	= $("#email").val()
		var code 	= $("#code1").val()
		var lang = '/'+$("#lang").val()+'/';
		
		var error = '';
		if (email=='')							{error='empty_email';}
		if (error=='' && !checkmail(email))		{error='inc_email';}
		if (error=='' && code=='')				{error='empty_code';}
		if (error==''){
			$.post(url_ajax,
				  {
					action : "forgot_password",
					email  : email,
					code   : code
				  },
				  function(data){
					  var arr=data.split('|');
						if (arr[0].match(RE)) {
							$("#login").val(arr[1]);
							RefreshCheck();
							AlertMsg($("#pwd_restored").val(),'ok');
							 setTimeout (function (){showHideLogin()}, 2000);
						}else{
							AlertMsg($("#"+arr[1]).val(),'error');
							$("#code1").val("")
							RefreshCheck();
						}
				  }
				);
		}else{
			AlertMsg($('#'+error).val(),'error');
			RefreshCheck();
		}
		
	}

	/**
	*	FaceBox Alert
	**/
	function AlertMsg(message,type){
		var type = (type == null) ? "info" : type;	
		jQuery.facebox("<table width='220' border='0' cellspacing='2' cellpadding='1'><tr align='left' valign='middle'><td width='52'><img src='/admin/img/facebox/icons/"+type+".png'></td><td>"+message+"</td></tr></table>")
	}

	

	/**
	*	Show/Hide Login/Forgot div
	**/
	function showHideLogin(){
		var login_div = $("#login_div").attr("class");
		if (login_div=='hidden'){
			$("#login_div").show("slow");
			$("#forgot_div").hide("fast");
		}else{
			$("#login_div").hide("fast");
			$("#forgot_div").show("slow");
		}
		$("#login_div").toggleClass("hidden")
	}
	
	/**
	*	check mail
	**/
	function checkmail(email){
		var returnval=emailfilter.test(email)
		return returnval
	}
	
	/**
	*	Contact with Ajax
	**/
	function ContactUs(){
		var RE = /ok/;
		var email 	= $("#email").val()
		var name 	= $("#name").val()
		var phone 	= $("#phone").val()
		var code 	= $("#code").val()
		var message	= $("#contact_message").val()
		
		var error = '';
		if (name=='')							{error='empty_name';}
		if (error=='' && email=='')				{error='empty_email';}
		if (error=='' && !checkmail(email))		{error='inc_email';}
		if (error=='' && message=='')			{error='empty_message';}
		if (error=='' && code=='')				{error='empty_code';}
		if (error==''){
			$.post(url_ajax,
				  {
					action : "contact_us",
					email  : email,
					name   : name,
					phone  : phone,
					message: message,
					code   : code
				  },
				  function(data){
					  var arr=data.split('|');
						if (arr[0].match(RE)) {
							$("input[@type=text],input[@type=password],textarea").val("");
							RefreshCheck();
							AlertMsg($("#"+arr[1]).val(),'info');
						}else{
							AlertMsg($("#"+arr[1]).val(),'error');
							$("#code").val("")
							RefreshCheck();
						}
				  }
				);
		}else{
			AlertMsg($('#'+error).val(),'error');
			RefreshCheck();
		}
		
	}


	/**
	 *	Verify if the number is integer
	 */	 
	function isNumber(id,type,fill){
		var type = (type == null) ? "int" : type;	
		var fill = (fill == null) ? true : fill;	
		var nr = $("#"+id).val()
		
		var RE = (type=="int") ? /^\d*$/ : /^\d*(\.\d{0,2})?$/;
		if (!nr.match(RE)){
			nr = nr.substring(0,(nr.length-1))
			if (!nr) {nr= (fill) ? 1 : "";}
			$('#'+id).attr({ value: nr});
			
			return true;
		}else{
			if ($('#'+id).val()=="" || $('#'+id).val()=="0") {nr= (fill) ? 1 : "";}
			$('#'+id).attr({ value: nr});
			//$('#'+id).attr({ value: "1"});
			return true;
		}
	}
	
-->