var site_timeout = '';
var Functions = {
	frame_send : function(s,v){
		var url = s+'.php?'+v;
		Functions.resetTimeout();
		Functions.initTimeout();
		site_timeout = setTimeout("Functions.timed_out();", 29000);
		$('#response').hide();
		$('html, body').animate({scrollTop: $('#site').offset().top},
			function(){
					$('#content').animate({height:'hide'},
						function(){
							$('#loader').fadeIn();
							setTimeout("window.open('"+url+"', 'iframe')",1000);
							return false;
						});
			});
	},
	framed_response : function(d){
		Functions.resetTimeout();
		$('#loader').fadeOut(
			function(){
				$('#response').html(d.msg);
				$('#response').animate({height:'show'},
					function(){
						if(d.status == 1){
							$('#content').animate({height:'show'});
						}
						if(d.call){
							setTimeout("window.open('"+d.call+"', '_self')",1000);
						}
					});
		});
	},
	stripHTML:function(){
		var re= /<\S[^><]*>/g
		for (i=0; i<arguments.length; i++){
			arguments[i].value = arguments[i].value.replace(re, "");
		}
	},
	insert:function(theform, text) { 
		var theform = $('#'+theform);
		var _val = theform.val();
		ToLength  = _val.length;
		var info = _val;
		info += (ToLength != 0) ? ' / ' + text:text;
		theform.val(info);
		theform.focus();

	},
	initTimeout : function(){
		site_timeout = setTimeout("Functions.timed_out();", 29000);	
	},
	resetTimeout : function(){
		clearTimeout(site_timeout);
	},
    timed_out: function(){
	    Functions.resetTimeout();
	    $('#loader').fadeOut(
			function(){
				$('#response').html('Maximum server execution time exceeded!<br />The server encountered an error or simply timed out. Please try again in a few minutes or contact the system administrator if the problem persists.');
				$('#response').fadeIn(
					function(){
						$('#content').animate({height:'show'},
							function(){
								setTimeout("$('#response').fadeOut();", 3000);
							});	
					});
			});
    }
}