// JavaScript Document
var gsa = new globalSettingsArray();
var ajax = new jax();
function globalSettingsArray(){
	this.loadedct=0;
	this.callTracker=[];
	this.callTrackerId=0;
	this.styles=[];
	this.styles.maxZ=1;
	this.styles.defaultstyle=[];
	this.styles.defaultstylesSet=false;
	this.libraryLocation = "../../mylibrary/";
	this.logErrors = true;
	this.display=[];
	this.display.IE = document.all?true:false;
	this.display.IEVersion = getVersion();
	//getWindow();
	this.callback = [];
	this.errorLog = [];
	this.errorStatus = false;
	this.panel = [];
	this.forms = [];
	this.form=[];
	this.selectPresets = [];
	this.selectionPresets = [];//  //  storage for the select presets
	this.linkOffset = '../';
	this.updateURL=this.libraryLocation+"update.php";
	this.insertURL=this.libraryLocation+"insert.php";
	this.titlesURL=this.libraryLocation+"gettitles.php";
	this.delURL =  this.libraryLocation+"delete.php";
	this.infoURL = this.libraryLocation+"getinfo.php";
	this.alerts = false;
	this.zLevel=[];
	this.passval=[];
	this.date=[];
	this.date.MonthName=["January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"];
	this.date.WeekDayName=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

}//  //  global
function getVersion(){     
		var version = 999; // we assume a sane browser    
		if (navigator.appVersion.indexOf("MSIE") != -1) {    
			var v = [];
			v = navigator.appVersion.split("MSIE"); 
			if (v[1].indexOf(".") != -1){
				var b = [];
				b=v[1].split(".");
				if (b[0].indexOf(" ") != -1){
					var c = [];
					c=b[0].split(" ");
					version = c.join("");
				}
				else
					version = b[0];
			} 
		}
		return version;  
		
}//  //  getVersion
function defineURLS(offset){
	if(offset)gsa.linkOffset = offset;
	gsa.updateURL= gsa.linkOffset+gsa.libraryLocation+"update.php";
	gsa.insertURL= gsa.linkOffset+gsa.libraryLocation+"insert.php";
	gsa.titlesURL= gsa.linkOffset+gsa.libraryLocation+"gettitles.php";
	gsa.delURL =   gsa.linkOffset+gsa.libraryLocation+"delete.php";
	gsa.infoURL =  gsa.linkOffset+gsa.libraryLocation+"getinfo.php";
}//  //  define urls
function setError(wht){
	if(!gsa.logErrors)return;
	gsa.errorLog.push(wht);
	if(!gsa.errorStatus){
		gsa.errorStatus=true;
		////if(document.getElementById('errorzone'))
		//document.getElementById('errorzone').innerHTML="<input type='button' value='check errors' onclick='errorShow()'/>";
	}
}//  //  setError
function errorShow(){
	var dis = '';
	for(i=0;i<gsa.errorLog.length;i++){
		if(gsa.errorLog[i])dis = dis+i+" "+gsa.errorLog[i]+"<br>";
	}
	gsa.panel.er.addContent(dis);
	gsa.panel.er.on();
}//  //  error show
function jax(){
	this.track = true;
	gsa.alerts = true;
	this.alertOff = function(){
		gsa.alerts = false;
	}
	this.getHTTPObject = function() {
		var ua;
		if(window.XMLHttpRequest) {
		try {
		ua = new XMLHttpRequest();
		} catch(e) {
		ua = false;
		}
		} else if(window.ActiveXObject) {
		try {
		ua = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
		ua = false;
		}
		}
		return ua;
	}
	this.get = function(url,callback,otherparam,track) {
			var tra=gsa.callTrackerId;
			if(track){
				tra = track;
				gsa.callTracker[track].ct++;
			}else{
				
				var now = "uid=" + new Date().getTime();
				url += (url.indexOf("?")+1) ? "&" : "?";
				url += now;
				gsa.callTracker[gsa.callTrackerId]= new callTrack();
				gsa.callTrackerId++;
			}
			var http = this.init(); //The XMLHttpRequest object is created at every call - to defeat Cache problem in IE
			if(!http||!url) return;
			http.open("POST", url, true);
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Connection", "close");
			http.onreadystatechange = function () {//Call a function when the state changes.
			if (http.readyState == 4){
				if(http.status == 200) {//Ready State will be 4 when the document is loaded.
					var result = "";
					if(http.responseText) {
						result = http.responseText;
					}else{ 
							if(gsa.callTracker[tra].ct>5){ 
								if(gsa.alerts)sendingproblem(tra);
							}else{
								if(this.track){
									if(otherparam) {
										ajax.get(url,callback,otherparam,tra);
									}else{
										ajax.get(url,callback,null,tra);
									}
								}
							}
					}
					if(callback){
						if(otherparam){
							callback(result,otherparam);
						}else{
							callback(result);
						}
					}
				}else{
							if(gsa.callTracker[tra].ct>5){ 
								if(gsa.alerts)sendingproblem(tra);
							}else{
								if(this.track){
									if(otherparam) {
										ajax.get(url,callback,otherparam,tra);
									}else{
										ajax.get(url,callback,null,tra);
									}
								}
							}
				}
			} else { //An error occured
					crap='';
			}
			}
			http.send(null);
	}
	this.getweather = function(url,callback,otherparam,track) {
			var tra=gsa.callTrackerId;
			if(track){
				tra = track;
				gsa.callTracker[track].ct++;
			}else{
				
				var now = "uid=" + new Date().getTime();
				url += (url.indexOf("?")+1) ? "&" : "?";
				url += now;
				gsa.callTracker[gsa.callTrackerId]= new callTrack();
				gsa.callTrackerId++;
			}
			var http = this.init(); //The XMLHttpRequest object is created at every call - to defeat Cache problem in IE
			if(!http||!url) return;
			http.open("POST", url, true);
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Connection", "close");
			http.onreadystatechange = function () {//Call a function when the state changes.
			if (http.readyState == 4){
				if(http.status == 200) {//Ready State will be 4 when the document is loaded.
					var result = "";
					if(http.responseText) {
						result = http.responseText;
					}
					if(callback){
						if(otherparam){
							callback(result,otherparam);
						}else{
							callback(result);
						}
					}
				}
			} else { //An error occured
					crap='';
			}
			}
			http.send(null);
	}
	this.post = function(url,params,callback,track) {
			var tra=gsa.callTrackerId;
			if(track){
				tra = track;
				gsa.callTracker[track].ct++;
			}else{
				params = params+"&"+"uid=" + new Date().getTime();
				gsa.callTracker[gsa.callTrackerId]= new callTrack();
				gsa.callTrackerId++;
			}
			var http = this.init(); //The XMLHttpRequest object is created at every call - to defeat Cache problem in IE
			if(!http||!url) return;
			
			http.open("POST", url, true);
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", params.length);
			http.setRequestHeader("Connection", "close");
			http.onreadystatechange = function() {//Call a function when the state changes.
				if(http.readyState == 4){
					if(http.status == 200) {
						var result = '';
						if(http.responseText){
							result = http.responseText;
						}else{
							if(gsa.alerts)sendingproblem(tra);
							ajax.post(url,params,callback,tra);
						}
						if(callback)callback(result);
					} else { 
						if(gsa.callTracker[tra].ct>5){ 
								if(gsa.alerts)sendingproblem(tra);
							}else{
								if(this.track){
									if(otherparam) {
										ajax.get(url,callback,otherparam,tra);
									}else{
										ajax.get(url,callback,null,tra);
									}
								}
							}
					}
				}
				}
			http.send(params);
	}

	this.init = function(){return this.getHTTPObject();}
}//  //  ajax

function callTrack(){
	this.ct=0;
}
var problemct=0;
var problemtimer;
function sendingproblem(tra){
	if(!gsa.serverStatus)gsa.serverStatus=[];
	gsa.serverStatus[tra]=gsa.serverStatus[tra]+1;
}
	

	
	