// JSO
// Get Element By Id - id, "parentNode";
function jso_gI(a,b)
{
	b=b||document;
	return b.getElementById(a)
}
// Get Elements By Tag Name - tagName, "parentNode";
function jso_gT(a,b,i)
{
	a=a||"*";
	b=b||document;
	b=b.getElementsByTagName(a)
	a=[]
	for(i=0;i<b.length;i++)a[a.length]=b[i];
	return a
}
// Get Elements By Attribute Value - tagName, "parentNode", attibute name, attibute value;
function jso_gAV(a,b,c,d,f,i,v)
{
	a=a||"*";
	b=b||document;
	if(!c)return false;
	b=b.getElementsByTagName(a)
	a=[]
	for(i=0;i<b.length;i++)if((v=f?b[i].getAttribute(c):v=b[i][c]||b[i].getAttribute(c))&&(!d||(v.toString().match(new RegExp("(^| )"+d+"($| )","gi"))!=null)))a.push(b[i]);;
	return a
}
// Create Element - tagName, attributes, content, parentNode, events;
function jso_cE(a,b,c,d,e,i)
{
	a=document.createElement(a)
	if(b)for(i in b)a[i]=b[i];;
	if(c)for(i in c)if(typeof c[i] != "function")a.appendChild(c[i].nodeType?c[i]:document.createTextNode(c[i]));;
	if(e)for(i in e)jso_aE(a,i,e[i]);;
	if(d)d.appendChild(a);
	return a
}
// Get Event Triggered Element
function jso_gE(x)
{
	x=x||window.event;
	x=x.target||x.srcElement;
	if(x.nodeType==3)x=x.parentNode;
	return x
}
// Add Event
function jso_aE(O,E,F)
{
	return(O.aE=O.addEventListener)?O.aE(E,F,0):(O.aE=O.attachEvent)?O.aE("on"+E,F):!1;
}
// Remove Event
function jso_rE(O,E,F)
{
	return(O.rE=O.removeEventListener)?O.rE(E,F,0):(O.rE=O.detachEvent)?O.rE("on"+E,F):!1;
}
// Stop Event Propagation
function jso_sE(e)
{
	e = e||window.event;
	if(e.preventDefault)
		e.preventDefault();
	e.returnValue=false
	return false
}
// Set Opacity
function jso_sO(a,b)
{
	if(jso_ie)
		a.style.filter='alpha(opacity='+(100*b)+')';
	else
		a.style.opacity = b;
	if(b == 1)
		jso_cO(a);
}
// Clear Opacity
function jso_cO(a)
{
	if(jso_ie)
		a.style.filter='';
	else
		a.style.opacity = '';
}
// ajax
function jso_ajax(params)
{
	var T = this
	for(var i in params)
	{
		this[i]=params[i];
	}
	this.ajax = false
	if (window.XMLHttpRequest)
	{
		this.ajax = new XMLHttpRequest();
	}
	else
	{
		this.ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (this.ajax)
	{
		if(jso_ajax.prototype.count <= 0)
		{
			jso_ajax.prototype.count = 0;
			jso_gT('body')[0].className = 'ajax_on';
		}
		jso_ajax.prototype.count++;
		this.ajax.onreadystatechange = function(){T.onreadystatechange.call(T)}
		this.method=this.method?this.method.toUpperCase():"GET";
		this.uri=this.uri||"";
		this.postData=this.postData?this.postData:null;
		this.ajax.open(this.method,this.uri, true);
		if (this.method == "POST")
		{
			this.ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		}
		this.ajax.send(this.postData)
		this.ok = true
	}
	else
	{
		this.ok = false
	}
}
jso_ajax.prototype.onreadystatechange = function()
{
	switch(this.ajax.readyState)
	{
		case 0:
			if(this.onUninitialized)
			{
				this.onUninitialized();
			}
			break;
		case 1:
			if(this.onLoading)
			{
				this.onLoading();
			}
			break;
		case 2:
			if(this.onLoaded)
			{
				this.onLoaded();
			}
			break;
		case 3:
			if(this.ajax.status == 200 || this.ajax.status == 304)
			{
				if(this.onInteractive)
				{
					this.onInteractive(this.ajax);
				}
			}
			else
			{
				if(this.onInteractiveError)
				{
					this.onInteractiveError(this.ajax);
				}
				else if(this.onError)
				{
					this.onError(this.ajax);
				}
				else if(this.onInteractive)
				{
					this.onInteractive(this.ajax);
				}
			}
			break;
		case 4:
			if(this.ajax.status == 200 || this.ajax.status == 304)
			{
				if(this.onComplete)
				{
					this.onComplete(this.ajax);
				}
			}
			else
			{
				if(this.onCompleteError)
				{
					this.onCompleteError(this.ajax);
				}
				else if(this.onError)
				{
					this.onError(this.ajax);
				}
				else if(this.onComplete)
				{
					this.onComplete(this.ajax);
				}
			}
			jso_ajax.prototype.count --;
			break;
	}
	if(jso_ajax.prototype.count <= 0)
	{
		jso_ajax.prototype.count = 0;
		var domBody = jso_gT('body')[0];
		domBody.className = domBody.className.replace(/ ?ajax_on/gi,'');
	}
}
jso_ajax.prototype.count = 0;
if(!window.jso_ie)
{
	var jso_ie = false;
}
// jsoPlaceholder
function jsoPlaceholder(domInput,defaultText)
{
	if(!domInput)
		return;
	if(!('placeholder' in domInput) || jso_ie)
	{
		this.domInput = domInput;
		this.changeInputType = (!jso_ie && this.domInput.type == 'password');
		if(defaultText)
		{
			this.defaultText = defaultText;
		}
		else
		{
			this.defaultText = this.domInput.getAttribute('placeholder');
		}
		if(this.defaultText)
		{
			var T = this;
			jso_aE(this.domInput,'focus',function(){T.focus.call(T)})
			jso_aE(this.domInput,'blur',function(){T.blur.call(T)})
			jso_aE(this.domInput.form,'submit',function(){T.focus.call(T);var TT = T;window.setTimeout(function(){TT.blur.call(TT)},100)})
			this.blur();
			this.domInput.oPlaceholder = this;
		}
	}
}
jsoPlaceholder.prototype.focus = function()
{
	this.domInput.className = this.domInput.className.replace(/ *default */gi,'');
	if(this.domInput.value == this.defaultText)
	{
		this.domInput.value = '';
		if(this.changeInputType && this.domInput.type == 'text')
		{
			this.domInput.type = 'password';
			if(window.opera)
			{
				this.domInput.focus();
			}
		}
	}
}
jsoPlaceholder.prototype.blur = function()
{
	if(this.domInput.value == '' || this.domInput.value == this.defaultText)
	{
		this.domInput.className = this.domInput.className.replace(/ *default */gi,'') + ' default';
		this.domInput.value = this.defaultText;
		if(this.changeInputType)
		{
			this.domInput.type = 'text';
		}
	}
}
// jsoRequired
function jsoRequired(domInput)
{
	this.domInput = domInput;
	this.domInput.required = '';
	this.domInput.removeAttribute('required');
	this.domForm = this.domInput.form;
	if(this.domInput.type == 'checkbox' || this.domInput.type == 'radio')
	{
		this.errorText = i18n.select_fields;
	}
	else
	{
		if(this.domInput.parentNode.nodeName.toLowerCase() == 'label')
		{
			var domLabel = this.domInput.parentNode;
		}
		else
		{
			var domLabel = jso_gAV('label',this.domInput.parentNode,'htmlFor',this.domInput.id)[0];
		}
		if(domLabel)
		{
			this.errorText = i18n.fill_in_field + ' ' + domLabel.firstChild.nodeValue.replace(/(^[ 	\n]*|[ 	\n]*$|\*+)/gi,'');
		}
		else
		{
			this.errorText = i18n.fill_in_fields;
		}
	}
	if(!this.domForm.jsoRequired)
	{
		this.domForm.jsoRequired = [];
		this.domForm.onsubmit = function()
		{
			var i=0,validateF;
			for(;i<this.jsoRequired.length;i++)
			{
				validateF = this.jsoRequired[i];
				if(!validateF())
				{
					return false;
				}
			}
			return true;
		}
	}
	var T = this;
	this.domForm.jsoRequired.push(function(){return T.validateF.call(T)});
}
jsoRequired.prototype.validateF = function()
{
	if(!this.domInput.offsetHeight || !this.domInput.offsetWidth)
	{
		return true;
	}
	if(this.domInput.type == 'checkbox')
	{
		if(!this.domInput.checked)
		{
			return this.errorF();
		}
	}
	else if(this.domInput.type == 'radio')
	{
		var i=0;domInputs = this.domForm[this.domInput.name];
		for(;i<domInputs.length;i++)
		{
			if(domInputs[i].checked)
			{
				return true;
			}
		}
		return this.errorF();
	}
	else
	{
		if(!this.domInput.value.match(/[^ 	]+/))
		{
			return this.errorF();
		}
		if(this.domInput.getAttribute('type') == 'search' && this.domInput.value.length < 4)
		{
			this.errorText = i18n.to_short;
			return this.errorF();
		}
		if(this.domInput.getAttribute('type') == 'email' && !this.domInput.value.match(/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/i))
		{
			this.errorText = i18n.invalid_email;
			return this.errorF();
		}
	}
	return true;
}
jsoRequired.prototype.errorF = function()
{
 	alert(this.errorText);
	this.domInput.focus();
	return false;
}
// getStyle
function getStyle(el,styleProp)
{
	if (el.currentStyle)
	{
		return el.currentStyle[styleProp];
	}
	else if (window.getComputedStyle)
	{
		return document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	}
}
function createCookie(name,value,days)
{
	if(days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return false;
}


