function closeWindow() {
	window.close();
}

function periodDates(id) {
	var toDate = "";
	if ((document.getElementById(id) != null) && (id == 'txtPeriodFrom')) {
		toDate = lastDayOfMonth(document.all.txtPeriodFrom.value);
		if (toDate.length > 0) {
			document.all.txtPeriodTo.innerText =  toDate;
		}
	}
}

function lastDayOfMonth(fromDate) {
	var dd = "";
	var d = "31";
	var m = "";
	var y = "";
	for (var i=0; i < fromDate.length;) {
		if (fromDate.substr(i, 1) == "-") {
			i++;
			if (m.length == 0) {
				dd = fromDate.substr(0, (i - 1));
				m = fromDate.substr(i, 3);
			}
			else {
				y = fromDate.substr(i, (fromDate.length - i));
			}
		}
		i++;
	}
	switch(m) {
		case "Feb":
			if ((y % 4) == 0) {
				d = "29";
			}
			else {
				d = "28";
			}
			break;
		case "Apr":
			d = "30";
			break;
		case "Jun":
			d = "30";
			break;
		case "Sep":
			d = "30";
			break;
		case "Nov":
			d = "30";
			break;
		default:
			break;
	}
	if (dd != 1) {
		return("");
	}
	else {
		return(d + "-" + m + "-" + y);
	}
}

function refreshOpener() {
	if (opener.document.getElementById("_refresh") != null) {
		opener.document.getElementById("_refresh").innerText="1";
		opener.document.forms(0).submit();
		closeWindow();
	}
}

function insertHTML(id, HTMLstring) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).innerHTML=HTMLstring;
	}
}

function appendHTML(id, HTMLstring) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).insertAdjacentHTML("BeforeEnd",HTMLstring);
	}
}

function changeClass(id, newClass) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).className=newClass;
	}
}

function openFile(file) {
	if (file.length != 0) {
		window.open(file,"file","toolbar=1,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1");
	}
}

function cDel() {
	return confirm('Are you sure?');
}

function addLink(id, target) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).href = target;
	}
}

function dfp(url,dir,h,w) { 
	w = window.open(url+'&dir='+escape(dir),"dfp","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+w+",height="+h+",left=200,top=80");
	w.focus();
} 

function popup(url,h,w,t,l) { 
	w=window.open(url,"popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width="+w+",height="+h+",left="+l+",top="+t);
	w.focus();
} 

function newWindow(url, name) { 
	if (name == null) {
		name="new";
	}
	w=window.open(url,name,"toolbar=1,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1");
	w.focus();
} 
	
function changeCont(url) {
	if (confirm('Data has changed...\nContinue anyway?')) {
		newWindow(url,window.name);
	}
}

function changeClose() {
	if (confirm('Data has changed...\nClose anyway?')) {
		refreshOpener();
	}

function cDel () {
	return confirm('Are you sure?');
	}
}
