function browserCheck() 
{
	var b = navigator.appName;
	if (b == "Netscape") 
		this.b = "ns";
	else if (b == "Microsoft Internet Explorer") 
		this.b = "ie";
	else 
		this.b = b
	this.us = navigator.userAgent;
	
	//Opera check
	
	this.opera = this.us.indexOf("Opera");
	if(this.opera != -1){
		this.opera = true;
		this.b = "";
	}
	else {
		this.opera = false;
	}
	
	//Firefox Check
	
	this.firefox = this.us.indexOf("Firefox");
	if(this.us.indexOf("Firefox")!=-1){
		this.firefox = true;	
	}else{
		this.firefox = false;	
	}
	
	//DOM Check
	
	this.DOM = (document.createElement && document.getElementsByTagName);
	
	this.version = navigator.appVersion;
	if (this.b == 'ie')
	{ 
		var ve = this.version.indexOf("MSIE")
		this.v = parseInt(this.version.substr(ve+4))
	}
	else 
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v<5)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.ie55 = (this.version.indexOf('MSIE 5.5')>0)
	this.ie6 = (this.version.indexOf('MSIE 6')>0) 
	this.min = (this.ns||this.ie)
}//end BrowserCheck() 

is = new browserCheck();

function checkForm(name_form)
{
	var Form = document.forms[name_form];
	if (Form != null)
	{
		var elements = Form.getElementsByTagName("select");
		for (var i=0; i<elements.length; i++)
		{
			if (!elements[i].name)
				continue;
			eval("var tt = document.forms." + name_form+ "['" + elements[i].name + "'];");
			if (tt == null)
				continue;
			if ((elements[i].getAttribute('required') != null) && (elements[i].getAttribute('required') != '') && (elements[i].value == ''))
			{
				alert(elements[i].getAttribute('required'));
				elements[i].focus();
				return false;
			}
		}

		var tElement = Form.getElementsByTagName("input");

		for (var i=0; i<tElement.length; i++)
		{
			if (!tElement[i].name || tElement[i].name.indexOf('[')>0)
				continue;
			eval("var tt = document.forms." + name_form+ "['" + tElement[i].name + "'];");
			if (!tt || tt == null)
				continue;

			if (tElement[i].name.indexOf('pass')>-1)
			{
				eval("var tt1 = document.forms." + name_form+ ".IsChangePassword");
				if (tt1 != null && !tt1.checked)
				{
					continue;
				}
			}

			if ((tElement[i].getAttribute('required') != null) && (tElement[i].getAttribute('required') != '') && (tElement[i].value == ''))
			{
				alert(tElement[i].getAttribute('required'));
				tElement[i].focus();
				return false;
			}
			if ((tElement[i].getAttribute('equal') != null) && (tElement[i].getAttribute('equal') != ''))
			{
				var t = tElement[i].getAttribute('equal');
				eval("var tt = document.forms." + name_form+ "." + t);
				if ((tt != null) && (tt.value != tElement[i].value))
				{
					alert(tElement[i].getAttribute('equaltext'));
					tt.focus();
					return false;
				}
			}
			if ((tElement[i].getAttribute('minlength') != null) && (tElement[i].getAttribute('minlength') != '') && (tElement[i].value.length < tElement[i].getAttribute('minlength')))
			{
				alert(tElement[i].getAttribute('mintext'));
				tElement[i].focus();
				return false;
			}

			if (tElement[i].getAttribute('name') && tElement[i].getAttribute('name').indexOf('email')>-1)
			{
				if ((tElement[i].value != '') && !echeck(tElement[i].value)) {
					tElement[i].focus();
					if (tElement[i].getAttribute('required') != null)
						alert(tElement[i].getAttribute('required'));
					else
						alert("Ââåäèòå email");
					return false;
					}
			}
			if (tElement[i].getAttribute('valtype') && (tElement[i].getAttribute('valtype') == 'int'))
			{
				if (!isPositiveInteger(tElement[i].value)) {
					tElement[i].focus();
					alert("Ââåäèòå ïîëîæèòåëüíîå ÷èñëî");
					return false;
					}
			}
			if (tElement[i].getAttribute('valtype') && (tElement[i].getAttribute('valtype') == 'float'))
			{
				if (!isPositiveFloat(tElement[i].value)) {
					tElement[i].focus();
					alert("Ââåäèòå ïîëîæèòåëüíîå ÷èñëî");
					return false;
					}
			}
		}

		return true;
	}
	else
	{
		return fasle;
	}
}

function confirmDelete(question, where)
{
	temp = window.confirm(question);
	if (temp) //delete
	{
		window.location=where;
	}
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true;					
}

function ScreenInfo(){
	this.w=screen.width;
	this.h=screen.height;
}

scrinfo = new ScreenInfo();

function open_window(link,w,h) //opens new window
{
	str = '';
	if (w!='')
		str = str + "width="+w+",";
	if (h!='')
		str = str + "height="+h+",";
	var win = str+"menubar=no,location=no,resizable=yes,scrollbars=yes";
	wishWin = window.open(link,'wishWin',win);
}

function WindowProperty(){
	if(is.ie){
		this.iH = document.body.clientHeight;
		this.iW = document.body.clientWidth;	
	}else{
		this.iH = window.innerHeight;
		this.iW = window.innerWidth;	
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		preloadFlag = true;
	}
}

function clock_status()
{
	window.setTimeout("clock_status()",1000);
	today=new Date();
	if (document.getElementById("clock")!=null)
		document.getElementById("clock").innerHTML="Today: "+today.toLocaleString();
} 

function allowChangePassword(chk)
{
	passwordTR = document.getElementById("trChangePassword");
	passwordRetypeTR = document.getElementById("trChangePasswordRetype");

	if (chk.checked)
	{
		if(!is.ie)
		{
			passwordTR.style.display="table-row";
			passwordRetypeTR.style.display="table-row";
		}
		else
		{
			passwordTR.style.display="block";
			passwordRetypeTR.style.display="block";
		}
	}
	else
	{
		passwordTR.style.display="none";
		passwordRetypeTR.style.display="none";
	}
}


