
if (typeof(window['is_patternmatching_translation_loaded']) == "undefined")
{
	var trans_js_href = document.location.href;
	trans_js_href = trans_js_href + ((trans_js_href.indexOf("?") != -1)?"&":"?") + "class=cAuxilary&method=mGetPatternMatchingJS&path=engine/common/class/";
	document.write("<script language='JavaScript' src='" + trans_js_href + "'></script>");
}

function findParentTab(element) 
{
	if (element.parentElement == null)
	{
		return null;
	}

	if ((element.parentElement.className == "tab-page") )
	{
		return element.parentElement;
    }
	else 
	{
		return findParentTab(element.parentElement);
	}
}

function fSetActiveParentTab(el)
{
	
	var tab = findParentTab(el);
	
	if (tab != null && null != tabpane)
	{
		for (i=0; i<=tabpane.pages.length-1; i++)
		{
			if (tabpane.pages[i].element.getAttribute("id") == tab.getAttribute("id"))
			{
				tabpane.pages[i].select();
				tabpane.setSelectedIndex(i);
				return true;
				//tabpane.pages[i].show();
			}
		}
		return false;
	}	
	else return false;
}


function checkForPatternMatching()
{
	var args=checkForPatternMatching.arguments;
	var argsLen=args.length;
	if(argsLen==0)
	{
		if(document.all.Forms)if(!checkForPatternMatchingInForm(document.all.Forms))return false;
	}
	else
	{
		for(var i=0;i<argsLen;i++)
		{
			var theForm=args[i];
			if(theForm)if(!checkForPatternMatchingInForm(theForm))return false;
		}
	}
	return true;
}

function checkForPatternMatchingInForm(theForm)
{
	for(var k=0;k<theForm.elements.length;k++)
	{
		var theEl=theForm.elements[k];
		if(!checkForPatternMatchingOperate(theEl))return false;
	}
	return true;
}

function checkForPatternMatchingInElement()
{
	var args=checkForPatternMatchingInElement.arguments;
	var argsLen=args.length;
	for(var i=0;i<argsLen;i++)
	{
		var theEl=args[i];
		if(theEl)if(!checkForPatternMatchingOperate(theEl))return false;
	}
	return true;
}

function checkForPatternMatchingOperate(oRef)
{
	this.theEl=oRef;
	this.setFocus=function()
	{
		if(!/hidden/.test(this.theEl.type.toLowerCase())||!/hidden/.test(this.theEl.currentStyle.visibility)||!/none|^$/.test(this.theEl.currentStyle.display))this.theEl.focus();
		if(typeof(this.theEl.type)!='undefined'&&this.theEl.isTextEdit&&!/button|submit|reset|hidden/.test(this.theEl.type.toLowerCase()))
		{
			var theTSeletion=this.theEl.createTextRange();
			theTSeletion.select();
		}
		return;
	};
	this.checkLengths=function()
	{
		if((typeof(this.theEl.valuemaxlength)!='undefined'&&!isNaN(parseInt(this.theEl.valuemaxlength))&&typeof(this.theEl.value)!='undefined')||(typeof(this.theEl.valueminlength)!='undefined'&&!isNaN(parseInt(this.theEl.valueminlength))&&typeof(this.theEl.value)!='undefined'))
		{
			if(typeof(this.theEl.valuemaxlength)!='undefined'&&typeof(this.theEl.valueminlength)!='undefined')
			{
				if(parseInt(this.theEl.valuemaxlength)<parseInt(this.theEl.valueminlength))
				{
					var theMax=this.theEl.valuemaxlength;
					this.theEl.valuemaxlength=this.theEl.valueminlength;
					this.theEl.valueminlength=theMax;
				}
			}
			if(typeof(this.theEl.maxLength)!='undefined')
			{
				if(parseInt(this.theEl.valueminlength)>this.theEl.maxLength)this.theEl.valueminlength=this.theEl.maxLength;
			}
			if(this.theEl.value.length>parseInt(this.theEl.valuemaxlength)||this.theEl.value.length<parseInt(this.theEl.valueminlength))
			{
				if(typeof(this.theEl.valuelengthmessage)!='undefined'&&this.theEl.valuelengthmessage!='')
				{
					alert(this.theEl.valuelengthmessage.replace("\\n","\n"));
				}
				else
				{
					if(this.theEl.value.length>parseInt(this.theEl.valuemaxlength))
						alert('\n' + (typeof(window['TXT_ALERT_MAX_VALUE_VIOLATION']) != "undefined")?TXT_ALERT_MAX_VALUE_VIOLATION:"Max length violation!" + "\n\n" + (typeof(window['TXT_ALERT_MAX_VALUE_CURRENT_VALUE']) != "undefined")?TXT_ALERT_MAX_VALUE_CURRENT_VALUE:"Max legth for selected field is" + this.theEl.valuemaxlength + '.\n\n');
					if(this.theEl.value.length<parseInt(this.theEl.valueminlength))
						alert('\n' + (typeof(window['TXT_ALERT_MIN_VALUE_VIOLATION']) != "undefined")?TXT_ALERT_MIN_VALUE_VIOLATION:"Min length violation!" + "\n\n" + (typeof(window['TXT_ALERT_MIN_VALUE_CURRENT_VALUE']) != "undefined")?TXT_ALERT_MIN_VALUE_CURRENT_VALUE:"Min legth for selected field is" + this.theEl.valueminlength + '.\n\n');
				}
				fSetActiveParentTab(oRef);
				this.setFocus();
				return false;
			}
		}
		return true;
	};
	if(!this.theEl.readOnly&&!this.theEl.disabled)
	{
		if(!this.checkLengths())return false;
		if(typeof(this.theEl.regexp)!='undefined'&&this.theEl.regexp!='')
		{
			if(typeof(this.theEl.condition)!='undefined'&&this.theEl.condition!='')
			{
				var r=eval(this.theEl.condition);
				if(r!=null&&!r)return true;
				else if(r==null)return false;
			}
			var re=new RegExp(this.theEl.regexp);
			var result=re.test(this.theEl.value);
			if(result)return true;
			
			var msg_1 = (typeof(window['TXT_ALERT_INCORRECT_FIELD_FORMAT']) != "undefined")?TXT_ALERT_INCORRECT_FIELD_FORMAT:"Incorrect field format!";
			var msg_2 = (typeof(window['TXT_ALERT_YOU_MUST_USE_THE_FOLLOWING_FIELD_FORMAT']) != "undefined")?TXT_ALERT_YOU_MUST_USE_THE_FOLLOWING_FIELD_FORMAT:"You must use selected format";
			
			if(typeof(this.theEl.message)!='undefined'&&this.theEl.message!='')
			{
				if (this.theEl.getAttribute("type")=="file"&&null!=this.theEl.getAttribute("loaded"))
				{
					return true;
				}
				alert(this.theEl.message.replace("\\n","\n"));
			}
			else alert('\n' + msg_1 + '\n\n' + ((this.theEl.format&&this.theEl.format!='')?(msg_2 + ':\n\n'+this.theEl.format+'\n\n'):''));
			fSetActiveParentTab(oRef);
			this.setFocus();
			return false;
		}
	}
	return true;
}