﻿// JScript File
function set_hiddenDate( _cellDate ) 
{
	document.frmEvtSubmit.hiddenDate.value=_cellDate; 
	document.frmEvtSubmit.submit();
	
}

function fnActivateFlashObjects() {
// Internet Explorer object "Click to activate" fix
	if(navigator.appName == "Microsoft Internet Explorer") {		
		var poObjects = document.getElementsByTagName("object");
		for(var i=0; i < poObjects.length; i++) {
			poObjects[i].outerHTML = poObjects[i].outerHTML;
		}
	}
}

function showPic (whichpic) {
	if (document.getElementById) {
		document.getElementById('placeholder').src = whichpic.href;
	if (whichpic.title) {
		document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
	} else {
		document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
	}
		return false;
	} else {
		return true;
	}
}


function fnGetPosition() {
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

	var dsocLeft=document.all? iebody.scrollLeft : pageXOffset
	var dsocTop=document.all? iebody.scrollTop : pageYOffset
	
	return [dsocLeft, dsocTop];
}

function fnDisplayUploadWaitScreen(psDialogText) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
  }	
	
	var posXY = fnGetPosition();
	
	var poScreen = document.getElementById('uploadWaitScreen');		
		poScreen.style.width = myWidth + 'px';
		poScreen.style.height = document.body.clientHeight + 'px';
		poScreen.style.visibility = 'visible';
		
	var poDialog = document.getElementById('uploadWaitScreenDialog');	
		//poDialog.style.width = 140;
		//poDialog.style.height = 171;
		//poDialog.innerHTML = "<img src=\"../_images/loading_anim.gif\">";
		poDialog.style.width = 300;
		poDialog.style.height = 150;
		poDialog.innerHTML = psDialogText;
		poDialog.style.left = ((myWidth / 2) - 155) + 'px';
		poDialog.style.top = (((myHeight / 2) + posXY[1]) - 75) + 'px';
		poDialog.style.visibility = 'visible';
}

function fnFileUploadSelect(poFormElement){
	var paInput = document.getElementsByTagName('input');	
	for(i=0;i < paInput.length; i++) {
		if(paInput[i].type == "file"){			
			if(paInput[i].name != poFormElement) {
				paInput[i].disabled = 'disabled';
			}
		}
	}
}

function fnShowHide(psElementID) {
	var psElement = document.getElementById(psElementID);
	
	switch (psElement.style.display)
	{
	case 'none':
		psElement.style.display = "block";
		break;
	case 'block':
		psElement.style.display = "none";
		break;
	}
}

function fnFormSubmit(psFormID, psCmd) {
	document.getElementById('cmd').value = psCmd;
	document.getElementById(psFormID).submit();
}

function fnErrorMessage(poElement, psError) {
    if(psError != '') {
        poElement.style.display = 'block';        
    }
}

function fnGoTo(psLocation) {
	if(psLocation == 'back') {
		history.go(-1);
	}
	else {
		location.href = psLocation;
	}
}

function fnWindowOpen(psUrl, psName, piWidth, piHeight) {
	poWindow = window.open(psUrl, psName,'width='+piWidth+',height='+piHeight+',left='+(screen.width - piWidth) / 2+',top='+(screen.height - piHeight) / 2+',toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');
	poWindow.focus();
}

function fnPressePop(psUrl, psName, piWidth, piHeight) {
	poWindow = window.open(psUrl, psName,'width='+piWidth+',height='+piHeight+',left='+(screen.width - piWidth) / 2+',top='+(screen.height - piHeight) / 2+',toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');
	poWindow.focus();
}


function fnConfirmCmd(psText) {
	var agree=confirm(psText);
	if (agree) {
		return true;
	}
	else {
		return false ;
	}
}

function makeRequest(psUrl, psElement) {
    var httpRequest;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/xml');
            // See note below about this line
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                       try {
                            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                           } 
                         catch (e) {}
                      }
                                   }

    if (!httpRequest) {
        //alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    httpRequest.onreadystatechange = function() { returnContents(httpRequest, psElement); };
    httpRequest.open('GET', psUrl, true);
    httpRequest.send(null);

}

function returnContents(httpRequest, psElement) {

    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            if(document.getElementById(psElement).value) {
				document.getElementById(psElement).value = httpRequest.responseText;
				}
			else if(document.getElementById(psElement).innerHTML) {
				document.getElementById(psElement).innerHTML = httpRequest.responseText;
				}
			
            //alert(httpRequest.responseText);
        } else {
            document.getElementById(psElement).value = httpRequest.responseText
            //alert('There was a problem with the request.');
        }
    }

}




// Password strength meter
function fnPasswordStr(psPassword) {
	psPassword = psPassword.replace(/^\s*/g, "");
	psPassword = psPassword.replace(/\s*$/g, "");
	var piPoints	= 0;
	var piLength	= psPassword.length;
	if(piLength >= 3 && piLength <= 12) {
		piPoints = (piLength - 3) * 3;
	}
	else {
		piPoints = (piLength - 3) * 2;
		if(piLength > 12) piPoints = piPoints + 9;
	}
	if(/[a-z]/.test(psPassword)) {
		piPoints = piPoints + 5;
		if(psPassword.match(/[a-z]/g).length >= 2) piPoints = piPoints + 2;
		if(psPassword.match(/[a-z]/g).length >= 3) piPoints = piPoints + 1;
	}
	if(/[A-Z]/.test(psPassword)) {
		piPoints = piPoints + 6;
		if(psPassword.match(/[A-Z]/g).length >= 2) piPoints = piPoints + 2;
		if(psPassword.match(/[A-Z]/g).length >= 3) piPoints = piPoints + 1;
	}
	if(/\d/.test(psPassword)) {
		piPoints = piPoints + 6;
		if(psPassword.match(/\d/g).length >= 2) piPoints = piPoints + 2;
		if(psPassword.match(/\d/g).length >= 3) piPoints = piPoints + 1;
	}
	if(/[^A-Za-z0-9]/.test(psPassword)) {
		piPoints = piPoints + 6;
		if(psPassword.match(/[^A-Za-z0-9]/g).length >= 2) piPoints = piPoints + 3;
		if(psPassword.match(/[^A-Za-z0-9]/g).length >= 3) piPoints = piPoints + 2;
	}
	if(/[a-z]/.test(psPassword) && /[A-Z]/.test(psPassword)) piPoints = piPoints + 3;
	if(/[A-Za-z]/.test(psPassword) && /\d/.test(psPassword)) piPoints = piPoints + 4;
	if(/[^A-Za-z0-9]/.test(psPassword) && /[A-Za-z0-9]/.test(psPassword)) piPoints = piPoints + 3;
	if(/[^A-Za-z0-9]/.test(psPassword) && /[A-Za-z]/.test(psPassword) && /\d/.test(psPassword)) piPoints = piPoints + 4;
	var psSwitch = psPassword;
	psSwitch = psSwitch.replace(/[A-Z]+/g, "|");
	psSwitch = psSwitch.replace(/[a-z]+/g, "|");
	psSwitch = psSwitch.replace(/\d+/g, "|");
	psSwitch = psSwitch.replace(/[^A-Za-z0-9|]+/g, "|");
	if(psSwitch.length < 12)	piPoints = piPoints + ((psSwitch.length - 1) * 2);
	else						piPoints = piPoints + 22;
	var psPrevChar		= "";
	var piPrevNumber	= -1;
	var piPrevQwerty	= -1;
	var piPrevAlpha		= -1;
	var psCurrChar, piCurrNumber, piCurrQwerty, piCurrAlpha;
	while(piLength > 0) {
		psCurrChar = psPassword.substring(piLength - 1, piLength).toLowerCase();
		if(psPrevChar == psCurrChar) {
			piPoints = piPoints - 2;
		}
		else {
			if(psCurrChar == "|") {
				piCurrNumber	= -1;
				piCurrQwerty	= -1;
				piCurrAlpha		= -1;
			}
			else {
				piCurrNumber	= "1234567890".indexOf(psCurrChar) + 1;
				piCurrQwerty	= "qwertyuiop|asdfghjkl|zxcvbnm".indexOf(psCurrChar) + 1;
				piCurrAlpha		= "abcdefghijklmnopqrstuvwxyz".indexOf(psCurrChar) + 1;
			}
			if(
				(piCurrNumber > 0 && (piPrevNumber == piCurrNumber - 1 || piPrevNumber == piCurrNumber + 1)) ||
				(piCurrQwerty > 0 && (piPrevQwerty == piCurrQwerty - 1 || piPrevQwerty == piCurrQwerty + 1)) ||
				(piCurrAlpha > 0 && (piPrevAlpha == piCurrAlpha - 1 || piPrevAlpha == piCurrAlpha + 1))
			) {
				piPoints = piPoints - 2;
			}
			psPrevChar = psCurrChar;
			piPrevNumber	= (piCurrNumber > 0)	? piCurrNumber	: -1;
			piPrevQwerty	= (piCurrQwerty > 0)	? piCurrQwerty	: -1;
			piPrevAlpha		= (piCurrAlpha > 0)		? piCurrAlpha	: -1;
		}
		piLength = piLength - 1;
	}
	if(piPoints > 0) {
		if(psPassword.length <= 3)		piPoints = Math.ceil(piPoints / 2);
		else if(psPassword.length <= 4)	piPoints = Math.ceil(piPoints / 1.5);
	}
	piPoints = piPoints * 1.2;
	if(parseInt(piPoints) <= 0) piPoints = 0;
	if(piPoints > 100) piPoints = 100;
    try {		
		var poDivPasswordStr1 = document.getElementById("divPasswordStrength1");
		var poDivPasswordStrCount = document.getElementById("divPasswordStrengthCount");
		if(piPoints >= 0) {
			// Color trs1=20, trs2=40
			poDivPasswordStr1.style.display = "block";
			poDivPasswordStr1.style.width = Math.round(piPoints*1.6) + "px";
			poDivPasswordStrCount.innerHTML = Math.round(piPoints) + "%";
		}

    }
    catch(e) {
    }
}