function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function tb_remove1() {
	 	$("#TB_imageOff").unbind("click");
		$("#TB_closeWindowButton").unbind("click");
		$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
		$("#TB_load").remove();
		if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
			$("body","html").css({height: "auto", width: "auto"});
			$("html").css("overflow","");
		}
		document.onkeydown = "";
		document.onkeyup = "";
		return false;
	}
	
	
	function resetError(){
		error = null;
		error = new Array;
		if (typeof(to_hide) == 'object') for (var i in to_hide) if (document.getElementById(to_hide[i])) document.getElementById(to_hide[i]).style.display='none';
		if (typeof(to_changeClass) == 'object') for (var i in to_changeClass) if (document.getElementById(to_changeClass[i])) document.getElementById(to_changeClass[i]).className='';
	}
	
	function show_button(act){
		if (!typeof(button_id) || typeof(button_id)=='undefined') return ;
		if (act) {
			if (document.getElementById(button_id)) {
				document.getElementById(button_id).disabled = true;
			 	document.getElementById(button_id).value = 'Waiting...';
			}
		}
			else {
				if (document.getElementById(button_id)) {
					document.getElementById(button_id).disabled = false;
					document.getElementById(button_id).value = 'Submit';
				}
			}
	}
	
	function post_page(idd){
		show_button(true);
		var options = { 
				beforeSubmit:  resetError,  // pre-submit callback 
				success:       showResponse,  // post-submit callback 
				error: function(){show_button(false);},
				type:      'post' ,       // 'get' or 'post', override for form's 'method' attribute 
				dataType:  'script' ,       // 'xml', 'script', or 'json' (expected server response type) 
				clearForm: false,        // clear all form fields after successful submit 
				resetForm:false
		};
		$("#"+idd).ajaxSubmit(options);
	}
	
	function showResponse(data){
		var ari_name;
		var ari_obj;
		eval(data);
		var found_error = false;
		for (var i in error) {
			if (document.getElementById('td_'+i)) document.getElementById('td_'+i).className='style1';
			if (document.getElementById('td_'+i)) document.getElementById('td_'+i).style.display='inline';
			found_error = true;
		}
		if (!found_error) {
			alert(msg_success);
			var userAgent = navigator.userAgent.toLowerCase();
			if (otherwin){
				history.go(-1)
				//history.back(1);
			} else {
				tb_remove1();
			}
			
		}	else {
			show_button(false);
			change_ari(ari_obj,ari_name);
		}
	}
	
	function change_ari(obj,lov){
		if (!obj) obj = 'ari';
		if (!document.getElementById(obj)) return ;
		a=Math.random(4,100);
		//alert(document.getElementById(obj).src);
		document.getElementById(obj).src="includes/ari.php?l="+lov+"&r="+a;
	}
	
	function Get_Cookie( check_name ) {
				// first we'll split this cookie up into name/value pairs
				// note: document.cookie only returns name=value, not the other components
				var a_all_cookies = document.cookie.split( ';' );
				var a_temp_cookie = '';
				var cookie_name = '';
				var cookie_value = '';
				var b_cookie_found = false; // set boolean t/f default f
			
				for ( i = 0; i < a_all_cookies.length; i++ )
				{
					// now we'll split apart each name=value pair
					a_temp_cookie = a_all_cookies[i].split( '=' );
			
			
					// and trim left/right whitespace while we're at it
					cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
			
					// if the extracted name matches passed check_name
					if ( cookie_name == check_name )
					{
						b_cookie_found = true;
						// we need to handle case where cookie has no value but exists (no = sign, that is):
						if ( a_temp_cookie.length > 1 )
						{
							cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
						}
						// note that in cases where cookie is initialized but no value, null is returned
						return cookie_value;
						break;
					}
					a_temp_cookie = null;
					cookie_name = '';
				}
				if ( !b_cookie_found )
				{
					return null;
				}
			}
			
			function Set_Cookie( name, value, expires, path, domain, secure ){
				// set time, it's in milliseconds
				var today = new Date();
				today.setTime( today.getTime() );
				if ( expires ){	expires = expires * 1000 * 60 * 60 * 24;}
				var expires_date = new Date( today.getTime() + (expires) );
				old = Get_Cookie(name);
				if (!old || old=='null' || old==null) old='';
				document.cookie = name + "=" +old+'|'+escape( value ) +
				( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
				( ( path ) ? ";path=" + path : "" ) +
				( ( domain ) ? ";domain=" + domain : "" ) +
				( ( secure ) ? ";secure" : "" );
				
				}
		
		function number_format( number, decimals, dec_point, thousands_sep ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     
 
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
  }