//Author: Siu Wai, Lau
//Purpose: This file is to share the common code between different page in javascript

// create a pop up windows
function Popup_window(url, h, w) {
	window.open(url,"",'height=' +h +', width=' + w + ', scrollbars=yes');
}

// make a post request to the URL
function redirectURL(url, frm_name){
	var myForm = document.getElementById(frm_name);
	myForm.setAttribute("action", url);
	myForm.setAttribute("method", "post");
    myForm.submit();           
}

// hide or show the child details section
function switchChild(show)
{
	if(show == 'false'){
		document.getElementById('child_details').style.display = 'none';
		document.getElementById('lbl_child').style.display = 'none';
		// remove all the child details
		var tableElement = document.getElementById('tbl_child_details');
		var rowNo = tableElement.rows.length;
		if(rowNo > 0){  // if hidden is required, remove all the rows except the header in the child section.
			for(var i = tableElement.rows.length - 1; i > 0; i--)
			{
			tableElement.deleteRow(i);
			}
		}
		document.getElementById('child_name').value='';
	} else { // if the child section is required to show.
		document.getElementById('lbl_child').style.display = 'block';
		document.getElementById('child_details').style.display = 'block';
	}
}

// show or hide the child information
function showChildDetails()
{
	if(document.getElementById('no_child').value == "0") {
		switchChild('false'); 
	} else {
		switchChild('true')
	};
}

