/**************************************************************************
*                                                                         *
*   This application is developed and owned by Thomas Idea Co.,Ltd.       *
*   Thomas Idea Co., Ltd is granted  license from Thomas Idea  *
*   for its internal use only. Usage on any parts of the program without  *
*   a permission from Thomas Idea Co.,Ltd. is illegal and prohibited.     *
*   This application is protected by the International Right Law.         *
*                       -  All rights reserved.                           *
*                                                                         *
**************************************************************************/
var fieldDate;
var specialCharList = "!@#$%^&*()+={}[]\\/><'?:;~,.|\"";

function getSelectValue(drpdwn) {
	str = drpdwn.options[drpdwn.selectedIndex].value;
	return str;
}

function showMessage(txt, obj) {
	alert(txt);
	obj.focus();
	return false;
}

function openWin(pages, winName, detail) {
	w = open (pages, winName, detail);
	if (w.opener == null)
		w.opener = self;
	w.focus();
}

function openerReload(formStr) {
	openerForm = eval("opener.document." + formStr);
	if (!isOpenerClose() && openerForm != null)
		openerForm.submit();
}

function isOpenerClose() {
	if (opener.closed)
		return true;
	else
		return false;
}

function isElement(formStr, elementStr) {
	if (!isOpenerClose()) {
		openerForm = eval("opener.document." + formStr);
		openerObject = eval("opener.document." + formStr + "." + elementStr);
		if ((openerForm == null) && (openerObject == null))
			return false;
		else
			return true;
	} else
		return false;
}

function replaceAll(strValue, oldStr, newStr) {
	var index;
	var i = 0, start = 0, end = 0;
	tempStr = "";
	while (strValue.indexOf(oldStr, start) != -1) {
		end = strValue.indexOf(oldStr, start);
		tempStr = tempStr + strValue.substring(start, end) + newStr;
		start = end + oldStr.length;
	}
	tempStr = tempStr + strValue.substring(start, strValue.length);
	return tempStr;
}

function isEmpty(str) {
	if (str == null || str == "")
		return true;
	else
		return false;
}

function isSpace(str) {
	var index;
	for (index = 0; index < str.length; index++) {
		if(str.charAt(index) != " ")
			return false;
	}
	return true;
}

function isNumber(numStr) {
	var numRegEx = /^\d{0,}$/;
	return numRegEx.test(numStr);
}

function isEmail(emailStr) {
	var emlRegEx = /^[a-zA-Z]+[\w\.\-]*@[\da-zA-Z]+([\.\_\-][\da-zA-Z]+)+$/;
	return emlRegEx.test(emailStr);
}

function isDouble(dblStr) {
	var dblRegEx = /^\d{0,}[.]?\d{0,}$/;
	return dblRegEx.test(dblStr);
}

function chkNumber(){
	if(event.keyCode < 48 || event.keyCode > 57) {
		if(event.keyCode != 46)
			event.keyCode = 0;
	}
}


function isFloat(str) {
	dotindx = 0, dotflag = false;
	field = "", tmp = "";
	for (i = 0; i < str.length; i++)
	{
		tmp = str.substring(i, i+1);
		if (tmp == ".")
		{
			if (dotflag==false)
			{
				dotflag = true;
			}
			else
			{
				return false;
			}
		}
	}
	if (dotflag)
	{
		field=replaceAll(str, ".", "");
		if (isNumber(field))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{		
		if (isNumber(str))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}	

/*
	Allow 0-9
*/
function chkNumeric() {
	if (event.keyCode < 48 || event.keyCode > 57) {
		event.keyCode = 0;
	}
}

/*
	Allow a-z, A-Z
*/
function chkEngChar() {
	if (event.keyCode < 65 || event.keyCode > 122)
		event.keyCode = 0;
	else if (event.keyCode >= 91 && event.keyCode <= 96)
		event.keyCode = 0;
}

/*
	Allow a-z, A-Z and 0-9 only
*/
function chkFCode() {
	if (event.keyCode < 48 || event.keyCode > 122) {
		if (event.keyCode != 13) {
			event.keyCode = 0;
		}
	} else if ((event.keyCode >= 58 && event.keyCode <= 64) || (event.keyCode >= 91 && event.keyCode <= 96)) {
		event.keyCode = 0;
	}
}

/*
	Allow a-z, A-Z, 0-9 and _ only
*/
function chkFolderName() {
	if (event.keyCode < 48 || event.keyCode > 122) {
		if (event.keyCode != 13)
			event.keyCode = 0;
	} else if ((event.keyCode >= 58 && event.keyCode <= 64) || (event.keyCode >= 91 && event.keyCode <= 96)) {
		if (event.keyCode != 95)
			event.keyCode = 0;
	}
}

function ignorePaste() {
	if ((event.ctrlKey) && (event.keyCode == 86)) {
		event.keyCode = 0;
		return false;
	}
}

function makeNumeric(str) {
	if (isNumber(str))
		return str;
	else
		return "";
}

function clearSubmit(frmTemp) {
	frmTemp.onsubmit = function() {
		return true;
	}
}

function getElementValue(formStr, elementStr, objType) {
	val = "";
	if (isElement(formStr, elementStr)) {
		if (objType == "T")
			val = eval("opener.document." + formStr + "." + elementStr + ".value");
		else if (objType == "C") {
			openerObject = eval("opener.document." + formStr + "." + elementStr);
			if (openerObject.checked)
				val = eval("opener.document." + formStr + "." + elementStr + ".value");
		} else if (objType == "R") {
			openerObject = eval("opener.document." + formStr + "." + elementStr);
			val = getRadioValue(openerObject)
		} else if (objType == "S") {
			openerObject = eval("opener.document." + formStr + "." + elementStr);
			val = getDropDownValue(openerObject)
		}
	}
	return val;
}

//## Date Function ##
function isCorrectDuration(fromField, toField) {
	startDate = getLongDateFormat(fromField);
	endDate = getLongDateFormat(toField);
	if (endDate < startDate)
		return false;
	else
		return true;
}

function isCorrectDate(fromDateObj, toDateObj, strValue) {
	result = true;
	strValue1 = strValue.substring(0, 1).toUpperCase() + strValue.substring(1, strValue.length);
	if (isSpace(fromDateObj.value) && !isSpace(toDateObj.value))
		result = showMessage("Please input " + strValue + " (Start).", fromDateObj);
	else if (!isSpace(fromDateObj.value) && isSpace(toDateObj.value))
		result = showMessage("Please input " + strValue + " (End).", toDateObj);
	else if (!isSpace(fromDateObj.value) && !isSpace(toDateObj.value)) {
		if (!isCorrectDuration(fromDateObj.value, toDateObj.value))
			return showMessage(strValue1 + " (Start) should be later than " + strValue + " (End).", toDateObj);
	}
	return result;
}

function getLongDateFormat(dateValue) { //dd/mm/yyyy to Month dd, yyyy
	var longMonthName = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	dd = eval(dateValue.substring(0,dateValue.indexOf('/')));
	mm = eval(dateValue.substring(dateValue.indexOf('/') + 1,dateValue.lastIndexOf('/')));
	yy = eval(dateValue.substring(dateValue.lastIndexOf('/') + 1,dateValue.length));
	longDate = longMonthName[mm] + " " + dd + ", " + yy;
	longDate = new Date(longDate);
	return longDate
}

function isDate(dd, mm, yy) {
  var rtn = false;
  yy = (parseInt(yy)-543)+"";
  if (mm == 2){
    if (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) {
      if (dd <= 29) {rtn = true;}
    } else {
      if (dd <= 28) {rtn = true;}
    }
  }
  else if  ((mm == 1) || (mm == 3) || (mm == 5) ||(mm == 7) || (mm == 8) || (mm == 10) || (mm == 12)){
    if (dd <= 31) rtn = true;
  }
  else {     
    if (dd <= 30) rtn = true;
  }
  return rtn;    
}

function isDate(dd, mm, yy) {
  var rtn = false;
  yy = (parseInt(yy)-543)+"";
  if (mm == 2){
    if (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0)) {
      if (dd <= 29) {rtn = true;}
    } else {
      if (dd <= 28) {rtn = true;}
    }
  }
  else if  ((mm == 1) || (mm == 3) || (mm == 5) ||(mm == 7) || (mm == 8) || (mm == 10) || (mm == 12)){
    if (dd <= 31) rtn = true;
  }
  else {     
    if (dd <= 30) rtn = true;
  }
  return rtn;    
}

function getCurrentDate() {
	tdy = new Date();
	tdyDay = tdy.getDate();
	tdyMonth = tdy.getMonth() + 1;
	tdyYear = tdy.getYear();
	if (tdyDay < 10)
		tdyDay = "0" + tdyDay;
	if (tdyMonth < 10)
		tdyMonth = "0" + tdyMonth;
	return tdyDay + "/" + tdyMonth + "/" + tdyYear;
}

function getDateNow(){
	today=new Date();						
	document.write(today.getDate());
	document.write(".");
	document.write(today.getMonth()+1);
	document.write(".");
	document.write(today.getYear());
}
//## Date Function ##

//## File ##
function getFileType(fileSource) {
	return fileSource.substring(fileSource.lastIndexOf('.') + 1,fileSource.length);
}

function getFileName(fileSource) {
	return fileSource.substring(fileSource.lastIndexOf('\\') + 1,fileSource.lastIndexOf('.'));
}

function getFileNameFromUrl(fileSource) {
	return fileSource.substring(fileSource.lastIndexOf('/') + 1,fileSource.lastIndexOf('.'));
}

function getFullFileName(fileSource) {
	return fileSource.substring(fileSource.lastIndexOf('\\') + 1,fileSource.length);
}

//var imageFile = "س͡Ҿ (gif, jpg, png, jpeg, bmp).";
var imageFile = "Please select a correct file (gif, jpg, png, jpeg, bmp).";
function isImage(str) {
	ext = getFileType(str);
	ext = ext.toLowerCase();
	if (ext != "gif" && ext != "jpg" && ext != "png" && ext != "jpeg" && ext != "bmp") {
		return false
	}
	else
		return true;
}

//var imageFile2 = "س͡Ҿ (jpg).";
var imageFile2 = "Please select a correct file (jpg).";
function isImage2(str) {
	ext = getFileType(str);
	ext = ext.toLowerCase();
	if (ext != "jpg" ) {
		return false
	}
	else
		return true;
}

//var flashFile = "س͡Ż Flash (swf).";
var flashFile = "Please select a correct file (swf).";
function isFlash(str) {
	ext = getFileType(str);
	ext = ext.toLowerCase();
	if (ext != "swf") {
		return false
	}
	else
		return true;
}

//var videoFile = "س͡մ (ra, rm, ram, rom, mpg, mpeg, wmv, mov, avi).";
var videoFile = "Please select a correct file (ra, rm, ram, rom, mpg, mpeg, wmv, mov, avi).";
function isVideo(str) {
	ext = getFileType(str);
	ext = ext.toLowerCase();
	if (ext != "ra" && ext != "rm" && ext != "ram" && ext != "rom" && ext != "mpg" && ext != "mpeg" && ext != "wmv" && ext != "mov" && ext != "avi") {
		return false
	}
	else
		return true;
}

//var audioFile = "س͡§ (mp3, wma, midi, wav).";
var audioFile = "Please select a correct file (mp3, wma, midi, wav).";
function isAudio(str) {
	ext = getFileType(str);
	ext = ext.toLowerCase();
	if (ext != "mp3" && ext != "wma" && ext != "midi" && ext != "wav") {
		return false
	}
	else
		return true;
}

//var multimediaFile = "س͡ŵ (gif, jpg, png, jpeg, bmp, swf, ra, rm, ram, rom, mpg, mpeg, wmv, mov, avi, mp3, wma, midi, wav).";
var multimediaFile = "Please select a correct file (gif, jpg, png, jpeg, bmp, swf, ra, rm, ram, rom, mpg, mpeg, wmv, mov, avi, mp3, wma, midi, wav).";
function isMultimedia(str) {
	ext = getFileType(str);
	ext = ext.toLowerCase();
	if (ext != "gif" && ext != "jpg" && ext != "png" && ext != "jpeg" && ext != "bmp" && ext != "swf" && ext != "ra" && ext != "rm" && ext != "ram" && ext != "rom" && ext != "mpg" && ext != "mpeg" && ext != "wmv" && ext != "mov" && ext != "avi" && ext != "mp3" && ext != "wma" && ext != "midi" && ext != "wav") {
		return false
	}
	else
		return true;
}

//var allowFile = "س͡ŷ˹ (gif, jpg, png, jpeg, pdf, doc, xls, ppt, zip).";
var allowFile = "Please select a correct file (gif, jpg, png, jpeg, pdf, doc, xls, ppt, zip).";
function isAllowFile(str) {
	ext = getFileType(str);
	ext = ext.toLowerCase();
	if (ext != "gif" && ext != "jpg" && ext != "jpeg") {
		return false
	}
	else
		return true;
}
//## File ##

function isAllowFilez(flName,fltyp) {
	var allowFile = fltyp;
	fileType = getFileType(flName).toLowerCase();
	if (allowFile.indexOf(fileType) >= 0)
		return false;
	else
		return true;
}

//## Drop Down Object ##
function isSelectDropDown(drpdwn) {
	str = drpdwn.options[drpdwn.selectedIndex].value;
	if ( str == null || str == "" || str.toUpperCase() == "-NONE-")
		return false;
	else
		return true;
}

function markSelectValue(drpdwn, data) {
	for (i=0; i<drpdwn.length; i++) {
		if (drpdwn.options[i].value == data)
			drpdwn.selectedIndex = i;
	}
}

function getDropDownValue(drpdwn) {
	var str = drpdwn.options[drpdwn.selectedIndex].value;
	return str;
}

function getDropDownText(drpdwn) {
	var str = drpdwn.options[drpdwn.selectedIndex].text;
	return str;
}

function getDropDownIndex(drpdwn) {
	var str = drpdwn.options[drpdwn.selectedIndex].index;
	return str;
}

function refreshDropDown(firstDrop, secondDrop, arr, remain) {
	var dataID = getDropDownValue(firstDrop);
	secondDrop.length = remain;
	var indx = secondDrop.length;
	var count = arr[0].length;
	if (isSelectDropDown(firstDrop)) {
		for (var i=0; i<=count - 1; i++) {
			if (arr[0][i] == dataID) {
				secondDrop.options[indx] = new Option(arr[2][i], arr[1][i], false, false)
				indx++;
			}
		}
	}
	secondDrop.selectedIndex = 0;
}

function clearDropDown(dropObj, remain) {
	dropObj.length = remain;
	dropObj.selectedIndex = 0;
}
//## Drop Down Object ##

//## Radio Object ##
function isClickRadio(radioObj) {
	var i;
	for(i = 0; i < radioObj.length; i++) {
		if (radioObj[i].checked == true)
			return true;
	}
	return false;
}

function markRadioValue(radioObj, data) {
	for (i=0; i<radioObj.length; i++) {
		if (data == radioObj[i].value)
			radioObj[i].checked = true;
	}
}

function getRadioValue(radioObj) {
	var i;
	for(i=0; i<radioObj.length; i++) {
		if(radioObj[i].checked == true)
			return radioObj[i].value;
	}
	return "";
}
//## Radio Object ##

//## Check Box Object ##
function isClickCheckBox(frm, start, num, skip) {
	var result, isChecked;
	//var end = parseInt(num) * parseInt(skip);
	var end = num;
	for (i = start; i < end; i+=skip) {
		if (frm.elements[i].checked) {
			isChecked = true;
			i = end++;
		}
		else{
			isChecked = false;
		}
	}
	return isChecked;
}

function isClickCheckBox2(frm,chckBox,chckBox2) {
	var check;
	for(i = 0; i < frm.length; i++){
		if ((frm.elements[i].name.toUpperCase() == chckBox.toUpperCase()||frm.elements[i].name.toUpperCase() == chckBox2.toUpperCase()) && !frm.elements[i].disabled&&frm.elements[i].type.toUpperCase() == "CHECKBOX")
		if(frm.elements[i].checked == true){
			check=true;
			break;
		}
	}
	return check;
}

function markCheckValue(radioObj, data) {
		if (data == radioObj.value)
			radioObj.checked = true;
}

function setCheckAllCheckbox(frm, chkObj, chkAllObj, start, num, skip) {
	var count = 0;
	var chkCount = 0;
	//var end = num * skip;
	var end = num;

	if (chkObj.checked) {	
		for (i = start; i < end; i+=skip) {
			count++;
			if (frm.elements[i].checked && !frm.elements[i].disabled) {
				chkCount++;
			}
		}
		
		if (count == chkCount)
			chkAllObj.checked = true;
		else
			chkAllObj.checked = false;

	} else {
		chkAllObj.checked = false;
	}
}

/*created: wjs. checkAll position in bottom page*/
function setCheckAllCheckbox2(frm, chkObj, chkAllObj, start, num, skip) {
	var count = 0;
	var chkCount = 0;
	//var end = num * skip;
	var end = num;

	if (chkObj.checked) {	
		for (i = start; i < end; i+=skip) {
			if(frm.elements[i].name.toUpperCase() == "CHECKALL")
				break;
			count++;
			if (frm.elements[i].checked && !frm.elements[i].disabled) {
				chkCount++;
			}
		}
		
		if (count == chkCount)
			chkAllObj.checked = true;
		else
			chkAllObj.checked = false;

	} else {
		chkAllObj.checked = false;
	}
}

/*function selectAllCheckbox(frm) {
	for(i = 0; i < frm.length; i++) {
		if (frm.elements[i].name!=null && frm.elements[i].name.toUpperCase() != "CHECKALL" && !frm.elements[i].disabled&&frm.elements[i].type.toUpperCase() == "CHECKBOX") {
				frm.elements[i].checked = frm.checkAll.checked;
		}
	}
}*/

function selectAllCheckbox(frm, chkAllObj, start, num, skip) {
	//var end = num * skip;
	var end = num;

	for (i = start; i < end; i+=skip) {
		if (frm.elements[i].name!=null && frm.elements[i].name.toUpperCase() != "CHECKALL" && !frm.elements[i].disabled) {
				frm.elements[i].checked = chkAllObj.checked;
		}
	}
}

function selectAllCheckbox2(frm,checkAll,chckBox,chckBox2) {
	for(i = 0; i < frm.length; i++){
		if ((frm.elements[i].name.toUpperCase() == chckBox.toUpperCase()||frm.elements[i].name.toUpperCase() == chckBox2.toUpperCase()) && !frm.elements[i].disabled&&frm.elements[i].type.toUpperCase() == "CHECKBOX") {
				frm.elements[i].checked = frm.elements[checkAll].checked;
		}
	}
}
/*created: wjs. checkAll position in bottom page*/
function selectAllCheckbox3(frm, chkAllObj, start, num, skip) {
	//var end = num * skip;
	var end = num;
	for (i = start; i < end; i+=skip) {
		if(frm.elements[i].type.toUpperCase() == "CHECKBOX"){
			if(frm.elements[i].name.toUpperCase() == "CHECKALL"){
				break;
			}
			else if (frm.elements[i].name!=null && frm.elements[i].name.toUpperCase() != "CHECKALL" && !frm.elements[i].disabled) {
				frm.elements[i].checked = chkAllObj.checked;
			}
		}
	}
}

function checkCheckAll(frm,me){
	var check;
	if (me.checked == false){
		frm.checkAll.checked = false;
	}
	else{
		for(i = 0; i < frm.length; i++){
		if(frm.elements[i].name!=null && frm.elements[i].name.toUpperCase() != "CHECKALL" && !frm.elements[i].disabled&&frm.elements[i].type.toUpperCase() == "CHECKBOX")
			if(frm.elements[i].checked == true){
				check=true;
			}
			else{
				check=false;
				break;
			}
		}
		if(check){
			frm.checkAll.checked = true;
		}
	}
}

function checkCheckAll2(frm,me,checkAll,chckBox,chckBox2) {
	var check;
	if (me.checked == false){
		frm.elements[checkAll].checked = false;
	}
	else{
		for(i = 0; i < frm.length; i++){
		if ((frm.elements[i].name.toUpperCase() == chckBox.toUpperCase()||frm.elements[i].name.toUpperCase() == chckBox2.toUpperCase()) && !frm.elements[i].disabled&&frm.elements[i].type.toUpperCase() == "CHECKBOX")
			if(frm.elements[i].checked == true){
				check=true;
			}
			else{
				check=false;
				break;
			}
		}
		if(check){
			frm.elements[checkAll].checked = true;
		}
	}
}
//## Check Box Object ##

function hidestatus() {
	window.status = " ";
	return true;
}
/*if (document.layers)
	document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);

document.onmouseover = hidestatus;
document.onmouseout = hidestatus;
*/
function goToPage(colIndex, currentPage) {
  document.frmSearch.hidCurr.value = currentPage;
  document.frmSearch.submit();
}

function goToPage2(page, currentPage) {
  document.frmDetail.hidCurr2.value = currentPage;
  document.frmDetail.action=page;
  document.frmDetail.submit();
}

function disableRightClick(e) { 
  /*var message = "Right click disabled"; 
  
  if(!document.rightClickDisabled) // initialize 
  { 
    if(document.layers) 
    { 
      document.captureEvents(Event.MOUSEDOWN); 
      document.onmousedown = disableRightClick; 
    } 
    else document.oncontextmenu = disableRightClick; 
    return document.rightClickDisabled = true; 
  } 
  if(document.layers || (document.getElementById && !document.all)) 
  { 
    if (e.which==2||e.which==3) 
    { 
      return false; 
    } 
  } 
  else 
  { 
    return false; 
  } */
} 

n = (document.layers) ? 1 : 0; 
ie = (document.all) ? 1 : 0; 
var check = false; 

function checkPN() { 
        check = false; 
        document.onkeypress = keyPress; 
        document.onkeydown = keyDown; 
        document.onkeyup = keyUp; 
        event.keyCode=0; 
        event.returnValue=false; 
        event.cancelBubble=true; 
        if (n) { 
                document.captureEvents(Event.keydown | Event.keyup | Event.keypress); 
        } 
} 

function keyPress(e) { 
        if (n) { 
                var nKey = e.which; 
                var ieKey = 0; 
        } 
        if (ie) { 
                var ieKey = event.keyCode; 
                var nKey = 0; 
        } 
        if ((nKey == 110 || ieKey == 17||ieKey == 78||ieKey == 80) && event.ctrlKey && !check) {   
                event.keyCode=0; 
                check=true; 
                press(); 
				event.keyCode=0; 
				event.returnValue=false; 
				event.cancelBubble=true; 
        } 
} 

function keyDown(e) { 
        if (n) { 
                var nKey = e.which; 
                var ieKey = 0; 
        } 
        if (ie) { 
                var ieKey = event.keyCode; 
                var nKey = 0; 
        } 
        if ((nKey == 110 || ieKey == 17||ieKey == 78||ieKey == 80) && event.ctrlKey && !check) {   
				event.keyCode=0; 
				check=true; 
				press(); 
				event.keyCode=0; 
				event.returnValue=false; 
				event.cancelBubble=true;
        } 
} 

function keyUp(e) { 
        if (n) { 
                var nKey = e.which; 
                var ieKey = 0; 
        } 
        if (ie) { 
                var ieKey = event.keyCode; 
                var nKey = 0; 
        } 
        if ((nKey == 110 || ieKey == 17 || nKey == 112 || ieKey == 78 || ieKey == 80) && event.ctrlKey){ 
                event.keyCode=0; 
                check=false; 
        event.keyCode=0; 
        event.returnValue=false; 
        event.cancelBubble=true; 
        } 
} 

function press() { 
        if (check) { 
                check=false; 
   } 
} 	
	
function fillChar( txt, ch, position, length) {
    	var rtn = txt;
   		if (!isEmpty(txt) ) {
        	var txtlen = txt.length;
        	if (length > txtlen) {  
          	for(var i = 0; i < (length - txtlen) ; i++) {
						if(position == 0)
              				rtn = ch + rtn;
						else if(position == 1)
							rtn = rtn + ch;
            			else
            				rtn = rtn + ch;
          	}
        	}else if (length < txtlen) {
			  rtn = txt.substring(0,length);
        	}
    	}else {
     	 rtn = "";
      	for(var j = 0; j < length ; j++) {
              rtn = rtn + ch;
      	}
    }
    return rtn; 
 }

/////////////////////////////////// calendar ////////////////////////////////////
function genCalendar(field) {
	var cal = new calendar1(eval("document."+field));
	cal.popup();
}
function genCalendar2(field) {
	var cal = new calendar2(eval("document."+field));
	cal.popup();
}
function genCalendar3(field) {
	var cal = new calendar2(eval("document."+field));
	cal.popup();
}
/// calendar
// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function calendar1(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup1;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}


function calendar2(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup2;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function calendar3(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup3;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}
//var obj_calwindow;
function cal_popup1 (str_datetime) {
	//this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	this.dt_current = this.prs_tsmp(str_datetime);
	if (!this.dt_current) return;	
	var top_w = 200;
	var left_w = 200;
	if(this.obj_calwindow!=null){
		this.obj_calwindow.location='../../js/clndr/clndr.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id;
	}else{
		this.obj_calwindow = window.open(
			'../../js/clndr/clndr.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
			'Calendar', 'width=178,height='+(this.time_comp ? 210 : 190)+
			',status=no,resizable=no,top='+top_w+',left='+left_w+',dependent=yes,alwaysRaised=yes'
		);
	}
	this.obj_calwindow.opener = window;
	this.obj_calwindow.focus();
}

//var obj_calwindow;
function cal_popup2 (str_datetime) {
	//this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	this.dt_current = this.prs_tsmp(str_datetime);
	if (!this.dt_current) return;	
	var top_w = 200;
	var left_w = 200;
	if(this.obj_calwindow!=null){
		this.obj_calwindow.location='../../../js/clndr/clndr.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id;
	}else{
		this.obj_calwindow = window.open(
			'../../../js/clndr/clndr.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
			'Calendar', 'width=178,height='+(this.time_comp ? 210 : 190)+
			',status=no,resizable=no,top='+top_w+',left='+left_w+',dependent=yes,alwaysRaised=yes'
		);
	}
	this.obj_calwindow.opener = window;
	this.obj_calwindow.focus();
}
function cal_popup3 (str_datetime) {
	
	//this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	this.dt_current = this.prs_tsmp(str_datetime);
	if (!this.dt_current) return;	
	var top_w = 200;
	var left_w = 200;
	if(this.obj_calwindow!=null){
		this.obj_calwindow.location='../../js/clndr/clndr2.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id;
	}else{
		this.obj_calwindow = window.open(
			'../../js/clndr/clndr2.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
			'Calendar', 'width=178,height='+(this.time_comp ? 210 : 190)+
			',status=no,resizable=no,top='+top_w+',left='+left_w+',dependent=yes,alwaysRaised=yes'
		);
	}
	this.obj_calwindow.opener = window;
	this.obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp1 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date1 (dt_datetime) {
	return (
		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
		+ (dt_datetime.getFullYear()+543)
	);
}
// time generating function
function cal_gen_time1 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp1 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date1 (str_date) {

	var arr_date = str_date.split('/');

	if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd-mm-yyyy.");
	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[1]-1);
	 
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);

	var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
	dt_date.setDate(arr_date[0]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time1 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0]))
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

function IsValidIdNr(objId) {
	var IntTotal=0;
	var IntCheckDigit;
	var IntDigitThirteen ;
	var CharDigit ;
	var N = 13;
	var i = 1;
	var IntTemp ;
	if(objId.value == "") {
		return true
	}else if(objId.length < 13 || objId.length > 13){
		return false
	}else{
		IntDigitThirteen = parseInt(objId.substr(12, 1))
	   
		for( i = 1 ; i <= 12; i++){
			IntTotal = IntTotal + (parseInt(objId.substr(i-1, 1)) * N);
			N = N - 1;
		}
		IntTemp = IntTotal % 11
		//alert(IntTotal);
		switch ( IntTemp){
			case 0 : IntCheckDigit = 1;break;
			case 1 : IntCheckDigit = 0;break;
			default : IntCheckDigit = 11 - IntTemp;break;
		}
		//alert(IntCheckDigit);
		if (IntDigitThirteen != IntCheckDigit){
			return false
		}
		return true
	}
}

function openLoadding()
{
	var loading = document.getElementById("loading");
	loading.style.width = screen.width-20;
	loading.style.top = screen.height/2-183;
	loading.style.visibility = "visible";
}
function closeLoadding()
{
	var loading = document.getElementById("loading");
	loading.style.visibility = "hidden";
	document.body.style.cursor = "auto";
}





