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 || tElement[i].getAttribute('nocheck'))
				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 && (tElement[i].value != ''))
			{
				if (!echeck(tElement[i].value)) {
					tElement[i].focus();
					alert('Ââåäèòå ïðàâèëüíûé E-mail!');
					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 (tElement[i].value != '' && !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 confirmDelete2(question, where)
{
	temp = window.confirm(question);
	if (!temp) 
	{
		return;
	}
	temp = window.prompt('×òîáû ïîäòâåðäèòü, ÷òî âû íå ïüÿíû ââåäèòå delete');
	if (temp!='delete') 
	{
		return;
	}
	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";
	}
}

function PWD(a,m) {
	var m
	var a
	if(!a) { a == "12" }
    if(m == "8") { var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~`[]{}|\:;\"'<>,.?/ "; }
    if(m == "0") { var chars = "1234506789"; }
    if(m == "1") { var chars = "^[_]!#$%&()<=>{}|?@*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ~abcdefghijklmnopqrstuvwxyz"; }
	if(m == "2") { var chars = "0123456789abcdef"; }
	if(m == "3") { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; }
	if(m == "4") { var chars = "101"; }
	if(m == "5") { var chars = "435XH781$xr!x0fORoi-+^@~|_|)(/"; }
	if(m == "6") { var chars = "AaA-a-BbCcC(c(DdEeE-e-FfGgG,g,HhIiI-i-JjKkK,k,LlL,l,MmNnN,n,OoPpRrSsS(s(TtUuU-u-VvZzZ(z("; }
	if(m == "7") { var chars = "ÀàÁáÂâÃãÄäÅå¨¸ÆæÇçÈèÉéÊêËëÌìÍíÎîÏïÐðÑñÒòÓóÔôÕõÖö×÷ØøÙùÚúÛûÜüÝýÞþßÿ"; }
	
	var pass = ""
	    for (x=0; x < a; x++){
			rand  = Math.random() * chars.length;
			genn = Math.round(rand);
			while (genn<=0){
              	   genn++;
       			}
		 pass+=chars.charAt(genn);
		}
	document.getElementById('pass').value=pass;
}

function OperatorChange(el)
{
	if (el.value=='2')
		$("#ffgg[name='number_el']").hide();
	else
		$("#ffgg[name='number_el']").show();
	$("#CLAIM").val('');
	$("#PNUMBER").val('');
}

function OperatorChange2(el)
{
	pas_input = document.getElementById('sel_pnumber_form');
	if (el.value=='2')
	{
		pas_input.style.display="none";		
	}
	else
	{
		if(!is.ie)
		{
			pas_input.style.display="table-row";			
		}
		else
		{
			pas_input.style.display="block";
		}
	}
	$("#CLAIM").val('');
	$("#PNUMBER").val('');
}
