﻿
var Arr = new Image();
Arr.src = "/web/images/arrow.gif";
var ArrDown = new Image();
ArrDown.src = "/web/images/arrow_down.gif";

function verify(f)
{
	var i = 0;
	for (i = 0; i < f.elements.length; i++)
	{
		if ( ! f[i].value )
		{
			return false;
		}
	}
	return true;
}



function helpwin()
{
	openwindow('http://web.bmby.com/help/EnglishManual/', '', screen.width, screen.height, false);
	return false;
}

function ShowMenuPart(div)
{
	menudiv = document.getElementById('menu'+div);
	arrow = document.getElementById('Image_'+div);
	if ( menudiv.style.display == 'block' )
	{
		menudiv.style.display = 'none';
		arrow.src = "/web/images/arrow.gif";
	}
	else
	{
		menudiv.style.display = 'block';
		arrow.src = "/web/images/arrow_down.gif";
	}


}


function GetFile(FileName)
{
	var f = document.forms['downloadform'];
	f.target = '_balnk';
	f['FileName'].value = String(FileName);
	f.submit();
}

function openwindow(URL, WinName, width, height, external){

	var width_factor = ( ( screen.width / 100 ) * 98 )
	if( width >= width_factor ) width = width_factor;

	var height_factor = ( ( screen.height / 100 ) * 90 )
	if( height >= height_factor ) height = height_factor;

	var top = ( ( screen.height-height) / 2 ) - ( screen.height / 20 );
	if( top < 1 ) top = 1;

	var left = ( screen.width - width ) / 2 ;
	if( left < 1 ) left = 1;

	var winmethods = 'toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=1,resizable=1,copyhistory=no';
	winmethods += ',width='+width+',height='+height+',top='+top+',left='+left;
	var win = window.open(URL, WinName, winmethods);
	if(!external)
	{
		win.resizeTo(width, height);
		win.moveTo(left, top);
	}
	win.focus();
}

onload = disableAutoComplete;
function disableAutoComplete()
{
	if ( document.forms[0] && document.forms[0].Username && document.forms[0].Username.type != 'hidden')
	{
		document.forms[0].Username.setAttribute('autocomplete','off')
		document.forms[0].Username.focus();
	}
}


var ShowInterDiv = false;
function InterLang(show)
{
	var interDiv = document.getElementById('inter');
	if ( show )
	{
		ShowInterDiv = true;
		interDiv.style.right = String(2 + 'px');
		interDiv.style.display = 'block';
	}
	else if ( ! ShowInterDiv )
	{
		interDiv.style.display = 'none';
	}
	ShowInterDiv = false;
}

function capsProcess( e ) {
  if( !e ) { e = window.event; } if( !e ) { return; }
  var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
  if (theKey == 20) { capsDetect(false); }
}

function capsDetect( e ) {
  if( !e ) { e = window.event; } if( !e ) { MWJ_say_Caps( false ); return; }
  var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
//  if (theKey == 20) { alert("Caps pressed"); }
  var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
  var c = String.fromCharCode(theKey);
  var cUC = c.toUpperCase();
  var cLC = c.toLowerCase();
  if (cUC!=cLC) {
    MWJ_say_Caps( ( cUC==c && !theShift ) || ( cLC==c && theShift ) );
  }
}
function MWJ_say_Caps( capsEngaged ) {
	if( capsEngaged ) {
    if (document.getElementById("CapsNotifier").style.display == 'none') {
	    document.getElementById("CapsNotifier").style.display = 'block';
	  }
	} else {
    if (document.getElementById("CapsNotifier").style.display == 'block') {
	    document.getElementById("CapsNotifier").style.display = 'none';
	  }
	}
}

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 null;
}

function eraseCookie(name) {
	createCookie(name,"0",-1);
}

function setSystem(sys, frm)
{
	date = new Date(2010,10,07)
	switch(sys)
	{
		case "1":
			frm.action='/index.php';
			document.cookie = "software=1;expires=" + date.toGMTString();
		break
		
		case "2":
			frm.action='/manage/';
			document.cookie = "software=2;expires=" + date.toGMTString();
		break
		
		default:
			frm.action='/index.php';
			document.cookie = "software=0;expires=" + date.toGMTString();
		break;
	}
}
