// Title
//document.title = "HRMS Admin";

var cldHighlighted;
var cldHighlightedClass;

var MSG_SAVE_SUCCESS = "Data have been save successfully!\n";

function doInit() {
}

function confirm_cancel() {
	if(confirm("Are you sure want to Cancel and back to previous screen?")) return(true); else return(false);
}

function h_sub_menu(int_status) {
//	window.status = window.event.srcElement.className;
	if (int_status) {
		window.event.srcElement.className = "lineMenuUp";
	} else {
		window.event.srcElement.className = "lineMenu";
	}
}

function h_sub_line_menu(int_status) {
//	window.status = window.event.srcElement.className;
	if (int_status) {
		window.event.srcElement.className = "subLineMenuUp";
	} else {
		window.event.srcElement.className = "subLineMenu";
	}
}

function h_menu(int_status) {
//	window.status = window.event.srcElement.className;
	if (int_status) {
		window.event.srcElement.className = "mainMenuUp";
	} else {
		window.event.srcElement.className = "mainMenu";
	}
}

function h_menu_top(int_status) {
//	window.status = window.event.srcElement.className;
	if (int_status) {
		window.event.srcElement.className = "lineMenuTopUp";
	} else {
		window.event.srcElement.className = "lineMenuTop";
	}
}
/*
function doNavigateContent(str_location) {
	top.content.location = str_location;
}

function doNavigateContent(str_location, str_title, str_menu) {
	top.content.location = str_location;
	if (typeof(str_title) == "string") {
		top.head.titleModule.innerHTML = str_title;
		top.frames.subSubMenu.location = str_menu;
	}
}
*/
function doNavigateContent(str_location, str_title, str_menu) {
	top.content.location = str_location;	
	if (typeof(str_title) == "string") {
		top.head.contentTitle.innerText = str_title;
		top.frames.subSubMenu.location = str_menu;
  }
}

function doNavigateContentInv(str_location, str_title, str_menu) {
	top.content.location = str_location;	
	if (typeof(str_title) == "string") {
		top.frames.subSubMenu.location = str_menu;
		if (str_title == "Transaction") {
			top.head.headimages.src = "../images/head_transaction.gif";
		} else if (str_title == "Process") {
			top.head.headimages.src = "../images/head_process.gif";
		} else if (str_title == "Report") {
			top.head.headimages.src = "../images/head_report.gif";
		} else if (str_title == "System Maintenance") {
			top.head.headimages.src = "../images/head_maintenance.gif";
		} else if (str_title == "Home") {
			top.head.headimages.src = "../images/head_home.gif";
		} else if (str_title == "Recruitment") {
			top.head.headimages.src = "../images/head_recruitment.gif";
		} else if (str_title == "Employee") {
			top.head.headimages.src = "../images/head_employee.gif";
		} else if (str_title == "Training") {
			top.head.headimages.src = "../images/head_training.gif";
		} else if (str_title == "Personnel") {
			top.head.headimages.src = "../images/head_personnel.gif";
		} else if (str_title == "Master") {
			top.head.headimages.src = "../images/head_master.gif";
		} else if (str_title == "Home") {
			top.head.headimages.src = "../images/head_home.gif";
		} else {
			top.head.headimages.src = "../images/spacer.gif";
		}
  }
}

function doNavigate(str_location) {
	window.top.location = str_location;
}

function showServicesDetail(int_sub_services) {
	var int_value = event.srcElement.value;
	int_value *= 1;

	// Personal radio button response
	if (int_sub_services == 1) {
		switch (int_value) {
			case 1:
				services_detail.location = "services_detail.html";
				break;
			case 2:
				services_detail.location = "services_detail_blank.html";
				break;
			case 3:
				showError(2);
				break;
			default:
				showError();
				break;
		}
	}

	// Corporate radio button response
	if (int_sub_services == 2) {
		switch (int_value) {
			case 1:
				showError(2);
				break;
			case 2:
				showError(2);
				break;
			case 3:
				showError(2);
				break;
			default:
				showError();
				break;
		}
	}
	
}

var str_old_sub;

function showSub(str_sub) {
	var str_text = event.srcElement.innerText;
	var int_obj_left = event.srcElement.offsetLeft + event.srcElement.offsetWidth;
	var int_obj_top = event.srcElement.offsetTop + 25;
	var str_cmd;

/*	if (str_old_sub == str_sub) {
		str_text = str_text.replace("-", "+");
		str_cmd	 = str_sub + ".style.display = 'none'; ";
	} else {
		str_text = str_text.replace("+", "-");
		str_cmd	 = str_sub + ".style.display = 'block';"
	}

	eval(str_cmd);
	event.srcElement.innerText = str_text;

	if (str_old_sub == str_sub) {
		str_old_sub = "";
	} else {
		str_old_sub = str_sub;
	}*/

	var str_sub_status;
	str_sub_status = eval(str_sub + ".style.display");
	if (str_sub_status == "" || str_sub_status == 'none') {
		str_text = str_text.replace("+", "-");
		str_cmd	 = str_sub + ".style.display = 'block';"
	} else {
		str_text = str_text.replace("-", "+");
		str_cmd	 = str_sub + ".style.display = 'none'; ";
	}

	eval(str_cmd);
	event.srcElement.innerText = str_text;
}

function getMonthName(int_month) {
	var str_month;

	switch (int_month) {
		case 0:
			str_month = "January";
			break;
		case 1:
			str_month = "February";
			break;
		case 2:
			str_month = "March";
			break;
		case 3:
			str_month = "April";
			break;
		case 4:
			str_month = "May";
			break;
		case 5:
			str_month = "June";
			break;
		case 6:
			str_month = "July";
			break;
		case 7:
			str_month = "August";
			break;
		case 8:
			str_month = "September";
			break;
		case 9:
			str_month = "October";
			break;
		case 10:
			str_month = "November";
			break;
		case 11:
			str_month = "December";
			break;
	}
	return str_month;
}

function getDayName(int_day) {
	var str_day;

	switch (int_day) {
		case 0:
			str_day = "Sunday";
			break;
		case 1:
			str_day = "Monday";
			break;
		case 2:
			str_day = "Tuesday";
			break;
		case 3:
			str_day = "Wednesday";
			break;
		case 4:
			str_day = "Friday";
			break;
		case 5:
			str_day = "Thursday";
			break;
		case 6:
			str_day = "Saturday";
			break;
	}
	return str_day;
}

function printDate(str_format, int_ret) {

	var str_date, str_month, str_day, str_sec, str_min, str_hour;
	var int_day, int_date, int_month, int_year, int_sec, int_min, int_hour;
	var d = new Date();

	// Get date of month
	int_date = d.getDate();
	str_date = int_date.toString();
	if (str_date.length == 1) {str_date = "0" + str_date;}
	str_date = str_format.replace("dd", str_date);
	
	// Get year
	int_year = d.getFullYear();
	str_date = str_date.replace("yy", int_year);

	// Get second
	int_sec = d.getSeconds();
	str_sec = int_sec.toString();
	if (str_sec.length == 1) {str_sec = "0" + str_sec;}
	str_date = str_date.replace("ss", str_sec);

	// Get minute
	int_min = d.getMinutes();
	str_min = int_min.toString();
	if (str_min.length == 1) {str_min = "0" + str_min;}
	str_date = str_date.replace("mm", str_min);

	// Get hours
	int_hour = d.getHours();
	str_hour = int_hour.toString();
	if (str_hour.length == 1) {str_hour = "0" + str_hour;}
	str_date = str_date.replace("hh", str_hour);

	// Get month of year
	int_month = d.getMonth() + 1;
	str_month = int_month.toString();
	if (str_month.length == 1) {str_month = "0" + str_month;}
	str_date = str_date.replace("Mm", str_month);
	str_date = str_date.replace("MM", getMonthName(int_month));

	// Get day
	int_day = d.getDay();
	str_date = str_date.replace("DD", getDayName(int_day));

	if (int_ret) {
		return str_date;
	} else {
		document.write(str_date);
	}
}

function showError(int_error) {
	var str_message = "";
	switch (int_error) {
		case 1:
			str_message = 'Module not installed !!!';
			break;
		case 2:
			str_message = 'Database Not Found !!!';
			break;
		default:
			str_message = 'Error found !!!';
	}
	alert(str_message);
}

function check(form_name) {
	var ret_value = false;
	for (i = 0; i < form_name.elements.length; i++) {
		if (form_name.elements(i).attributes(81).value == "text" && form_name.elements(i).value == "") {
			alert("Missing Value");
			ret_value = false;
			form_name.elements[i].focus();
			break;
		} else {
			ret_value = true;
		}
	}
	return ret_value;
}

function cancelEvent() {
	cancelEvent = true;
}

function cldChangeColor(id) {
	if(id==0) {
		switch(window.event.srcElement.className) {
			case "listCldRed":
				window.event.srcElement.className="listCldRedLight";
				break;
			case "listCldBlue":
				window.event.srcElement.className="listCldBlueLight";
				break;
			case "listCldSilver":
				window.event.srcElement.className="listCldSilverLight";
				break;
		}
	}
	else {
		switch(window.event.srcElement.className) {
			case "listCldRedLight":
				window.event.srcElement.className="listCldRed";
				break;
			case "listCldBlueLight":
				window.event.srcElement.className="listCldBlue";
				break;
			case "listCldSilverLight":
				window.event.srcElement.className="listCldSilver";
				break;
		}
	}
}

function confirm_delete() {
	if (confirm("Hapus data ini?")) return(true); 
	else return(false);
}

function alertDelete() {
  if (document.forms[0].candelete.value == 1) {
    alert("Can't be deleted, already used");
    return(false);
  } else {
    if(confirm("Delete this record?")) return(true); else return(false);
  }
}

function cldHighlightMe() {
	
	var cldHighlight=window.event.srcElement;
	
	if(cldHighlight.className!="listCldHighLighted") {
		if(cldHighlighted=="[object]")
		{
			switch(cldHighLightedClass) {
				case "listCldRedLight":
					cldHighlighted.className="listCldRed";
					break;
				case "listCldBlueLight":
					cldHighlighted.className="listCldBlue";
					break;
				case "listCldSilverLight":
					cldHighlighted.className="listCldSilver";
					break;
			}
		}
		
		cldHighlighted=cldHighlight;
		cldHighLightedClass=cldHighlighted.className;
		
		cldHighlight.className="listCldHighLighted";
		return(true);
	} else {
		return(false);
	}

}

function NewWin (locs, name, winwidth, winheight, wintop, winleft, scrollskah, resizekah, titlekah, statuskah)
{	
	extra = '';
	extra = extra + 'width=' + winwidth;
	extra = extra + ', height=' + winheight;
	extra = extra + ', top=' + wintop;
	extra = extra + ', left=' + winleft;
	extra = extra + ', scrollbars=' + scrollskah;
	extra = extra + ', resizable=' + resizekah;
	extra = extra + ', titlebar=' + titlekah;	
	extra = extra + ', status=' + statuskah;	
	window.open (locs, name, extra);
}