
var currencyDispNormal = "0"
var wasError = false;
var lastErrorTime = new Date;
lastErrorTime = new Date;

var arrLabeles = new Object;
var arrDisabledFields = new Object;
var arrAlwaysDisabledFields = new Object;
var arrNotNullFields = new Object;
var arrNotNullFields_defaulted = new Object;
var arrFieldsToUnset = new Object;
var arrMaxLen = new Object;
var arrTypes = new Object;
var formSubmitted = false;

function formatNumber(value, lng) {
	var comma, dot;
	if (currencyDispNormal != 0) {
		comma = ".";
		dot = ",";
	}
	else {
		comma = ",";
		dot = ".";
	}
	
	var r = "";
	var otherString;
	var insertedChar = 0;
	
	// . position
	value = "" + value;
	i = value.indexOf(".");
	if (i < 0) {
		i = value.length;
		otherString = "";
	}
	else {
		otherString = value.substr(i + 1, value.length);
		otherString = otherString;
	}
	for (i--; i >= 0; i--) {
		if (insertedChar == 3) {
			r = dot + r;
			insertedChar = 0;
		}
		r = "" + value.charAt(i) + r;
		insertedChar++;
	}

	if (lng > 0) {
		// otherString
		
		for (i = 0; i < lng; i++) {
			otherString = otherString + "0"
		}
		otherString = otherString.substr(0, lng)
		otherString = comma + otherString
	}
	else {
		if (otherString != "") otherString = comma + otherString;
	}
	return r + otherString;
}

function standard_doResetPassword(fieldName) {
	var f = document.forms[0];
	
	if (typeof("doResetPassword") == "function") {
		doResetPassword(fieldName);
		
		return ;
	}
	
	if (typeof(doCheck)  == "function") {
		var h = doCheck();
		if (!h) return ;
	}
	else {
		if (!standardDoCheck()) return ;
	}
	
	if (!confirm(allIzcmJsMessages["MODIFY_PASSWORD"])) return ;
	
	var oldAction = f.action;
	f.action += "?toSubmit=save&changePassword=" + fieldName;
	submitForm(0);
	f.action = oldAction;
	formSubmitted = true;
}
function submitForm(formToSubmit) {
	var el, idx;
	var oldValues = new Object;

	// change and save format
	for (idx = 0; idx < document.forms[formToSubmit].length; idx++) {
		el = document.forms[formToSubmit].elements[idx].name;

		if (arrTypes[el] == "htmlEditor") continue;
		if (el == "") continue;
		
		if (
			(document.forms[formToSubmit].elements[el].type != "text") 
			//|| (document.forms[formToSubmit].elements[el].type == "hidden")
		) continue;
		oldValues[el] = document.forms[formToSubmit].elements[el].value;
		if (arrTypes[el] == 'numeric') {
			document.forms[formToSubmit].elements[el].value = 
				convertToInt(oldValues[el]);
		}
		else if (arrTypes[el] == 'float') {
			document.forms[formToSubmit].elements[el].value = 
				convertToFloat(oldValues[el]);
		}
	}

	document.forms[formToSubmit].submit();
	
	// restore old values
	for (el in oldValues) {
		document.forms[formToSubmit].elements[el].value = oldValues[el];
	}
}
function nvl(val, defval) {
	if ((typeof(val) != 'undefined') && (val != ''))
		return val;
	else
		return defval;
}

function showError(msg) { 
	if (!toCheckError()) return false;
	lastErrorTime = new Date;
	alert(msg);
	lastErrorTime = new Date;
}

function toCheckError() {
	var currTime = new Date;
	currTime = currTime.getTime ();
	var lastErrorMillisec = lastErrorTime.getTime ();
	
	if (currTime - lastErrorMillisec < 500) return false;
	return true;
}
function convertToInt(value) {
	if (value == "") return "";
	
	var n = value;
	if (n == "") return true;
	if (currencyDispNormal == 0) {
		n = n.replace(/\./g,"");
		n = n.replace(/\,/g,".");
	}
	else {
		n = n.replace(/\,/g,"");
	}
	
	var h = parseInt(n);
	if (' ' + h != ' ' + n) {
		return "NaN";
	}
	
	return h;
}
function ctrlInt(obj, toShowError, def) {
	if (!toCheckError()) return false;
	
	if (obj.value == "") return true;

	var h = convertToInt(obj.value);
	if (h == "NaN") {
		var lMsg = allIzcmJsMessages["NO_NUMBER"];
		
		if (toShowError) {
			obj.value = def;
			wasError = true;
		
			showError(lMsg);
			obj.focus();
		}

		return lMsg;
	}
	
	obj.value = formatNumber(h, 0);
			
	return true;
}
function convertToFloat(value) {
	if (value == "") return "";
	
	var n = value;
	if (n == "") return true;
	if (currencyDispNormal == 0) {
		n = n.replace(/\./g,"");
		n = n.replace(/\,/g,".");
	}
	else {
		n = n.replace(/\,/g,"");
	}
	
	var h = parseFloat(n);
	if (h != n) return "NaN";
	
	return h;
}
function ctrlFloat(obj, toShowError, def, len) {
	if (!toCheckError()) return false;
	
	if (obj.value == "") return true;

	var h = convertToFloat(obj.value);
	if (h == "NaN") {
		var lMsg = allIzcmJsMessages["NO_FLOAT"]
		if (toShowError) {
			wasError = true;
		
			showError(lMsg);
			obj.value = def;
			obj.focus();
		}
						
		return lMsg;
	} 
	
	obj.value = formatNumber(h, len);
			
	return true;
}

function DateCtrl(dateObj, toShowError, dataDef) {
	if (!toCheckError()) return false;

	dateStr = dateObj.value;
	if (dateStr == "") return true;
	
   // chack a date of format dd/mm/yyyy
   datePattern = /^\d{2}(\/|\-|\.| )?\d{2}(\/|\-|\.| )?\d{4}$/;
   if (!datePattern.test(dateStr)) {
		var lMsg = allIzcmJsMessages["NO_DATE"];
		if (toShowError) {
			dateObj.value = dataDef;
			wasError = true;	
		
			showError(lMsg);
			dateObj.focus();		
		}
      return lMsg;
   }
   
   dateArr = dateStr.split(/\//);
   if (dateArr.length = 3) {
      dateArr[0] = dateStr.substr(0, 2);
      dateArr[1] = dateStr.substr(3, 2);
    	dateArr[2] = dateStr.substr(6, 4);
   }
   
   int_date = new Date(dateArr[1] + "/" + dateArr[0] + "/" + dateArr[2]);
   day = int_date.getDate();
   month = int_date.getMonth()+1;
   year = int_date.getFullYear();

   if (parseInt(dateArr[0], 10) != day 
      || parseInt(dateArr[1], 10) != month 
	   || parseInt(dateArr[2], 10) != year
	) {
		var lMsg2 = allIzcmJsMessages["NO_DATE"];
		if (toShowError) {
			dateObj.value = dataDef;
			wasError = true;			
	
			showError(lMsg2);
			dateObj.focus();
		}
			 
		return lMsg2;
   }
	
	return true;
}

function checkDate(stratDate, stratTime, endDate, endTime) {
   var j = 0;
   var dateArr = stratDate.split(/\/|\-|\.| /);
   var dateArrF = dfin.split(/\/|\-|\.| /);
   var oraArr = stratTime.split(/\./);
   var oraArrF = endTime.split(/\./);
   x = new Date(dateArr[2],dateArr[1]-1,dateArr[0],oraArr[0],oraArr[1]);
   y = new Date(dateArrF[2],dateArrF[1]-1,dateArrF[0],oraArrF[0],oraArrF[1]);
   z = new Date();
   if (x >= y) {
   	return false;
   }

	return true;
}

function checkLen(obj, leng, toShowError) {
	var strLen = obj.value.length;
	if (strLen > leng) {
		var lMsg = allIzcmJsMessages["TOO_LONG"] + "(" + strLen+ "/" + leng + ")";
		
		if (toShowError) {
			showError(lMsg);
		}
		return lMsg;
	}
	
	return true; 
}

function checkEmail(obj, toShowError) {
	if (obj.value == "") return true;

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (!toCheckError()) return false;
	
	if (!filter.test(obj.value)) {
		var lMsg = allIzcmJsMessages["NO_EMAIL"];
		if (toShowError) {
			showError(lMsg);
			obj.focus();
		}
		
		return lMsg;	
	}
	return true;
}
	
function setState(f, field, flag) {
	if (arrAlwaysDisabledFields[field] != null) {
		if (arrAlwaysDisabledFields[field]) {
			//alert(field);
			flag = true;
		}
	}
	var el = "";
	var label = "";
	el = f.elements[field];

	if (el == null) {
		return ;
	}
	
	// change color
	if (el.style != null) {
		if (flag) {
			el.className = "inputDisabled";
			// el.style.borderColor = "#808080";
		}
		else {
			el.className = "boxinput";
			// el.style.borderColor = "#808080";
		}
	}	
	
	if (!flag) el.disabled = false;
	else {
		el.disabled = true;
	}

	// if label exists change
	label = document.getElementById(field+"_L");
	if (label) {
		if (!flag) label.style.color = "#111185";
		else label.style.color = "#D6E0F5";
	}		
}

function setStateFromArray(f, arr, flag) {
	for (el in arr) {
		setState(f, arr[el], flag);	
	}	
}

function setStateFromArray2(f, arr) {
	for (el in arr) {
		setState(f, el, arr[el]);	
	}	
}

function setCheckNullFromArray2(f, arr) {
	for (el in arr) {
		setState(f, el, arr[el]);	
	}	
}
/* arrLabel is the array of all mandatory fields. The keys are the elements name, 
	and the values are the labels.
	When a label is empty the check is not performed */
function checkForNull(f, arr, arrDefaulted, arrLabel) {
	var f = document.forms[0];
	var msg = "";
	var num = 0;
	
	for (el in arr) {
		// do we need to checkj ?
		if (arr[el] != "") {
			// does the fields exists ?
			if (typeof (f.elements[el]) == "undefined") {
				alert(el + " undefined field!");
				return false;
			}
			else {
				if (f.elements[el].value == "") {
					if (f.elements[el].disabled == false) {
						var toPrintMsg = true
						if (arrDefaulted != null) {
							toPrintMsg = 
								arrDefaulted[el] == null || 
								arrDefaulted[el] == "";
						}
						if (toPrintMsg) {
							if (num < 10) {
								msg += "\n - " + arrLabel[el];
							}
						}
					}
				}
			}
		}
	}	
	
	if (msg != "") {
		msg = allIzcmJsMessages["NO_VALUE"] + ":" + msg;
		if (num > 10) {
			msg = msg + "\n..."
		}
		showError(msg);
		return false;
	}
	
	return true;
}

function checkForLen(f, arr, arrLabel) {
	var f = document.forms[0];
	var msg = "";
	var num = 0;
	
	for (el in arr) {
		// do we need to checkj ?
		if (arr[el] != "") {
			// does the fields exists ?
			if (typeof (f.elements[el]) == "undefined") {
				alert(el + " undefined field.");
				return false;
			}
			else {
				if (f.elements[el].value.length > arr[el]) {
					var toPrintMsg = true
					if (toPrintMsg) {
						if (num < 10) {
							msg += "\n - " + arrLabel[el];
						}
					}
				}
			}
		}
	}	
	
	if (msg != "") {
		msg = allIzcmJsMessages["TOO_LONG"] + ":" + msg;
		if (num > 10) {
			msg = msg + "\n..."
		}
		showError(msg);
		return false;
	}
	
	return true;
}
function checkForTypes(f, arr, arrLabel) {
	var f = document.forms[0];
	var msg = "";
	var def = "";
	
	for (el in arr) {
		if (typeof(f.elements[el]) == "undefined") continue;	// calculated fields
		if (f.elements[el].type == "hidden") continue;
		
		if (f.elements[el].value == "") continue;
		
		if (arr[el] == "numeric") {
			r = ctrlInt(f.elements[el], false, def);
			if (typeof(r) == "string") {
				showError(arrLabel[el] + ": " + r);
				return false;
			}
		}
		
		if (arr[el] == "float") {
			r = ctrlFloat(f.elements[el], false, def, -1);
			if (typeof(r) == "string") {
				showError(arrLabel[el] + ": " + r);
				return false;
			}
		}
		
		if (arr[el] == "date") {
			r = DateCtrl(f.elements[el], false, def);
			if (typeof(r) == "string") {
				showError(arrLabel[el] + ": " + r);
				return false;
			}
		}
		
		if (arr[el] == "email") {
			r = ctrlEmail(f.elements[el], false, def);
			if (typeof(r) == "string") {
				showError(arrLabel[el] + ": " + r);
				return false;
			}
		}		
	}
	
	return true;
}

function standardDoCheck() {
	var f = document.forms[0];
	
	if (typeof(doDynamicFieldHandling) == "function") {
		if (doDynamicFieldHandling(null) == false) return false;
	}
	
	if (!checkForNull(f, arrNotNullFields, arrNotNullFields_defaulted, arrLabeles)) return false;
	if (!checkForTypes(f, arrTypes, arrLabeles)) return false;
	if (!checkForLen(f, arrMaxLen, arrLabeles)) return false;
	
	return true;
}
function enableAllFields(f) {
	for (var i = 0; i < f.elements.length; i++) {
		f.elements[i].disabled = false;
	}
}

function handle_arrFieldsToUnset() {
	var f = document.forms[0];
	
	for (el in arrFieldsToUnset) {
		if (!arrFieldsToUnset[el]) continue;
		if (typeof(f.elements[el]) == "undefined") {
			alert("Element not found " + el);
		}
		if (typeof(f.elements[el]) == "checkbox") f.elements[el].checked = false;
		else f.elements[el].value = "";
	}
}

function standardDoSubmit() {
	var currTime = new Date;
	currTime = currTime.getTime ();
	var lastErrorMillisec = lastErrorTime.getTime ();
	
	if (currTime - lastErrorMillisec < 500) return ;
	if (typeof(doSubmit) == "function") {
		doSubmit();
		return ;
	}

	var f = document.forms[0];

	// before check specific function ?
	if (typeof(beforeCheck)  == "function") beforeCheck();
	
	// specifick check function
	if (typeof(doCheck)  == "function") {
		var h = doCheck();
		if (!h) return ;
	}
	else {
		if (!standardDoCheck()) return ;
	}
	
	// after check specific function ?
	if (typeof(afterCheck)  == "function") {
		if (!afterCheck()) return ;
	}
	
	handle_arrFieldsToUnset();
	enableAllFields(f);
	var oldAction = f.action;
	f.action += "?toSubmit=save";
	// f.submit();
	submitForm(0);
	f.action = oldAction;
	formSubmitted = true;
}

function standardDoReset() {
	var f = document.forms[0];

	if (typeof(doReset) == "function") doReset();
	else {
		if (typeof(f.elements["isRefreshed"]) != "undefined") {
			f.elements["isRefreshed"].value = "";
		}
		f.submit();
	}
}

function _standardDoReload(anchorid) {
	if (formSubmitted) return ;
	var f = document.forms[0];
	
	if (typeof(doReload) == "function") doReload(anchorid);
	else {
		if (typeof(anchorid) != "undefined") {
			f.action += "#anchor_" + anchorid;
		}
		// activate all fields (canModify = false)
		for (var i = 0; i < document.forms[0].elements.length; i++) {
			document.forms[0].elements[i].disabled = false;
		}
		// f.submit();
		submitForm(0);		
	}	
}
function standardDoReload(anchorid) {
	setTimeout("_standardDoReload('" + anchorid + "')", 500);
}

function standardDoOnLoad() {
	var f = document.forms[0];

	if (typeof(doOnload) == "function") 
		doOnload();
	
}
function openPopupMaximized(strURL){
	window.open(strURL,'','top=0,left=0,width=' + screen.width + ', height=' + screen.height + ',menubar=0,resizable=yes,scrollbars=yes');
}
function openPopupSimple(strURL){
	window.open(strURL,'','top=10,left=10,width=650, height=400,menubar=0,resizable=yes,scrollbars=yes');
}

function openPopup(strURL,t,l,w,h){
	window.open(strURL,'','top='+t+',left='+l+',width='+w+', height='+h+',menubar=0,resizable=yes,scrollbars=yes');
}

function openPopupWithName(strURL,name, t,l,w,h){
	window.open(strURL,name,'top='+t+',left='+l+',width='+w+', height='+h+',menubar=0,resizable=yes,scrollbars=yes');
}

function standardDoClose() {
	var f = document.forms[0];
	
	if (typeof(doReload) == "function") doReload();
	else {
		self.opener.standardDoReload();
		window.close();
	}	
}

function doStandardConfirm(message) {
	if (confirm(message + "\n" + allIzcmJsMessages["CONTINUE"] + " ?")) {
		document.forms[0].elements["_confirmed"].value = 1
		standardDoSubmit();
	}
}

/*
function setup_hidden(w, f, objName, objValue) {
	var hdnObj;
	hdnObj = w.document.createElement("INPUT");
	hdnObj.type = "hidden";
	f.appendChild(hdnObj);
	hdnObj.name = objName;
	hdnObj.value = objValue;
}
*/

function exist(o) {
	return o != undefined;
}

function setup_hidden(w, f, objName, objValue) {
	var fName = f.name;
	var i = 0;
	
	for (i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name == objName) break;
	}

	if (i < f.elements.length) {
		f.elements[i].value = objValue;
	}
	else {
		var hdnObj;
		hdnObj = w.document.createElement("INPUT");
		hdnObj.type = "hidden";
		hdnObj.name = objName;
		hdnObj.value = objValue;
		f.appendChild(hdnObj);
	}
}

function standardDynamicFieldHandling(obj) {
	if (typeof(doDynamicFieldHandling) == "function") doDynamicFieldHandling(obj);
}

function openStandardSearch(izcmId, additionalParam) {
	openPopupWithName(
		"../lib/izcm_standardSearch.asp?IZCMID=" + izcmId + additionalParam ,
		"izcmsearch", 100,100,600,500)
}
var P_OP_SET_READALLOW		= 1;
var P_OP_UNSET_READALLOW		= 2;
var P_OP_IF_SET_READALLOW	= 4;
var P_OP_IF_UNSET_READALLOW	= 8;
//var P_OP_UNSET_READALLOW		= 16;
var P_OP_SET_NOTNULL			= 32;
var P_OP_UNSET_NOTNULL		= 64;
var P_OP_IF_SET_NOTNULL		= 128;
var P_OP_IF_UNSET_NOTNULL	= 256;
var P_OP_SET_TONULL			= 512;
var P_OP_UNSET_TONULL		= 1024;
var P_OP_IF_SET_TONULL			= 2048;
var P_OP_IF_UNSET_TONULL		= 4096;
var P_OP_SET_VISIBLE		= 8192;
var P_OP_UNSET_VISIBLE		= 16384;
var P_OP_IF_SET_VISIBLE		= 32768;
var P_OP_IF_UNSET_VISIBLE	= 65536;
function isTrue(v) {
	if (v == "") return false;
	if (v == false) return false;
	return true;
}

function isFalse(v) {
	return !isTrue(v);
}

function setValueToField(fieldName, value) {
	var f = document.forms[0];
	var e = f.elements[fieldName];
	
	if (e.type == "checkbox") {
		if (value == "1") e.checked = true;
		else e.checked = false;
	}
	else {
		e.value = value;
	}
}

function returnFieldValue(fieldName) {
	var f = document.forms[0];
	var e = f.elements[fieldName];
	
	if (typeof(e) == "undefined") {
		alert("unknown field: " + fieldName);
		return ;
	}
	
	if (e.type == "checkbox") {
		if (e.checked) return true;
		else return false;
	}
	else {
		return e.value;
	}
}

function setFiledProperties(fieldNames, operation, toSet) {
	var f = document.forms[0];
	var fieldName;
	
	if (typeof(fieldNames) == "string") {
		fieldName = fieldNames;		
		fieldNames = new Array();
		fieldNames[0] = fieldName;
	}
	
	var field;
	
	for (var i = 0; i < fieldNames.length; i++) {
		fieldName = fieldNames[i];
		field = f.elements[fieldName];

		// read only
		if (operation & P_OP_SET_READALLOW) {
			arrDisabledFields[fieldName] = !toSet;
			setState(f, fieldName, !toSet);
		}
	
		if (operation & P_OP_UNSET_READALLOW) {
			arrDisabledFields[fieldName] = toSet;
			setState(f, fieldName, toSet);
		}
		
		if ((operation & P_OP_IF_SET_READALLOW) && (toSet)) {
			arrDisabledFields[fieldName] = !toSet;
			setState(f, fieldName, !toSet);
		}
	
		if ((operation & P_OP_IF_UNSET_READALLOW) && (toSet)) {
			arrDisabledFields[fieldName] = toSet;
			setState(f, fieldName, toSet);
		}

		// to null
		if (operation & P_OP_SET_NOTNULL) {
			if (toSet) arrNotNullFields[fieldName] = arrLabeles[fieldName];
			else arrNotNullFields[fieldName] = "";
		}
	
		if (operation & P_OP_UNSET_NOTNULL) {
			if (!toSet) arrNotNullFields[fieldName] = arrLabeles[fieldName];
			else arrNotNullFields[fieldName] = "";
		}
		
		if ((operation & P_OP_IF_SET_NOTNULL) && (toSet)) {
			arrNotNullFields[fieldName] = arrLabeles[fieldName];
		}
	
		if ((operation & P_OP_IF_UNSET_NOTNULL) && (toSet))  {
			arrNotNullFields[fieldName] = "";
		}
	
		// to zero
		if (operation & P_OP_SET_TONULL) {
			if (toSet) {
				arrFieldsToUnset[fieldName] = true;
			}
			else arrFieldsToUnset[fieldName] = false;			 
		}
	
		if (operation & P_OP_UNSET_TONULL) {
			if (toSet) {
				arrFieldsToUnset[fieldName] = false;
			}
			else arrFieldsToUnset[fieldName] = true;			 
		}
		
		if ((operation & P_OP_IF_SET_TONULL) && (toSet)) {
			arrFieldsToUnset[fieldName] = true;
		}
	
		if ((operation & P_OP_IF_UNSET_TONULL) && (toSet)) {
			arrFieldsToUnset[fieldName] = false;			 
		}
		
		// to visible
		if (field.type != "hidden") {

			var elh = document.getElementById("_el_head_" + fieldName);
			var eld = document.getElementById("_el_data_" + fieldName);
			// if (!eld) alert("missing field _el_data_" + fieldName);
			// if (!elh) alert("missing field _el_head_" + fieldName);
		
			if (operation & P_OP_SET_VISIBLE) {
				if (toSet) {
					if (elh) elh.style.display = "";
					if (eld) eld.style.display = "";
				}
				else {
					if (elh) elh.style.display = "none"
					if (eld) eld.style.display = "none"
				}
			}
	
			if (operation & P_OP_UNSET_VISIBLE) {
				if (toSet) {
					if (elh) elh.style.display = "none";
					if (eld) eld.style.display = "none";
				}
				else {
					if (elh) elh.style.display = "";
					if (eld) eld.style.display = "";
				}
			}
		
			if ((operation & P_OP_IF_SET_VISIBLE) && (toSet)) {
				if (elh) elh.style.display = "";
				if (eld) eld.style.display = "";
			}
	
			if ((operation & P_OP_IF_UNSET_VISIBLE) && (toSet)) {
				if (elh) elh.style.display = "none";
				if (eld) eld.style.display = "none";
			}
		}
	}
}
// -------------------------- custmo controls
function doBandCheck() {
	return 1;
	
	// no check

	var f = document.forms[0];
	
	for (var i = 1; i <= 4; i++) {
		if 
		(
			(
				(f.elements["B" + i + "SCCM"].value != "") ||
				(f.elements["B" + i + "OCCM"].value != "") 
			) && 
			(f.elements["B" + i + "VRPM"].value == "")
		) {
			alert(allIzcmJsMessages["NO_CORRECT_BAND"]);
			return 0; 
		}
		if 
		(
			(
				(f.elements["B" + i + "SCCC"].value != "") ||
				(f.elements["B" + i + "OCCC"].value != "") 
			) && 
			(f.elements["B" + i + "VRPC"].value == "")
		) {
			alert(allIzcmJsMessages["NO_CORRECT_BAND"]);
			return 0;
		}
	}
	
	return 1;
}

function openHelpForField(id) {
	openPopupWithName("../lib/izcm_helpField.asp?IZCMID=" + id,"fieldHelp", 100,100,400,400);
}

function openHelpForPage(id) {
	openPopupWithName("../help/izcm_helpPage.asp?code=" + id,"fieldHelp", 100,100,400,400);
}

function uploadfile(name) {
	window.open(
		"../updownload/uploadfile.asp?fieldName=" + name
		,"UploadFile"
		,"width=700,height=550,toolbar=no,menubar=no,title=yes,scrollbars=1,resizable=1"
	).focus();
}

function dowloandFile(name) {
	var f = document.forms[0];
	
	if (f.elements[name].value == "") return ;

	if (f.elements[name+ "_TMP"].value != "") {
		self.location.href = "../updownload/download.asp" +
			"?source=" + f.elements[name+ "_TMP"].value +
			"&FileName=" + f.elements[name].value +
			"&isOrig=0";
	}
	else {
		self.location.href = "../updownload/download.asp" +
			"?source=" + f.elements[name+ "_PATH"].value +
			"&FileName=" + f.elements[name].value +
			"&isOrig=1";
	}
}

function resetFile(name) {
	var f = document.forms[0];
	
	f.elements[name].value = "";
	f.elements[name + "_TMP"].value = "";
}

function removeFile(name) {
	var f = document.forms[0];
	
	resetFile(name);
	
	// insert a string that con not be used
	f.elements[name + "_TMP"].value = "@*delete_file*@";
}
function charToDate(dateStr) {
	dateArr = dateStr.split(/\//);
	if (dateArr.length = 3) {
		dateArr[0] = dateStr.substr(0, 2);
		dateArr[1] = dateStr.substr(3, 2);
		dateArr[2] = dateStr.substr(6, 4);
	}
   
	return new Date(dateArr[1] + "/" + dateArr[0] + "/" + dateArr[2]);
}
