//===================================================
function Stricter()
{
	this.ajax = new Ajax();
	this.validator = new Validator();
	this.FCKEditor = null;
}

//==================================================================================
Stricter.prototype.fixPNG = function(image)
{
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ((version >= 5.5) && (version < 7) && (document.body.filters))
	{
		var imgID = (image.id) ? "id='" + image.id + "' " : "";
		var imgClass = (image.className) ? "class='" + image.className + "' " : "";
		var imgTitle = (image.title) ? 
		"title='" + image.title  + "' " : "title='" + image.alt + "' "
		var imgStyle = "display:inline-block;" + image.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + image.width 
		+ "px; height:" + image.height 
		+ "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + image.src + "\', sizingMethod='scale');\"></span>";
		image.outerHTML = strNewHTML;
	}
}

//==================================================================================
Stricter.prototype.accessCSS = function(layerID)
{
	var tstyle=null;
	try{
		if(document.getElementById){
			tstyle= document.getElementById(layerID).style; 
		} 
		else if(document.all) { 
			tstyle= document.all[layerID].style; 
		} 
		else if(document.layers) { 
			tstyle= document.layers[layerID]; 
		}
	}
	catch(ex){alert(layerID+' not found');}
	
	if(tstyle==null){
		return false;
	} else {
		return tstyle;
	}
		
}

//==================================================================================
function addMethod(object, name, fn)
{
	var old = object[ name ];
	object[ name ] = function(){
		if ( fn.length == arguments.length )
			return fn.apply( this, arguments );
		else if ( typeof old == 'function')
			return old.apply( this, arguments );
		};
}

//==================================================================================
//Created by: Cyanide_7
function autoTab(input, len, e)
{
	var isNN = (navigator.appName.indexOf("Netscape") != -1);
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)){
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele)
	{
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}

	function getIndex(input)
	{
		var index = -1, i = 0, found = false;
		while(i < input.form.length && index == -1)
		if(input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}

//===================================================
function Validator()
{
	
}
//===================================================
Validator.prototype.isString = function()
{
	
}
//===================================================
Validator.prototype.isNumeric = function()
{
	
}

//===================================================
function Ajax()
{
	this.ajaxobj = null;
	this.method = "POST";
	this.charset = "iso-8859-1";
	this.container = null;
	this.loading = null;
	this.url = null;
	this.formid = null;
	this.sync = true;

	addMethod(this, "get", function(curl, todiv){
		this.method = "GET";
		this.url = curl;
		this.container = todiv;
		this.execute();
	});
	
	addMethod(this, "get", function(mdl, act, todiv){
		this.method = "GET";
		this.url = "?mdl="+mdl+"&action="+act;
		this.container = todiv;
		this.execute();
	});

	addMethod(this, "post", function(curl, formid, todiv){
		this.method = "POST";
		this.formid = formid;
		this.url = curl;
		this.container = todiv;
		return this.execute();
	});

	addMethod(this, "post", function(mdl, act, formid, todiv){
		this.method = "POST";
		this.formid = formid;
		this.url = "?mdl="+mdl+"&action="+act;
		this.container = todiv;
		return this.execute();
	});
}

//=================================================
Ajax.prototype.execute = function() 
{
	if(this.loading)
		stricter.accessCSS(this.loading).visibility = "visible";

	var parameters = null;

	if(this.method=="POST")
		parameters = this.getFormVars(this.formid);

	if (window.XMLHttpRequest)
		this.ajaxobj = new XMLHttpRequest();
	else if (window.ActiveXObject) {
		try { this.ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try{ this.ajaxobj = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e){}
			}
	}

	if (this.ajaxobj.overrideMimeType)
		this.ajaxobj.overrideMimeType('text/xml; charset='+this.charset );

	if(stricter.ajax.sync==true) {
		this.ajaxobj.onreadystatechange = function() {
			if (stricter.ajax.ajaxobj.readyState == 4 ) {
				if (stricter.ajax.ajaxobj.status == 200) {
					result = stricter.ajax.ajaxobj.responseText;

					if(stricter.ajax.container!=null) {
						document.getElementById(stricter.ajax.container).innerHTML = result;
					}

					if(stricter.ajax.loading) {
						accessCSS(stricter.ajax.loading).visibility = "hidden";
					}
				}
			}
		}
	}
	
	this.ajaxobj.open(this.method, this.url, stricter.ajax.sync);

	this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	if(parameters)
		this.ajaxobj.setRequestHeader("Content-length", this.url.length + parameters.length);
	else
		this.ajaxobj.setRequestHeader("Content-length", this.url.length);
	this.ajaxobj.setRequestHeader("Connection", "close");
	this.ajaxobj.send(parameters);
	this.formid=null;
	
	if(stricter.ajax.sync==false) {
			result = stricter.ajax.ajaxobj.responseText;

		if(stricter.ajax.container!=null) {
			document.getElementById(stricter.ajax.container).innerHTML = result;
		}

		if(stricter.ajax.loading) {
			accessCSS(stricter.ajax.loading).visibility = "hidden";
		}	
	}
	
	return true;
}

//=================================================   
Ajax.prototype.getFormVars = function (formid)
{
	var strparams;
	var i = 0;
	var tmps;
	var poststr = "";
	var felements;

	if(document.forms[formid])
	{
		felements = document.forms[formid].elements;

		while(felements[i]!=null)
		{
			tmps = felements[i].name;

			switch(felements[i].type)
			{
				case "select-multiple":
				{
					var x = 0;
					var len = felements[i].options.length;
					var concat_sel = "";
					var num_sel;
					for(x=0; x<len; x++) {
						if(felements[i].options[x].selected == true)
							concat_sel += "&" + felements[i].name + "=" + felements[i].options[x].value;
					}
					poststr += concat_sel;

					break;
				}

				//-------------------
				case "checkbox":
				case "radio":
				{
					if(tmps==undefined)	break;
					if(felements[i].checked)
						poststr += "&" + felements[i].name +"="+ felements[i].value;
					break;
				}

				//-------------------
				default:
				{
					if(tmps==undefined)	break;
					poststr += "&" + felements[i].name +"="+ felements[i].value;
					break;
				}
			}
			
			i++;
		}
	}

	poststr = poststr.substr(1, poststr.length -1) ;

	poststr = encodeURI(poststr);

	return poststr;
}

// old api legacy
//==================================================================================
function accessCSS(layerID)
{ 
	return stricter.accessCSS(layerID);
}

// old api legacy
//==================================================================================
function ajax(mdl,action,formid,container,getvars)
{
	return stricter.ajax.post(mdl,action,formid,container);
}

stricter = new Stricter();


