// Ver 4.0 | 31.01.2010 14:19

var CMSka = new Object();

/* Загрузка данных через Ajax */
CMSka.ContentLoader = function(options)
{
	if(options["pathToPHP"] == undefined || options["pathToPHP"] == "")
	{
	return false;
	}

this.DATA = new Object();
this.OPTIONS = options;
this.ERROR_CONNECTION = "";
this.XML_DATA = new Object();
this.ARRAY_OBJECT = new Array();
this.ARRAY_DEEP = new Array();
this.TYPE_NOW;
this.DEEP = 0;


this.OPTIONS["pathToPHP"] = this.OPTIONS["pathToPHP"] == undefined ? "" : this.OPTIONS["pathToPHP"];
this.OPTIONS["formatData"] = this.OPTIONS["formatData"] == undefined ? "TEXT" : this.OPTIONS["formatData"];
this.OPTIONS["params"] = this.OPTIONS["params"] == undefined ? "" : this.OPTIONS["params"];
this.OPTIONS["paramsNowAdd"] = this.OPTIONS["paramsNowAdd"] == undefined ? false : this.OPTIONS["paramsNowAdd"];
this.OPTIONS["url"] = this.OPTIONS["url"] == undefined ? "ini/inter.CoreXML.php" : this.OPTIONS["url"];
this.OPTIONS["method"] = this.OPTIONS["method"] == undefined ? "GET" : this.OPTIONS["method"];
this.OPTIONS["async"] = this.OPTIONS["async"] == undefined ? true : this.OPTIONS["async"];
this.OPTIONS["functionNext"] = this.OPTIONS["functionNext"] == undefined ? "" : this.OPTIONS["functionNext"];
this.OPTIONS["functionError"] = this.OPTIONS["functionError"] == undefined ? this.errorConnection : this.OPTIONS["functionError"];
var thisObj = this;
	
	this.loadDocument = function()
	{
		this.onReadyState = function()
		{
		var ready = this.REQUEST.readyState;
		
			if(ready == 4)
			{
			var httpStatus = this.REQUEST.status;
		
				if(httpStatus == 200 || httpStatus == 0)
				{		
					if(this.OPTIONS["formatData"] == "TEXT")
					{
					this.DATA.text = this.REQUEST.responseText;
					}
					else if(this.OPTIONS["formatData"] == "XML")
					{
					this.DATA.text = this.REQUEST.responseText;
					this.convertXMLDateToObject(this.REQUEST.responseXML);
					this.DATA.xml = this.XML_DATA;
					delete this.XML_DATA;
					}
				
					if(this.OPTIONS["functionNext"] != "")
					{
					this.OPTIONS["functionNext"].call(this.OPTIONS["functionNext"], this.DATA);
					}
				}
				else
				{
				this.ERROR_CONNECTION = "Неверный статус протокола!";
				this.FUNCTION_ERROR.call(this);
				}
			}
		}
		
		this.errorConnection = function()
		{
		alert("Произошла ошибка соединения!\nПричина: " + this.ERROR_CONNECTION);
		}
	
		if(this.OPTIONS["params"] == "")
		{
		var params = "pathToPHP=" + this.OPTIONS["pathToPHP"] + "&formatData=" + this.OPTIONS["formatData"];
		}
		else
		{
		var params = this.OPTIONS["params"] + "&pathToPHP=" + this.OPTIONS["pathToPHP"] + "&formatData=" + this.OPTIONS["formatData"];
		}
		
		if(this.OPTIONS["paramsNowAdd"] == true)
		{
		var paramsNow = location.search.substring(1, location.search.length);
		
			if(paramsNow != "")
			{
			params = paramsNow + "&" + params;
			}
		}
		
	d = new Date();
	t = d.getTime();
	params = params + "&" + t;
	
		try
		{
		this.REQUEST = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		var loader = this;
		
			this.REQUEST.onreadystatechange = function()
			{
			loader.onReadyState.call(loader);
			}
			
			if(this.OPTIONS["method"] == "GET")
			{
			var par = decodeURI(this.OPTIONS["url"] + "?" + params);
			this.REQUEST.open("GET", par, this.OPTIONS["async"]);
			this.REQUEST.send(null);
			}
			else if(this.OPTIONS["method"] == "POST")
			{
			this.REQUEST.open("POST", this.OPTIONS["url"], this.OPTIONS["async"]);
			this.REQUEST.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			this.REQUEST.send(params);
			}
		}
		catch(er)
		{
		this.ERROR_CONNECTION = er;
		
			if(this.OPTIONS["functionError"] != "")
			{
			this.OPTIONS["functionError"].call(this);
			}
		}
		
		
		
		
		this.convertXMLDateToObject = function(node)
		{
		var poz = 0;
		var pozPast = 0;
		var nodeNow = node.childNodes;
		var arrayWas = new Array();

			for(var i = 0; i < nodeNow.length; i++)
			{
			poz++;

				if(poz == 1)
				{
				this.DEEP++;
				}
		
				if(nodeNow.item(i).nodeType == 7)
				{
				poz--;
				this.DEEP--;
				continue;
				}		
	
			var val = nodeNow.item(i).nodeValue;
		
				if(val != null)
				{
				val = CMSka.util.cleanStr(val, "");
				
					if(val != "" && nodeNow.item(i).nodeType == 3 && nodeNow.item(i).nodeName == "#text")
					{
					var name = "#text";
					this.TYPE_NOW = "TEXT";
					this.ARRAY_OBJECT[this.DEEP] = name;
					this.ARRAY_DEEP[this.DEEP] = CMSka.util.cleanStr(nodeNow.item(i).nodeValue, "");
					this.addObjectAndValueToVar();
					}
					else if(val == "")
					{
						if(poz == 1)
						{
						this.DEEP--;
						}
					poz--;
					continue;
					}
					else
					{
					var name = nodeNow.item(i).nodeName;
					this.TYPE_NOW = "NODE";
					this.ARRAY_OBJECT[this.DEEP] = name;
					this.ARRAY_DEEP[this.DEEP] = poz - 1;
					this.addObjectAndValueToVar();
					pozPast = this.DEEP;
					this.convertXMLDateToObject(nodeNow.item(i));
					this.DEEP = pozPast;				
					}
				}
				else
				{
				var name = nodeNow.item(i).nodeName;
				this.TYPE_NOW = "NODE";
				this.ARRAY_OBJECT[this.DEEP] = name;
				this.ARRAY_DEEP[this.DEEP] = poz - 1;
				this.addObjectAndValueToVar();
				pozPast = this.DEEP;
				this.convertXMLDateToObject(nodeNow.item(i));
				this.DEEP = pozPast;
				}
				
				if(nodeNow.item(i).attributes != null)
				{
					for(var z = 0; z < nodeNow.item(i).attributes.length; z++)
					{
					this.TYPE_NOW = "ATTRIBUT";
					this.DEEP++;
					this.ARRAY_OBJECT[this.DEEP] = nodeNow.item(i).attributes.item(z).nodeName;
					this.ARRAY_DEEP[this.DEEP] = CMSka.util.cleanStr(nodeNow.item(i).attributes.item(z).nodeValue, "");
					this.addObjectAndValueToVar();
					this.DEEP--;
					}
				}
			}
		}
		
		
		
		this.addObjectAndValueToVar = function()
		{
		var str = "this.XML_DATA";
		zag = 0;
		
			for(i = 1; i < (this.DEEP + 1); i++)
			{	
				if(this.TYPE_NOW == "TEXT")
				{
					if(i == this.DEEP)
					{
					eval("var iz = " + str + "['" + this.ARRAY_OBJECT[i] + "']");
		
						if(typeof iz == "undefined")
						{
						str += "['" + this.ARRAY_OBJECT[i] + "']" + " = '" + this.ARRAY_DEEP[i] + "';";
						}
						else
						{
						str += "['" + this.ARRAY_OBJECT[i] + "']" + " += '" + this.ARRAY_DEEP[i] + "';";
						}
					}
					else
					{
					str += "['" + this.ARRAY_OBJECT[i] + "']" + "[" + this.ARRAY_DEEP[i] + "]";
					}
				}
				else if(this.TYPE_NOW == "ATTRIBUT")
				{
					if(i == this.DEEP)
					{
					str += "['" + this.ARRAY_OBJECT[i] + "'] = '" + this.ARRAY_DEEP[i] + "';";
					}
					else
					{
					str += "['" + this.ARRAY_OBJECT[i] + "']" + "[" + this.ARRAY_DEEP[i] + "]";
					}
				}
				else if(this.TYPE_NOW == "NODE")
				{
					if(i == this.DEEP)
					{
					eval("var how = " + str + "['" + this.ARRAY_OBJECT[i] + "']");
					
						if(typeof how == "undefined")
						{
						this.ARRAY_DEEP[i] = 0;
						strArr = str + "['" + this.ARRAY_OBJECT[i] + "'] = new Array();\n";
						strObj = str + "['" + this.ARRAY_OBJECT[i] + "']" + "[" + this.ARRAY_DEEP[i] + "] = new Object();";
						}
						else
						{
						eval("var c = " + str + "['" + this.ARRAY_OBJECT[i] + "'].length");
						this.ARRAY_DEEP[i] = c;
						strArr = "";
						strObj = str + "['" + this.ARRAY_OBJECT[i] + "']" + "[" + this.ARRAY_DEEP[i] + "] = new Object();";
						}			
									
					str = strArr + strObj;
					}
					else
					{
					str += "['" + this.ARRAY_OBJECT[i] + "']" + "[" + this.ARRAY_DEEP[i] + "]";
					}
				}
			}

		eval(str);
		}
	}
	this.loadDocument();
}




/* Загрузка данных через фреймы */
CMSka.ContentLoaderByte = function(options)
{
	if(options["pathToPHP"] == undefined || options["objForm"] == undefined || options["pathToPHP"] == "" || options["objForm"] == "")
	{
	return false;
	}
	
var len = CMSka.ContentLoaderByteObject.history.length;
CMSka.ContentLoaderByteObject.history[len] = new Object();
CMSka.ContentLoaderByteObject.history[len] = options;
CMSka.ContentLoaderByteObject.history[len]["pathToPHP"] = options["pathToPHP"] == undefined ? "" : options["pathToPHP"];
CMSka.ContentLoaderByteObject.history[len]["params"] = options["params"] == undefined ? "" : options["params"];
CMSka.ContentLoaderByteObject.history[len]["paramsNowAdd"] = options["paramsNowAdd"] == undefined ? false : options["paramsNowAdd"];
CMSka.ContentLoaderByteObject.history[len]["url"] = options["url"] == undefined ? "ini/inter.CoreXML.php" : options["url"];
CMSka.ContentLoaderByteObject.history[len]["functionNext"] = options["functionNext"] == undefined ? "" : options["functionNext"];
CMSka.ContentLoaderByteObject.history[len]["objForm"] = options["objForm"] == undefined ? "" : options["objForm"];
CMSka.ContentLoaderByteObject.history[len]["timeWait"] = options["timeWait"] == undefined ? 300 : options["timeWait"] * 10;
CMSka.ContentLoaderByteObject.history[len]["oldValue"] = new Array();
CMSka.ContentLoaderByteObject.history[len]["timeOut"] = 100;
CMSka.ContentLoaderByteObject.history[len]["counter"] = 0;
CMSka.ContentLoaderByteObject.history[len]["DATA"] = new Object();

CMSka.ContentLoaderByteObject.chooseLoader();
}


CMSka.ContentLoaderByteObject = new Object();
CMSka.ContentLoaderByteObject.history = new Array();
CMSka.ContentLoaderByteObject.loading = false;


CMSka.ContentLoaderByteObject.chooseLoader = function()
{
var len = CMSka.ContentLoaderByteObject.history.length;

	if(len != 0 && CMSka.ContentLoaderByteObject.loading == false)
	{
	CMSka.ContentLoaderByteObject.loading = true;
	CMSka.ContentLoaderByteObject.generateIframe();
	CMSka.ContentLoaderByteObject.generateInput();
	
	setTimeout("CMSka.ContentLoaderByteObject.sendForm()", 1000);
	}
}
	

CMSka.ContentLoaderByteObject.generateIframe = function()
{
var history = CMSka.ContentLoaderByteObject.history;

var date = new Date();
var time = date.getTime();
history[0]["iframeName"] = "iframe_" + time;


	if(navigator.appName == "Microsoft Internet Explorer")
	{
	var iframe = "<iframe name='" + history[0]["iframeName"] + "' id='" + history[0]["iframeName"] + "'style='visibility: hidden; display: none; style='width: 200px; height: 200px;'></iframe>"; //'>
	document.body.insertAdjacentHTML("AfterBegin", iframe);
	}
	else
	{	
	var iframe = document.createElement("iframe");
	iframe.setAttribute("name", history[0]["iframeName"]);
	iframe.setAttribute("id", history[0]["iframeName"]);
	iframe.style.visibility = "hidden";
	iframe.style.display = "none";
	iframe.style.width = "0px";
	iframe.style.height = "0px";
	document.body.appendChild(iframe);
	}
}

	
	
CMSka.ContentLoaderByteObject.generateInput = function()
{
var history = CMSka.ContentLoaderByteObject.history;

var host = location.host;
var pathName = location.pathname;
var protocol = location.protocol;
var loca = protocol + "//" + host + pathName;

var inp = document.createElement("input");
inp.setAttribute("type", "hidden");
inp.setAttribute("name", "uri");
inp.setAttribute("value", loca);
history[0]["pathToUriObj"] = history[0]["objForm"].appendChild(inp);

var inp = document.createElement("input");
inp.setAttribute("type", "hidden");
inp.setAttribute("name", "pathToPHP");
inp.setAttribute("value", history[0]["pathToPHP"]);
history[0]["pathToPhpObj"] = history[0]["objForm"].appendChild(inp);

var pathNow = location.search.substring(1, location.search.length);

	if(pathNow != "" && history[0]["paramsNowAdd"] == true)
	{
		if(history[0]["params"] != "")
		{
		var href = history[0]["url"] + "?" + pathNow + "&" + history[0]["params"] + "&formatData=TEXT";
		}
		else
		{
		var href = history[0]["url"] + "?" + pathNow + "&formatData=TEXT";
		}
	}
	else
	{
		if(history[0]["params"] == "")
		{
		var href = history[0]["url"] + "?" + "formatData=TEXT";
		}
		else
		{
		var href = history[0]["url"] + "?" + history[0]["params"] + "&formatData=TEXT";
		}
	}

history[0]["objForm"].setAttribute("action", href);

history[0]["objForm"].setAttribute("target", history[0]["iframeName"]);
history[0]["objForm"].setAttribute("method", "post");
}
	
	
	
CMSka.ContentLoaderByteObject.sendForm = function()
{
var history = CMSka.ContentLoaderByteObject.history;

history[0]["objForm"].submit();
history[0]["iframeObject"] = document.getElementById(history[0]["iframeName"]);
setTimeout("CMSka.ContentLoaderByteObject.getContent()", history[0]["timeOut"]);
}
	
	
	
CMSka.ContentLoaderByteObject.getContent = function()
{
var history = CMSka.ContentLoaderByteObject.history;

	if(typeof history[0]["iframeObject"].contentWindow != "undefined")
	{
		try
		{
		history[0]["DATA"].text = history[0]["iframeObject"].contentWindow.document.body.innerHTML;
		}
		catch(er)
		{
		history[0]["counter"] = history[0]["timeWait"];
		}
	}
	else
	{
	history[0]["DATA"].text = history[0]["iframeObject"].contentDocument.body.innerHTML
	}
	
	if(history[0]["DATA"].text == "" && history[0]["counter"] != history[0]["timeWait"])
	{
	history[0]["counter"] = history[0]["counter"] + 1;
	setTimeout("CMSka.ContentLoaderByteObject.getContent()", history[0]["timeOut"]);
	}
	else
	{
	history[0]["iframeObject"].parentNode.removeChild(history[0]["iframeObject"]);
	history[0]["pathToPhpObj"].parentNode.removeChild(history[0]["pathToPhpObj"]);
	history[0]["pathToUriObj"].parentNode.removeChild(history[0]["pathToUriObj"]);
	history[0]["DATA"].text = CMSka.util.cleanStr(history[0]["DATA"].text, "");
	
	history[0]["DATA"].options = history[0];
	var functionNext = history[0]["functionNext"];
	this.DATA = history[0]["DATA"];
	history.shift();
	CMSka.ContentLoaderByteObject.loading = false;
	functionNext.call(functionNext, this.DATA);
	CMSka.ContentLoaderByteObject.chooseLoader();
	}
}






/* Проверка формы */
CMSka.CheckForm = function(options)
{
this.OPTIONS = options;
this.OPTIONS["nameForm"].reset();

	this.check = function(obj)
	{
	var obj = obj == undefined ? false : obj;
	var zag = 0;
	
		for(var i = 0; i < this.OPTIONS["rules"].length; i++)
		{		
			if(this.OPTIONS["rules"][i]["id"] != obj["id"] && obj != false)
			{
			continue;
			}
			
		this.OPTIONS["rules"][i]["isRedaktor"] = this.OPTIONS["rules"][i]["isRedaktor"] == undefined ? false : this.OPTIONS["rules"][i]["isRedaktor"];
			
		
			if(this.OPTIONS["rules"][i]["isRedaktor"] == false)
			{
			var objForm = document.getElementById(this.OPTIONS["rules"][i]["id"]);
			
				if(objForm == null) continue;
			
				if(objForm.type == "checkbox")
				{
					if(objForm.checked == true) var value = objForm.value;
					else var value = "";
				}
				else
				{
				var value = objForm.value;
				}
			
			value = this.replaceAloneKav(value);
			}
			else
			{
			var oEditor = FCKeditorAPI.GetInstance(this.OPTIONS["rules"][i]["id"]);
			var value = oEditor.GetHTML();
			}
		
		
			if(this.OPTIONS["rules"][i]["type"] == "namePage")
			{
			eval("var how = CMSka.util.isNamePage" + "('" + value + "', " + this.OPTIONS["rules"][i]["min"] + ", " + this.OPTIONS["rules"][i]["max"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "textN")
			{
			value = CMSka.util.getTextN(value);
			eval("var how = CMSka.util.isNotEmpty" + "('" + value + "', " + this.OPTIONS["rules"][i]["min"] + ", " + this.OPTIONS["rules"][i]["max"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "textBr")
			{
			value = CMSka.util.getTextBr(value);
			eval("var how = CMSka.util.isNotEmpty" + "('" + value + "', " + this.OPTIONS["rules"][i]["min"] + ", " + this.OPTIONS["rules"][i]["max"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "htmlN")
			{
			value = CMSka.util.getHtmlN(value);
			eval("var how = CMSka.util.isNotEmpty" + "('" + value + "', " + this.OPTIONS["rules"][i]["min"] + ", " + this.OPTIONS["rules"][i]["max"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "htmlBr")
			{
			value = CMSka.util.getHtmlBr(value);
			eval("var how = CMSka.util.isNotEmpty" + "('" + value + "', " + this.OPTIONS["rules"][i]["min"] + ", " + this.OPTIONS["rules"][i]["max"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "email")
			{
			eval("var how = CMSka.util.isEmail" + "('" + value + "', " + this.OPTIONS["rules"][i]["notNull"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "date")
			{
			eval("var how = CMSka.util.isDate" + "('" + value + "', " + this.OPTIONS["rules"][i]["notNull"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "number")
			{
			eval("var how = CMSka.util.isNumber" + "('" + value + "', " + this.OPTIONS["rules"][i]["notNull"] + ", " + this.OPTIONS["rules"][i]["unsigned"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "doubleNumber")
			{
			eval("var how = CMSka.util.isDoubleNumber" + "('" + value + "', " + this.OPTIONS["rules"][i]["notNull"] + ", " + this.OPTIONS["rules"][i]["unsigned"] + ")");
			}
			else if(this.OPTIONS["rules"][i]["type"] == "match")
			{
			var value2 = document.getElementById(this.OPTIONS["rules"][i]["idMatcher"]).value;
				
				if(obj == false)
				{
				eval("var how = CMSka.util.isMatch" + "('" + value + "', '" + value2 + "')");
				}
				else
				{
					if(value != "")
					{
					eval("var how = CMSka.util.isMatch" + "('" + value + "', '" + value2 + "')");
					}
					else
					{
					var how = true;
					}
				}
			}
			else
			{
			var params = this.OPTIONS["rules"][i]["params"];
			
				if(params != undefined)
				{
				var pol = params.length;
				var stringParams = "";
				
					for(z = 0; z < pol; z++)
					{
						if(stringParams == "")
						{
						stringParams += "'" + params[z] + "'";
						}
						else
						{
						stringParams += ", '" + params[z] + "'";
						}
					}
				
				eval("var how = CMSka.util." + this.OPTIONS["rules"][i]["type"] + "('" + value + "', " + stringParams + ")");
				}
				else
				{
				eval("var how = CMSka.util." + this.OPTIONS["rules"][i]["type"] + "('" + value + "')");
				}
			}
		
			if(this.OPTIONS["rules"][i]["errNameId"] == undefined)
			{
			var errNameId = "message_" + this.OPTIONS["nameForm"].name + "_" + this.OPTIONS["rules"][i]["id"];
			}
			else
			{
			var errNameId = this.OPTIONS["rules"][i]["errNameId"];
			}
		
			
			if(this.OPTIONS["rules"][i]["isRedaktor"] == false)
			{
			var objFormIn = document.getElementById(this.OPTIONS["rules"][i]["id"]);
			}
			else
			{
			var objFormIn = FCKeditorAPI.GetInstance(this.OPTIONS["rules"][i]["id"]);
			}
			
		
			
			if(!how)
			{
				if(zag == 0)
				{	
					if(obj == false)
					{
						if(this.OPTIONS["rules"][i]["isRedaktor"] == false)
						{
							if(this.OPTIONS["rules"][i]["idFocus"] != undefined)
							{
							objFormIn.focus();
							}
							else
							{
							objFormIn.focus();
							}
						}
						else
						{
							if(this.OPTIONS["rules"][i]["idFocus"] != undefined)
							{
							objFormIn.Focus();
							}
							else
							{
							objFormIn.Focus();
							}
						}
					}
				
				zag = 1;
				}
				
				
				if(this.OPTIONS["rules"][i]["classError"] != undefined)
				{
				var classError = this.OPTIONS["rules"][i]["classError"];
				}
				else
				{
				var classError = this.OPTIONS["classError"];
				}
			
				if(this.OPTIONS["rules"][i]["noMarkForm"] == undefined || this.OPTIONS["rules"][i]["noMarkForm"] == false)
				{
				objFormIn.className = classError;
				}
				
			document.getElementById(errNameId).style.display = "";
			document.getElementById(errNameId).innerHTML = this.OPTIONS["rules"][i]["alert"];
			}
			else
			{
				
				if(this.OPTIONS["rules"][i]["classOk"] != undefined)
				{
				var classOk = this.OPTIONS["rules"][i]["classOk"];
				}
				else
				{
				var classOk = this.OPTIONS["classOk"];
				}
				
				if(this.OPTIONS["rules"][i]["noMarkForm"] == undefined || this.OPTIONS["rules"][i]["noMarkForm"] == false)
				{
				objFormIn.className = classOk;
				}
			
			document.getElementById(errNameId).style.display = "none";
			document.getElementById(errNameId).innerHTML = "";
			}
		}
		
		if(zag == 1)
		{
		return false;
		}
		else
		{
		return true;
		}
		
	}
	
	
	this.replaceAloneKav = function(value)
	{
	re = new RegExp("'", "g");
	value = value.replace(re, "`");
	return value;
	}
	
	this.resetForm = function()
	{
	this.OPTIONS["nameForm"].reset();
	
		for(var i = 0; i < this.OPTIONS["rules"].length; i++)
		{
			if(this.OPTIONS["rules"][i]["isRedaktor"] == true)
			{
			var objFormIn = FCKeditorAPI.GetInstance(this.OPTIONS["rules"][i]["id"]);
			objFormIn.SetHTML("");
			}
		}
	}
}







/* Запрещаем отправлять форму при нажатии на кнопку Enter сделанную посредством ссылки */
CMSka.submitByLinks = new Object();
CMSka.submitByLinks.LINKS = new Object();

CMSka.submitByLinks.getBlock = function(id)
{
var objLin = document.getElementById(id);

	if(objLin != undefined)
	{
	objLin.disabled = true;
	
	objLin.up = objLin.onmouseup;
	objLin.click = objLin.onclick;
	
	objLin.onclick = CMSka.submitByLinks.deadent;
	objLin.onmouseup = CMSka.submitByLinks.deadent;
	}

CMSka.submitByLinks.LINKS[id] = objLin;
}

CMSka.submitByLinks.getUnBlock = function(id)
{
	if(CMSka.submitByLinks.LINKS[id] != undefined)
	{
	var objLin = CMSka.submitByLinks.LINKS[id];
	
	objLin.disabled = false;
	
	objLin.onclick = objLin.click;
	objLin.onmouseup = objLin.up;
	}
}

CMSka.submitByLinks.deadent = function()
{
return false;
}





/* Запрещаем отправлять форму при нажатии на кнопку Enter */
CMSka.submitByEnter = new Object();
CMSka.submitByEnter.block = false;

CMSka.submitByEnter.initialization = function()
{
var forms = document.getElementsByTagName("FORM");

	for(i = 0; i < forms.length; i++)
	{
	forms[i].onkeypress = CMSka.submitByEnter.submit;
	}
}


CMSka.submitByEnter.getBlock = function(id)
{
CMSka.submitByEnter.block = true;
}


CMSka.submitByEnter.getUnBlock = function()
{
CMSka.submitByEnter.block = false;
}


CMSka.submitByEnter.submit = function(event)
{
var even = CMSka.util.getEvent(event);
var target =  CMSka.util.getTargetFromEvent(even);

	if(target.tagName == "INPUT" || target.tagName == "SELECT")
	{
		if(even.keyCode == 13 && CMSka.submitByEnter.block == true)
		{
		return false;
		}
	}
}



/* Бар загрузки */
CMSka.loadBar = new Object();
CMSka.loadBar.ONLOADED = false;
CMSka.loadBar.STATUS = false;


CMSka.loadBar.initialization = function(id)
{
this.OBJ = document.getElementById(id);
this.ONLOADED = true;
this.CIRCLE;
}


CMSka.loadBar.start = function()
{
	if(this.ONLOADED == false || this.STATUS == true) return;
	
this.STATUS = true;
this.rightOnWindow();
this.circulPoints(0);
this.OBJ.style.display = "";
}


CMSka.loadBar.stop = function()
{
	if(this.ONLOADED == false || this.STATUS == false) return;

this.STATUS = false;
window.clearTimeout(this.circl);
this.OBJ.style.display = "none";
}


CMSka.loadBar.circulPoints = function(counts)
{
	switch(counts)
	{
	case 0: this.OBJ.innerHTML = "Загрузка..."; this.circl = window.setTimeout("CMSka.loadBar.circulPoints(1)", 200); break;
	case 1: this.OBJ.innerHTML = "Загрузка"; this.circl = window.setTimeout("CMSka.loadBar.circulPoints(2)", 200); break;
	case 2: this.OBJ.innerHTML = "Загрузка."; this.circl = window.setTimeout("CMSka.loadBar.circulPoints(3)", 200); break;
	case 3: this.OBJ.innerHTML = "Загрузка.."; this.circl = window.setTimeout("CMSka.loadBar.circulPoints(0)", 200); break;
	}
}


CMSka.loadBar.rightOnWindow = function()
{
var scrollY = 0;

	if(document.body && typeof document.body.scrollTop != "undefined")
	{
	scrollY += document.body.scrollTop;
	}
	else if(typeof window.pageXOffset != "undefined")
	{
	scrollY += window.pageYOffset;
	}
	
var y = scrollY;
this.OBJ.style.top = y;
}


CMSka.loadBar.handleScroll = function()
{
	if(CMSka.loadBar.ONLOADED)
	{
	CMSka.loadBar.rightOnWindow();
	}
}


CMSka.loadBar.handleResize = function()
{
	if(CMSka.loadBar.ONLOADED)
	{
	CMSka.loadBar.rightOnWindow();
	}
}

window.onresize = CMSka.loadBar.handleResize;
window.onscroll = CMSka.loadBar.handleScroll;






/* Класс вывода плашки сообщения */
CMSka.PlashkaMessage = function(options)
{
this.OPTIONS = options;
this.OPTIONS["setScroll"] = this.OPTIONS["setScroll"] == undefined ? true : this.OPTIONS["setScroll"];

	this.messageOk = function(mes)
	{
	var okObjMessage = document.getElementById(this.OPTIONS["okObjMessage"]);
	okObjMessage.style.display = "";
	
	var okObjContent = document.getElementById(this.OPTIONS["okObjContent"]);
	okObjContent.innerHTML = mes;
	
	this.hideError();
		
		if(this.OPTIONS["setScroll"] == true)
		{
		CMSka.util.setScrollToObject(okObjMessage, 50);
		}
	}
	
	
	
	this.messageError = function(mes)
	{
	var errorObjMessage = document.getElementById(this.OPTIONS["errorObjMessage"]);
	errorObjMessage.style.display = "";
	
	var errorObjContent = document.getElementById(this.OPTIONS["errorObjContent"]);
	errorObjContent.innerHTML = mes;
	
	this.hideOk();
		
		if(this.OPTIONS["setScroll"] == true)
		{
		CMSka.util.setScrollToObject(errorObjMessage, 50);
		}
	}
	
	
	
	this.hideOk = function()
	{
	var okObjMessage = document.getElementById(this.OPTIONS["okObjMessage"]);
	okObjMessage.style.display = "none";
	
	var okObjContent = document.getElementById(this.OPTIONS["okObjContent"]);
	okObjContent.innerHTML = "";
	}
	
	
	
	this.hideError = function()
	{
	var errorObjMessage = document.getElementById(this.OPTIONS["errorObjMessage"]);
	errorObjMessage.style.display = "none";
	
	var errorObjContent = document.getElementById(this.OPTIONS["errorObjContent"]);
	errorObjContent.innerHTML = "";
	}
	
	this.hide = function()
	{
	this.hideOk();
	this.hideError();
	}
}





/* Таблица с информацией и динамическими возможностями */
CMSka.TableInfo = function(options)
{
this.OPTIONS = options;
this.OBJ_CONTENT = document.getElementById(this.OPTIONS["idContent"]);
this.PUNKT = "";
this.BY_SORT = "";
this.DESC = "";
this.BASE = new Array();

var thisObj = this;

	this.write = function(punkt, bySort, desc)
	{
	this.PUNKT = (typeof punkt == "undefined" || punkt == "") ? this.PUNKT : punkt;
	this.BY_SORT = (typeof bySort == "undefined" || bySort == "") ? this.BY_SORT : bySort;
	this.DESC = (typeof desc == "undefined" || desc == "") ? this.DESC : desc;
	
		if(this.BASE[this.PUNKT + "_" + this.BY_SORT + "_" + this.DESC])
		{
		this.inputInContent(this.BASE[this.PUNKT + "_" + this.BY_SORT + "_" + this.DESC]);
		}
		else
		{
		var par = "punkt=" + this.PUNKT + "&bySort=" + this.BY_SORT + "&desc=" + this.DESC;
		CMSka.submitByEnter.getBlock();
		CMSka.loadBar.start();
		
		var options = new Object();
		options["pathToPHP"] = this.OPTIONS["phpTableInfo"];
		options["formatData"] = "TEXT";
		options["functionNext"] = this.afterWrite;
		options["paramsNowAdd"] = true;
		options["params"] = par;
		
		new CMSka.ContentLoader(options);
		}
		
	return false;
	}
	
	this.afterWrite = function(data)
	{
	CMSka.submitByEnter.getUnBlock();
	CMSka.loadBar.stop();
	
	thisObj.BASE[thisObj.PUNKT + "_" + thisObj.BY_SORT + "_" + thisObj.DESC] = data.text;
	thisObj.inputInContent(data.text);
	}
	
	this.inputInContent = function(content)
	{
	this.OBJ_CONTENT.innerHTML = content;
	}
	
	this.deleteByCheckBox = function()
	{
	var objForm = document[this.OPTIONS["nameForm"]];
	var par = CMSka.util.getPathByForm(objForm);
	
	var options = new Object();
	options["pathToPHP"] = this.OPTIONS["phpDeleteByCheckBox"];
	options["formatData"] = "TEXT";
	options["functionNext"] = this.afterDeleteByCheckBox;
	options["params"] = par;
	options["paramsNowAdd"] = true;

	CMSka.loadBar.start();
	new CMSka.ContentLoader(options);
	
	return false;
	}
	
	this.afterDeleteByCheckBox = function(data)
	{
	CMSka.loadBar.stop();
	
		if(data.text == "ok")
		{
		thisObj.deleteBase();
		thisObj.write();
		}
	}
	
	this.deleteBase = function()
	{
	this.BASE = new Array();
	}
	
	this.markTr = function(obj)
	{
	obj.style.cursor = "pointer";
	obj.style.backgroundColor = this.OPTIONS["markTrColor"];
	}
	
	this.unMarkTr = function(obj)
	{
	obj.style.backgroundColor = "";
	}
	
	this.goTo = function(pathToEdit)
	{
	var elems = document.getElementsByTagName("BASE");
	var base = elems[0].href;
	location.href = base + pathToEdit;
	}
}



/* Изображение для просмотра с возможностью удаления */
CMSka.ValuesOfImage = function(options)
{
this.OPTIONS = options;
var thisObj = this;

	this.write = function()
	{
	CMSka.submitByEnter.getBlock();
	CMSka.loadBar.start();
	
	var options = new Object();
	options["pathToPHP"] = this.OPTIONS["phpValuesOfImage"];
	options["formatData"] = "TEXT";
	options["functionNext"] = this.afterWrite;
	options["paramsNowAdd"] = true;
	
	new CMSka.ContentLoader(options);
	}

	
	this.afterWrite = function(data)
	{
	CMSka.submitByEnter.getUnBlock();
	CMSka.loadBar.stop();
	
		if(data.text != "")
		{
		document.getElementById(thisObj.OPTIONS["idContent"]).innerHTML = data.text;
		}
	}
	
	
	this.deleteImage = function(nameTable, nameCellContent, nameCellKey, valueCellKey)
	{
	var par = "nameTable=" + nameTable + "&nameCellContent=" + nameCellContent + "&nameCellKey=" + nameCellKey + "&valueCellKey=" + valueCellKey;
	CMSka.submitByEnter.getBlock();
	CMSka.loadBar.start();
	
	var options = new Object();
	options["pathToPHP"] = this.OPTIONS["phpDeleteImage"];
	options["formatData"] = "TEXT";
	options["functionNext"] = this.afterDeleteImage;
	options["params"] = par;
	new CMSka.ContentLoader(options);
	
	return false;
	}
	
	
	
	
	this.afterDeleteImage = function(data)
	{
	CMSka.submitByEnter.getUnBlock();
	CMSka.loadBar.stop();
	
		if(data.text == "true")
		{
		document.getElementById(thisObj.OPTIONS["idContent"]).innerHTML = "";
		}
	}
}


/* Картиники в виде галереи для просмотра */
CMSka.TableImage = function(options)
{
this.OPTIONS = options;
var thisObj = this;

	this.write = function()
	{
	CMSka.submitByEnter.getBlock();
	CMSka.loadBar.start();
	
	var options = new Object();
	options["pathToPHP"] = this.OPTIONS["phpValuesOfImage"];
	options["formatData"] = "TEXT";
	options["functionNext"] = this.afterWrite;
	options["paramsNowAdd"] = true;
	new CMSka.ContentLoader(options);
	}

	
	this.afterWrite = function(data)
	{
	CMSka.submitByEnter.getUnBlock();
	CMSka.loadBar.stop();
	
		if(data.text != "")
		{
		var idContent = document.getElementById(thisObj.OPTIONS["idContent"]);
		idContent.innerHTML = data.text;
		}
	}
	
	
	this.deleteImage = function(nameTable, nameCellContent, nameCellKey, valueCellKey)
	{
	var par = "nameTable=" + nameTable + "&nameCellContent=" + nameCellContent + "&nameCellKey=" + nameCellKey + "&valueCellKey=" + valueCellKey;
	CMSka.submitByEnter.getBlock();
	CMSka.loadBar.start();
	
	var options = new Object();
	options["pathToPHP"] = this.OPTIONS["phpDeleteImage"];
	options["formatData"] = "TEXT";
	options["functionNext"] = this.afterDeleteImage;
	options["params"] = par;
	new CMSka.ContentLoader(options);
	
	return false;
	}
	
	this.afterDeleteImage = function(data)
	{
	CMSka.submitByEnter.getUnBlock();
	CMSka.loadBar.stop();
		
		if(data.text == "true")
		{
		thisObj.write();
		}
	}
}



/* Редактор */
CMSka.Redaktor = function(options)
{
this.OPTIONS = options;
this.OPTIONS["ToolbarSet"] = this.OPTIONS["ToolbarSet"] == undefined ? "page" : this.OPTIONS["ToolbarSet"];
this.OPTIONS["Height"] = this.OPTIONS["Height"] == undefined ? 450 : this.OPTIONS["Height"];
this.OPTIONS["BodyClass"] = this.OPTIONS["BodyClass"] == undefined ? "CONTENT" : this.OPTIONS["BodyClass"];
this.OPTIONS["EditorAreaCSS"] = this.OPTIONS["EditorAreaCSS"] == undefined ? "css/main.css" : this.OPTIONS["EditorAreaCSS"];
this.OPTIONS["ToolbarComboPreviewCSS"] = this.OPTIONS["ToolbarComboPreviewCSS"] == undefined ? "../../" + this.OPTIONS["EditorAreaCSS"] : this.OPTIONS["ToolbarComboPreviewCSS"];
this.OPTIONS["EditorAreaStyles"] = this.OPTIONS["EditorAreaStyles"] == undefined ? undefined : this.OPTIONS["EditorAreaStyles"];

	this.write = function(options)
	{
	var oFCKeditor = new FCKeditor(this.OPTIONS["idNameTextarea"]);
	
	oFCKeditor.BasePath = "fckeditor/";
	
	var elems = document.getElementsByTagName("BASE");
	var base = elems[0].href;
	var d = new Date();
	oFCKeditor.Config['CustomConfigurationsPath'] = base + oFCKeditor.BasePath + 'myConfig.js?' + d.getTime();
	oFCKeditor.ToolbarSet = this.OPTIONS["ToolbarSet"];
	
	oFCKeditor.Config['BaseHref'] = base;
	oFCKeditor.Config['TemplatesXmlPath'] = base + "fckeditor/fckeditorTemplates.xml";
	oFCKeditor.Config['BodyClass'] = this.OPTIONS["BodyClass"];
	oFCKeditor.Config['EditorAreaCSS'] = this.OPTIONS["EditorAreaCSS"];
	oFCKeditor.Config['ToolbarComboPreviewCSS'] = this.OPTIONS["ToolbarComboPreviewCSS"];
	
		if(this.OPTIONS["EditorAreaStyles"] != undefined)
		{
		oFCKeditor.Config['EditorAreaStyles'] = this.OPTIONS["EditorAreaStyles"];
		}
	
	oFCKeditor.Height = this.OPTIONS["Height"];
	oFCKeditor.ReplaceTextarea();
	
	return oFCKeditor;
	}
}


/* Система просмотра изображений */
CMSka.ShowImage = function(options)
{
this.OPTIONS = options;
var thisObj = this;

this.OPTIONS["objImage"] = document.getElementById(this.OPTIONS["idNameImage"]);
this.OPTIONS["scrollbars"] = this.OPTIONS["scrollbars"] == undefined ? 0 : this.OPTIONS["scrollbars"];

	this.OPTIONS["objImage"].onmouseover = function()
	{
	thisObj.OPTIONS["objImage"].style.cursor = "pointer";
	thisObj.OPTIONS["objImage"].style.borderColor = thisObj.OPTIONS["borderColorOver"];
	}
	
	this.OPTIONS["objImage"].onmouseout = function()
	{
	thisObj.OPTIONS["objImage"].style.cursor = "auto";
	thisObj.OPTIONS["objImage"].style.borderColor = thisObj.OPTIONS["borderColorOut"];
	}
	
	this.OPTIONS["objImage"].onclick = function()
	{
	
		try
		{
		thisObj.OPTIONS["newWinShowImage"].close();
		}
		catch(er) {}
	
	var elems = document.getElementsByTagName("BASE");
	var base = elems[0].href;
	
	var infaHTML = "<base href='" + base + "'><BODY><TABLE border='0' width='100%' height='100%'><TR><TD align='center'><IMG src='" + thisObj.OPTIONS["pathToBigImage"] + "'></TD></TR></TABLE></BODY>";
	var width  = thisObj.OPTIONS["width"];
	var height = thisObj.OPTIONS["height"];
	
	var left = parseInt((screen.availWidth / 2) - (width / 2));
	var top = parseInt((screen.availHeight / 2) - (height / 2));
	
	var winFutr = "width=" + width + ", height=" + height + ", left=" + left + ", top=" + top + ", screenX=" + left + ", screenY=" + top + ", scrollbars=" + thisObj.OPTIONS["scrollbars"];
	
	var d = new Date();
	var t = d.getTime();
	
	thisObj.OPTIONS["newWinShowImage"] = window.open("", t, winFutr);
	thisObj.OPTIONS["newWinShowImage"].document.write(infaHTML);
	thisObj.OPTIONS["newWinShowImage"].focus();
	} 
}



/* Система открытия дополниетльного окна */
CMSka.Window = function(nameWindow, path, width, height, scrollbars)
{
var scrollbars = scrollbars == undefined ? "yes" : scrollbars;

var width = width == undefined ? 430 : width;
var height = height == undefined ? 590 : height;

var screenWidth = screen.width;
var screenHeight = screen.height;

var left = (screenWidth / 2) - (width / 2);
var top = (screenHeight / 2) - (height / 2);

var elems = document.getElementsByTagName("BASE");
var path = elems[0].href + path;

var objWin = window.open(path, nameWindow, "scrollbars=" + scrollbars + ",width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
objWin.focus();
	
	this.closes = function(objWin)
	{
	objWin.close();
	}
	
return objWin;
}




/* Утилиты */
CMSka.util = new Object();
CMSka.util.getEvent = function(even)
{
var even = even;

	if(typeof window.event != "undefined")
	{
	even = window.event;
	}

return even;
}

CMSka.util.getTargetFromEvent = function(even)
{
var target;

	if(typeof even.target == "undefined")
	{
	target = even.srcElement;
	}
	else
	{
	target = even.target;
	}

return target;
}


CMSka.util.cleanStr = function(value, replaceStr)
{
var searcher = new Array();
searcher[0] = "\r\n";
searcher[1] = "\n\r";
searcher[2] = "\n";
searcher[3] = "\r";
searcher[4] = "\t";

	for(var i = 0; i < searcher.length; i++)
	{
	re = new RegExp(searcher[i], "g");
	value = value.replace(re, replaceStr);
	}
	
value = CMSka.util.trim(value);

return value;
}

CMSka.util.cleanStrForCheck = function(value, replaceStr)
{
value = CMSka.util.cleanStr(value, replaceStr);

var searcher = new Array();
searcher[0] = "'";

	for(var i = 0; i < searcher.length; i++)
	{
	re = new RegExp(searcher[i], "g");
	value = value.replace(re, replaceStr);
	}

return value;
}

CMSka.util.addBR = function(value)
{
value = value.replace(/^\s+|\s+$/g,"");

var searcher = new Array();
searcher[0] = "\r\n";
searcher[1] = "\n\r";
searcher[2] = "\n";
searcher[3] = "\r";

	for(var i = 0; i < searcher.length; i++)
	{
	re = new RegExp(searcher[i], "g");
	value = value.replace(re, "<br />");
	}

return value;
}

CMSka.util.strip_tags = function(str, allowed_tags)
{
var key = '', allowed = false;
var matches = [];
var allowed_array = [];
var allowed_tag = '';
var i = 0;
var k = '';
var html = '';
 
	var replacer = function(search, replace, str)
	{
    return str.split(search).join(replace);
	};
 
	if (allowed_tags)
	{
    allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
	}
 
str += '';
 
matches = str.match(/(<\/?[\S][^>]*>)/gi);
 

	for (key in matches)
	{
    	if(isNaN(key))
    	{
        continue;
		}
 
	html = matches[key].toString();
	allowed = false;
 
		for(k in allowed_array)
		{
		allowed_tag = allowed_array[k];
		i = -1;
	 
			if(i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
			if(i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
			if(i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
	 
			if (i == 0)
			{
			allowed = true;
			break;
	        }
	    }
 
		if(!allowed)
		{
        str = replacer(html, "", str);
    	}
	}
 
return str;
}

CMSka.util.trim = function(str)
{
str = str.replace(/^\s+|\s+$/g,"");

return str;
}


CMSka.util.getTextN = function(str)
{
str = CMSka.util.cleanStrForCheck(str, "");
str = CMSka.util.strip_tags(str);

return str;
}

CMSka.util.getTextBr = function(str)
{
str = CMSka.util.trim(str);
str = CMSka.util.addBR(str);
str = CMSka.util.strip_tags(str);

return str;
}

CMSka.util.getHtmlN = function(str)
{
str = CMSka.util.cleanStrForCheck(str, "");

return str;
}

CMSka.util.getHtmlBr = function(str)
{
str = CMSka.util.trim(str);
str = CMSka.util.addBR(str);

return str;
}


CMSka.util.isNotEmpty = function(value, min, max)
{
var min = min == undefined ? 0 : min;

	if(value.length == 0 && min == 0)
	{
	return true;
	}

var re = /.+/;
	if(value.match(re))
	{
		if(value.length < min || value.length > max)
		{
		return false;
		}
		else
		{
		return true;
		}
	}
	else
	{
	return false;
	}
}

CMSka.util.isNamePage = function(value, min, max)
{
var how = CMSka.util.isNotEmpty(value, min, max);

	if(how == true)
	{
	var re = /^[a-zA-Z0-9_]*$/;
	
		if(!value.match(re))
		{
		return false;
		}
		else
		{
		return true;
	}
	}
	else
	{
	return false;
	}
}


CMSka.util.isEmail = function(value, needs)
{
	if(needs == true)
	{
	var how = CMSka.util.isNotEmpty(value, 1);
		
		if(!how)
		{
		return false;
		}
	}
	else
	{
	var how = CMSka.util.isNotEmpty(value, 0, 0);
	
		if(how == true)
		{
		return true;
		}
	}
	
var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	
	if(!value.match(re))
	{
	return false;
	}
	else
	{
	return true;
	}
}


CMSka.util.isDate = function(value, needs)
{
	if(needs == true)
	{
	var how = CMSka.util.isNotEmpty(value, 1);
		
		if(!how)
		{
		return false;
		}
	}
	else
	{
	var how = CMSka.util.isNotEmpty(value, 0, 0);
	
		if(how == true)
		{
		return true;
		}
	}

var re = /^\d{1,2}(\.)\d{1,2}(\.)\d{4}$/;
	if(!value.match(re))
	{
	return false;
	}
	else
	{
	var date = value.split(".");
	var testDate = new Date(date[2], date[1] - 1, date[0]);
	date[0] = parseInt(date[0], 10);
	date[1] = parseInt(date[1], 10);
	date[2] = parseInt(date[2], 10);
		if(testDate.getDate() == date[0])
		{
			if((testDate.getMonth() + 1) == date[1])
			{
				if(testDate.getFullYear() == date[2])
				{
				return true;
				}
				else
				{
				return false;
				}
			}
			else
			{
			return false;
			}
		}
		else
		{
		return false;
		}
	}
}


CMSka.util.isNumber = function(value, needs, unsigned)
{	
	if(needs == true)
	{
	var how = CMSka.util.isNotEmpty(value, 1);
		
		if(!how)
		{
		return false;
		}
	}
	else
	{
	var how = CMSka.util.isNotEmpty(value, 0, 0);
	
		if(how == true)
		{
		return true;
		}
	}

	if(unsigned == true)
	{	
	var re = /^\d+$/;
	}
	else
	{
	var re = /^[-]?\d+$/;
	}
	
value = value.toString();
	if(!value.match(re))
	{
	return false;
	}
	else
	{
	return true;
	}
}


CMSka.util.isDoubleNumber = function(value, needs, unsigned)
{
	if(needs == true)
	{
	var how = CMSka.util.isNotEmpty(value, 1);
		
		if(!how)
		{
		return false;
		}
	}
	else
	{
	var how = CMSka.util.isNotEmpty(value, 0, 0);
	
		if(how == true)
		{
		return true;
		}
	}

	if(unsigned == true)
	{
	var re = /^\d*\.?\d*$/;
	}
	else
	{
	var re = /^[-]?\d*\.?\d*$/;
	}

value = value.toString();
	
	if(!value.match(re))
	{
	return false;
	}
	else
	{
	return true;
	}
}

CMSka.util.isMatch = function(value_1, value_2)
{
	if(value_1 != value_2)
	{
	return false;
	}
	else
	{
	return true;
	}
}


CMSka.util.setScrollToObject = function(obj, minus)
{
var minus = minus == undefined ? 0 : minus;

var offsetTop = 0;

	while(obj)
	{
	offsetTop += obj.offsetTop;
	obj = obj.offsetParent;
	}

window.scrollTo(0, offsetTop - minus);
}


CMSka.util.getPathByForm = function(obj)
{
var path = "";

	for(var i = 0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].name == "" || typeof obj.elements[i].name == "undefined" || (obj.elements[i].checked == false && (obj.elements[i].type == "checkbox" || obj.elements[i].type == "radio"))) continue;
	
		if(path == "")
		{
		path = obj.elements[i].name + "=" + obj.elements[i].value;
		}
		else
		{
		path += "&" + obj.elements[i].name + "=" + obj.elements[i].value;
		}
	}

return path;
}



CMSka.util.moneyFormat = function(x)
{
var p, i, j;
var s = "", s2 = "";
p = CMSka.util.roundEx(x, 2);
s = p.toString();
p = s.lastIndexOf(".");

	if(p > 0)
	{
	s2 = "," + s.substring(p + 1 ,s.length);
	s = s.substring(0, p);
	}
	else
	{
	s2=",00";
	};
	
	if(s2.length < 3) s2 += "0"; j = 1; i = s.length;
	
	for((i%3) ? i = Math.floor(i/3) : i = Math.floor(i/3) - 1; i > 0; --i)
	{
	p = s.length - (3 * j) - (j - 1);
	j++;
	s = s.substring(0, p) + " " + s.substring(p, s.length);
	}
	
return(s + s2);
}


CMSka.util.percentFormat = function(x)
{
var p, i, j;
var s = "", s2 = "";
p = CMSka.util.roundEx(x, 2);
s = p.toString();
p = s.lastIndexOf(".");

	if(p > 0)
	{
	s2 = "," + s.substring(p + 1 ,s.length);
	s = s.substring(0, p);
	}
	else
	{
	//s2=",00";
	};
	
	if(s2.length < 3) s2 += ""; j = 1; i = s.length;
	
	for((i%3) ? i = Math.floor(i/3) : i = Math.floor(i/3) - 1; i > 0; --i)
	{
	p = s.length - (3 * j) - (j - 1);
	j++;
	s = s.substring(0, p) + " " + s.substring(p, s.length);
	}
	
return(s + s2);
}


CMSka.util.roundEx = function(x, dgt)
{
var p, n;
p = Math.floor(Math.pow(10,dgt));
(x > 0) ? n = Math.floor(x) : n = Math.ceil(x);
return(n + Math.round((x - n) * p) /p);
}
