﻿/*-------------------------------------------------------------------------------
	*	FileName ; $common.js
	* Function : commmon utilies functions
	* CreatedDate : 01/02/2003
	* LastUpdate : 01/03/2003
-------------------------------------------------------------------------------*/
function stoperror(){ 
return true 
} 
window.onerror=stoperror 

//------------------------------------------------
// Function Name : LTrim 
// Actions : Remove left string.
//------------------------------------------------
function LTrim(Str) {
	return Str.replace(/^\s+/, '');
}

//------------------------------------------------
// Function Name : RTrim 
// Actions : Remove right space.
//------------------------------------------------
function RTrim(Str) {
	return Str.replace(/\s+$/, '');
}

//------------------------------------------------
// Function Name : Trim 
// Actions : Remove left&right space.
//------------------------------------------------
function Trim(Str) {
	return RTrim(LTrim(Str));
}

//------------------------------------------------
// Function Name : RemoveSpace 
// Actions : Remove left, right & all unwanted spaces inside a Str
//------------------------------------------------
function RemoveSpace(Str) {
	var str = Trim(Str).replace(/\s+/g, ' ');
	str = str.replace(/\s+[,]/g, ',');
	str = str.replace(/\s+[;]/g, ' ;');
	str = str.replace(/\s+[:]/g, ' :');
	return str.replace(/\s+[.]/g, '.');
}

//------------------------------------------------
// Function Name : AddSpace 
// Actions : Add some space to correct sentense
//------------------------------------------------
function AddSpace(Str) {
	var str = Str.replace(/\,/g, ', ');
	str = str.replace(/;/g, '; ');
	str = str.replace(/;/g, ' ;');
	str = str.replace(/\./g, '. ');
	str = str.replace(/\:/g, ' :');
	str = str.replace(/\:/g, ': ');
	str = RemoveSpace(str);
	return str;
}

//------------------------------------------------
// Function Name : TypingCheck 
// Actions : Check spell
//------------------------------------------------
function TypingCheck(Str) {
	var arrayStr = new Array();
	Str = AddSpace(Str);
	for (var i = 0; i < Str.length; i++) {
			arrayStr[i] = Str.charAt(i);
	}
	for (var i = 0; i < Str.length; i++) {
		if ( ( (isPeriod = (arrayStr[i] == '.')) || (arrayStr[i] == ',') || (arrayStr[i] == ';') )  && (i != Str.length - 1) ) {
			arrayStr[i+2] = isPeriod ? arrayStr[i+2].toUpperCase() : arrayStr[i+2].toLowerCase();
		}
	}
	arrayStr[0] = arrayStr[0].toUpperCase();
	var str = "";
	for (var i = 0; i < Str.length; i++) {
			str += arrayStr[i];
	}
	return str;
}


	function setCookie(name,value,day_add){
		var expiredDate = new Date();
		expiredDate.setTime(expiredDate.getTime() + (day_add*24*60*60*1000));
		document.cookie = name + '=' + escape(value) +  ';expires='+expiredDate.toGMTString()+';path=/;domain=ungvien.com';
		return ;
	}
	function getCookie(name){
		var cname = name + '=';
		var dc = document.cookie;
		if (dc.length > 0) {
			var begin = dc.indexOf(cname);
			if (begin != -1) {
			begin += cname.length;
			var end = dc.indexOf(';', begin);
			if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end));
			}
		}
		return null;
	}
function removeCookie(name){  
	var expiredDate = new Date();  
	expiredDate.setTime (expiredDate.getTime() - 24*60*60*1000);  
	var cval = getCookie(name); 
	document.cookie = name + '=' + escape(cval) + '; expires=' + expiredDate.toGMTString()+';path=/';
}
	
function GetYear() {
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
		year+=1900
	document.write (year)
}

function DateDisplay() {
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
		year+=1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10) daym="0"+daym
		var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
		var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
		document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)
}
	function getCategoryName(id){
		var i;
		for(i=0;i<Tree.length;i++){
			var arrElement = Tree[i].split('|');
			if(arrElement[0]==id){
				return arrElement[2];
			}
		}
		return '';
	}
	function instantStr(str){
		var imax = str.length;
		var str_new = '';
		for(var i=0;i<str.length;i++){
			str_new += str.charAt(i)+'&nbsp;'; 
		}
		return str_new;
	}
	function getTopicName(id){
		var i;
		for(i=0;i<arr_document_topic.length;i++){
			if(arr_document_topic[i][0]==id) return arr_document_topic[i][1];
		}
		return 'N/A';
	}
var arrPixFiles = new Array("jpg","jpeg","gif","png","bmp","tif","jpe");
var arrDocFiles = new Array("doc","xls","txt","xls","pdf","ppt","rtf","zip","rar","gz","bz2","tar","psd","fla");
var arrMovieFiles = new Array("div","mov","wmv","wma","avi","mpg","mpeg","qt","mp4","ram");
var arrFlashFiles = new Array("swf");
var _fileName;
var marked_row = new Array;
function CheckAll_bottom(f)
{
	if(f.allbox_up.checked) {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				if(!e.checked) {
					e.click();
				}
			}
		}
	}else {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				e.click();
			}
		}
	}
}
function CheckAll_bottom_v2(f)
{
	if(f.allbox_up.checked) {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				if(!e.checked) {
					e.click();
				}
			}
		}
	}else {
		for(var i=0;i<f.elements.length;i++)
		{
			var e=f.elements[i];
			if((e.name!='allbox_up')&&(e.type=='checkbox')&&(e.disabled==false)) {
				e.click();
			}
		}
	}
}
 function pasteClass(e,classSelect,classNormal)
    {
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) {
	    r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement) {
	    r = e.parentElement.parentElement;
	}
	if (r) {
		r.className = e.checked ? classSelect : classNormal;
	}
    }

 function nothing(e,bg,row_number,mark_color)
    {
	var r = null;
	if (e.parentNode && e.parentNode.parentNode) {
	    r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement) {
	    r = e.parentElement.parentElement;
	}
	if (r) {
		var  theCells = null;
		//r.style.backgroundColor=bg;
		if (typeof(document.getElementsByTagName) != 'undefined') {
			theCells = r.getElementsByTagName('td');
		}
		else if (typeof(r.cells) != 'undefined') {
			theCells = r.cells;
		}
		else {
			return false;
		}
		 var rowCellsCnt  = theCells.length;
         for (var c = 0; c < rowCellsCnt; c++) {
              //theCells[c].style.backgroundColor = bg;
			  theCells[c].setAttribute('bgcolor', bg, 0);
         }
		 if(bg.toLowerCase()==mark_color.toLowerCase()) {
			 marked_row[row_number] = true;
		 }
		 else marked_row[row_number] = false;
	}
    }
	
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
		
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function openBox(winWidth, winHeight, scrollbars,toolbar,top,left,fileSrc) {
	var newParameter = "width=" + winWidth + ",height=" + winHeight ;
	newParameter += ",scrollbars="+scrollbars+",toolbar="+toolbar+",top="+top+",left="+left;
    var newWindow = open(fileSrc,"",newParameter);
}

function openHref(url){
	var openObj = window;
	if(window.opener) openObj = window.opener;
	openObj.location.href = url;
}
function checkTrue(f){
	f.submit();
	return true;
}
function upper_first_char(str){
	var value_upper = '';
	if((str!=null)&&(str!='')){
		value_upper = str.charAt(0).toUpperCase();
		for(var i=1;i<str.length;i++){
			value_upper += str.charAt(i);
		}
	}
	return value_upper;
}
function upper_first_chars(str){
	var value_upper = '';
	if((str!=null)&&(str!='')){
		var arr_upper = str.split(' ');
		for(var i=0;i<arr_upper.length;i++){
			var arr_i = arr_upper[i];
			var value_upper_i = arr_i.charAt(0).toUpperCase();
			value_upper += value_upper_i;
			for(var j=1;j<arr_i.length;j++){
				value_upper += arr_i.charAt(j);
			}
			value_upper += ' ';
		}
	}
	return Trim(value_upper);
}
function resizeIF(){
	if(window.parent){
		var pcg = document.getElementById('body_top_table');
		if(pcg){
			var ifObj = window.parent.document.getElementById('td_parent_window');
			if(ifObj){
				ifObj.style.height = parseInt(pcg.offsetHeight) // + 400;
			}
		}	
	}	
}
function addSpaceN(text){
	var str = '';
	for(var i=0;i<text.length;i++){
		if(text.charAt(i)==' ') str += '&nbsp; &nbsp;';
		else str += text.charAt(i) + ' ';
	}
	return str;
}
function writeSelectDay (seName, choice) {	
	var sT='';
	sT = '<select size="1" name="' + seName + '">'
	sT += '<option value="">dd</option>';
	for (var i=1;i<=31;i++) {
		sT += '<option value=' + i;
		if (i== choice)
			sT += ' selected ';
		sT += '>' + i + '</option>';
	}	
	sT += '</select>'	
	document.write (sT);
}


function writeSelectMonth (seName, choice) {	
	var sT='';
	sT = '<select size="1" name="' + seName + '">'
	sT += '<option value="">mm</option>';
	for (var i=1;i<=12;i++) {
		sT += '<option value=' + i;
		if (i== choice)
			sT += ' selected ';
		sT += '>' + i + '</option>';
	}	
	sT += '</select>'	
	document.write (sT);
}


function writeSelectYear (seName, startYear, endYear, choice) {	
	var sT='';
	sT = '<select size="1" name="' + seName + '">'
	sT += '<option value="">yyyy</option>';
	for (var i=startYear;i<=endYear;i++) {
		sT += '<option value=' + i;
		if (i== choice)
			sT += ' selected ';
		sT += '>' + i + '</option>';
	}	
	sT += '</select>'	
	document.write (sT);
}
function create_option(arr,val){
	var selected = "";
	var str = "";
	for(var i=0;i<arr.length;i++){
		if((arr[i].toString()==val.toString())&&(val.toString()!='')){
			selected = "selected";
		}	
		else 	selected = "";
		str += "<option value='"+arr[i]+"' " + selected + ">"+ arr[i]+ "</option>";
	}
	return str;
}
function create_option_rs(arr,val){
	var selected = "";
	var str = "";
	for(var i=0;i<arr.length;i++){
		if((arr[i][0].toString()==val.toString())&&(val.toString()!='')){
			selected = "selected";
		}	
		else 	selected = "";
		str += "<option value='"+arr[i][0]+"' " + selected + ">"+ arr[i][1]+ "</option>";
	}
	return str;
}
function ajaxLoadIF(){
	var args = ajaxLoadIF.arguments;
	var el = document.getElementById(args[1]);
	if(el){
		el.innerHTML = '<IFrame align=top frameborder=0 height="100%" width="100%" marginheight=0 marginwidth=0 style="margin-top:10px; margin-left:0px; margin-right:0px; margin-bottom:0px;" scrolling=no src="'+args[0]+'" name="if_parent_window"></Iframe>';	
	}
}
function showThisItem(iItem){
	if((iItem.style.display)&&(iItem.style.display=='none')) iItem.style.display='';
}
function ajaxManager(){
	var args = ajaxManager.arguments;
	viewLoadStatus(args[2]);
	switch (args[0]){
		case "load_page":
			if (document.getElementById) {
				var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			}
			if (x){
				x.onreadystatechange = function(){
					if (x.readyState == 4 && x.status == 404){
						var el = document.getElementById(args[2]);
						if(el){
								//showThisItem(el);
								if((el.tagName.toUpperCase()=='INPUT')||(el.tagName.toUpperCase()=='TEXTAREA')){
									el.value = "Sorry, Sir/Madam. I tried, but, content you require's not found !";	
								}else{
									el.innerHTML = "Sorry, Sir/Madam. I tried, but, content you require's not found !";	
								}
						}
						//remove_loading(args[2]);
					}
					if (x.readyState == 4 && x.status == 200){
						var el = document.getElementById(args[2]);
						if(el){
							//showThisItem(el);
							if(args[5]){
								var eval_str = args[5]+'("'+ x.responseText +'","'+args[2]+'")';
								eval(eval_str);
							}else{
								if((el.tagName.toUpperCase()=='INPUT')||(el.tagName.toUpperCase()=='TEXTAREA')){
									el.value = x.responseText;
								}else{
									marked_row = new Array;
									var location = Trim(x.responseText.substr(0,9).toString().toLowerCase());
									if(location!="location"){
										el.innerHTML = x.responseText;
										runAfterLoad();	
										/*
										if((args[1].toString().substr("http://"+window.location.hostname+"/employee/".length,19).toLowerCase()=='inc_resume_create.p')||(args[1].toString().substr("http://"+window.location.hostname+"/employee/".length,19).toLowerCase()=='inc_resume_edit.php')){
											
										}
										*/
									}else{
										window.location.href=x.responseText.substr(10);
									}
								}
							}
						}
						//remove_loading(args[2]);
					}
				}
				if((args[3])&&(args[4])){
					try{
						x.open(args[3], args[1], true);
						x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
						x.send(args[4]);
					}catch(e){
						alert(e);
					}
				}else{
					try{
						x.open("GET", args[1], true);
						x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
						x.send(null);
					}catch(e){
						alert(e);
					}	
				}
			}
			break;
		case "load_js" :
			if (document.getElementById) {
				var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
				}
				if (x)
					{
				x.onreadystatechange = function(){
					if (x.readyState == 4 && x.status == 200){
						var getheadTag = document.getElementsByTagName('head')[0];
						setjs = document.createElement('script'); 
						//setjs.setAttribute('type', 'text/javascript');
						if(args[2]){
						setjs.setAttribute('language', args[2]);
						}
						getheadTag.appendChild(setjs); 
						setjs.text = x.responseText;
						}
					}
					x.open("GET", args[1],true);
					x.send(null);
					}
				break;	
	}
}
function remove_loading() {
	var targelem = document.getElementById('loader_container');
	if(targelem){
		targelem.style.display='none';
		targelem.style.visibility='hidden';
	}
}

function viewLoadStatus(tagHTML){
	if(tagHTML!=null){
		var targelem = document.getElementById(tagHTML);
		if((targelem.tagName.toUpperCase()!='INPUT')&&(targelem.tagName.toUpperCase()!='TEXTAREA')){
			targelem.innerHTML = '<div align="center"><img src="/images/newstyle/loading.gif" border=0><br>Loading...</div>';
		}
	}
}
function pasteJs(){
	var args = pasteJs.arguments;
	if(args[0]){
		var getheadTag = document.getElementsByTagName('head')[0];
		setjs = document.createElement('script'); 
		//setjs.setAttribute('type', 'text/javascript');
		if(args[1]){
			setjs.setAttribute('language', args[1]);
		}
		getheadTag.appendChild(setjs); 
		setjs.text = args[0];
	}
}
function runScripts(id) {
	if(id){
		var el = document.getElementById(id);
		if(el){
			var se = el.getElementsByTagName("script");
			if(se){
				for(var i=0;i<se.length;i++) {
					eval(se[i].innerHTML);
				}
			}
		}
	}
	return false;
}
function putContentFF(elementid,content){
	if (document.getElementById && !document.all){
		var rng = document.createRange();
		var el = document.getElementById(elementid);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(content);
		while (el.hasChildNodes())
			el.removeChild(el.lastChild);
			el.appendChild(htmlFrag);
	}
}
function bookmarkUngVien(){
	bookmarksite('UngVien.Com.Vn - Mang viec lam Viet Nam', 'http://www.ungvien.com.vn');
	return false;
}
/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
/*******NEW JS AJAX***************************/
var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
		page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
	if (!document.getElementById)	return
	for (i=0; i<arguments.length; i++){
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

/*******END AJAX******************************/
window.status = "UngVien.Com - Mang viec lam Viet Nam";