 function addEducations() { 	
    var targetTable = $('tableEducation');
    targetTable.insertRow();
    var newRow = targetTable.rows.length;
    
    // à¾ÔèÁ cell(<td>)
    targetTable.rows[newRow-1].insertCell();
    targetTable.rows[newRow-1].insertCell();	
    targetTable.rows[newRow-1].insertCell();
    targetTable.rows[newRow-1].insertCell();
    targetTable.rows[newRow-1].insertCell();
    targetTable.rows[newRow-1].insertCell();
    targetTable.rows[newRow-1].insertCell();
    // set attribuld  ID ãËé row
     id = Math.floor(Math.random()*10000000001);
    targetTable.rows[newRow-1].id = "Educations"+id;
    targetTable.rows[newRow-1].align = "center";
    //targetTable.rows[newRow-1].cells[0].id = "texttable";
    //targetTable.rows[newRow-1].cells[1].id = "texttable";
	
    // ãÊè¢éÍÁÙÅáµèÅÐ cell
    targetTable.rows[newRow-1].cells[0].innerHTML = '<input type="hidden" size="4" name="inputEdu_ID[]" id="inputEdu_ID'+id+'"><input type="text" size="4" name="inputEdu_Start[]" id="inputEdu_Start'+id+'">';
    targetTable.rows[newRow-1].cells[1].innerHTML = '<input type="text" size="4" name="inputEdu_Stop[]" id="inputEdu_Stop'+id+'">';
    targetTable.rows[newRow-1].cells[2].innerHTML = '<input type="text" size="20" name="inputEdu_Institute[]" id="inputEdu_Institute'+id+'">';
    targetTable.rows[newRow-1].cells[3].innerHTML = '<input type="text" size="20" name="inputEdu_Level[]" id="inputEdu_Level'+id+'">';
    targetTable.rows[newRow-1].cells[4].innerHTML = '<input type="text" size="20" name="inputEdu_Major[]" id="inputEdu_Major'+id+'">';
    targetTable.rows[newRow-1].cells[5].innerHTML = '<input type="text" size="3" name="inputEdu_Gpa[]" id="inputEdu_Gpa'+id+'">';
     targetTable.rows[newRow-1].cells[6].innerHTML = "<img src=\"images/icon/s_error.png\" align=\"absmiddle\" style=\"cursor: hand;\" onclick=\"DeleteEducations(Educations"+id+".rowIndex);\">";
 
    
}

function disableButton(mybtnObj,mycheckboxObj)
{
	btn = $(mybtnObj);
	chkbox = $(mycheckboxObj);
	if(chkbox.checked == true) {
		enable();
	} else {
		disable();
	}
}

function ShoworHide(myObj,fontObj)
{
	myObj = $(myObj);
	fontObj = $(fontObj);
	if(myObj.style.display == '') {
		myObj.style.display='none';
		fontObj.innerHTML = 'แก้ไข';
	} else {
		myObj.style.display='';
		fontObj.innerHTML = 'ย่อ';
	}
}
function ShoworHide(myObj,fontObj)
{
	myObj = $(myObj);
	fontObj = $(fontObj);
	if(myObj.style.display == '') {
		myObj.style.display='none';
		fontObj.innerHTML = 'แก้ไข';
	} else {
		myObj.style.display='';
		fontObj.innerHTML = 'ย่อ';
	}
}

/*
<textarea name="inputBlurb" id="inputBlurb" cols="60" rows="5">{$profile_data[Profile_Blurb]}</textarea>
						<input type="hidden" name="inputBlurbHidden"  id="inputBlurbHidden" value="">
showHideLayer('Blurb');
*/
 function DeleteEducations(numRow) { 
  var targetTable = $('tableEducation');	
   var x = window.confirm("Are you sure to delete ?");
     if (x) {
	  myForm.delEducations.value = myForm.delEducations.value+","+targetTable.rows[numRow].id;
      	  targetTable.deleteRow(numRow);
     } // if

   return;
  }
  
 function addEducations2() { 
   var targetTable = $('tableEducationEdit');
   var btAddEducation = $('btaddEducation2');
    var inputEdu_Gpa = $('inputEdu_Gpa');	
 	targetTable.style.display='';
 	btAddEducation.disabled=true;
 	inputEdu_Gpa.value='';
}  
  function saveEducation() { 
   var targetTable = $('tableEducationEdit');
   var btAddEducation = $('btaddEducation2');
   	btAddEducation.disabled=false;
 	targetTable.style.display='none';
 	
}   
  
  
 function confirmDelBlog(objBlogid) { 
  	
   var x = window.confirm("Are you sure to delete this Blog ?");
     if (x) {
     	location='?action=k2.core.blog.deleteblog&Blog_id='+objBlogid;
     	return true;
     }
   return false;
}
 function showCheckUserButton() { 
   var tdCheckAvailability = $('tdCheckAvailability');
   var tdAvailable = $('tdAvailable');	
   var inputUsernameChk = $('inputUsernameChk');	
   tdCheckAvailability.innerHTML = '<a href="javascript:void(0);" onclick="chkUsername();"><img src="/imagesnew/check_availability.gif" border="0"/></a>';
   tdAvailable.innerHTML = '';
    inputUsernameChk.value = 'no';
   return false;
}
function OnSubmitButtonClick() { 
	/*
	inputAvatarObj = $('inputAvatar');
	if (showImage(inputAvatarObj.value,'PrevieIMG',inputAvatarObj)) {
		
	}
	*/
	//$('btnInsertSignup').disabled=true;
	//addHeight = $addHeight;
	disable();
	
						Element.setStyle('msg', {position:'absolute', border:'2px solid #cccccc', backgroundColor: '#FFFFFF', width:'354', height: '104', left: ((screen.availWidth/2)-150), top: 600 }); 
						$('msg').innerHTML='<div class=handle width=100% align=right><img src=\"/modules/apply/images/delete.gif\" style=hspace=3 vspace=3></div><table width=\"100%\" height=\"90%\" border=\"2\"><tr><td width=\"100%\" height=\"100%\" align=\"center\" valign=\"middle\"><img src=\"/images/loading_b.gif\"><br><font color=\"#00cc00\"><b>ระบบกำลังบันทึกข้อมูล  กรุณารอสักครู่</b></font><br /><br /></td></tr></table>'; 
						Effect.Appear('msg');
						
 	ajax_OnSubmitButtonClick(ajax.getForm("myForm"));
	return false;
	
}

function enable() {
	aLink ="<a  href='#' onclick='OnSubmitButtonClick();' onmouseover=\"MM_swapImage('Image6','','imagesnew/images/i_ok_h.gif',1)\" onmouseout='MM_swapImgRestore()'><img src='imagesnew/images/i_ok_h.gif' name='Image4'  border='0' id='Image6' /></a>";
	$('btnInsertSignup').innerHTML = aLink;
}
function disable()
{
	nLink = "<img src='imagesnew/images/i_ok.gif' name='Image4'  border='0' id='Image6' />";
	$('btnInsertSignup').innerHTML = nLink;
}

function forgetPassword() { 
	xajax_forgetPassword(xajax.getForm("myForm"));
}


function updateProfile() { 
	/*
	Element.setStyle('msg', {position:'absolute', border:'2px solid #cccccc', backgroundColor: '#FFFFFF', width:'354', height: '104', left: ((screen.availWidth/2)+100), top: 300 }); 
	$('msg').innerHTML='<div class=handle width=100% align=right><img src="web/images/icon/delete.gif" style=cursor:pointer hspace=3 vspace=3></div><table width="100%" height="90%" border="2"><tr><td width="100%" height="100%" align="center" valign="middle"><img src="images/loading_b.gif"><br><font color="#00cc00"><b>ระบบกำลังบันทึกข้อมูล</b></font><br /><br /></td></tr></table>'; 
	Effect.Appear('msg'); 
	*/
	a=updateProfile.arguments
	location.hash='topPage';
	saveHtml_Profile('About');
	saveHtml_Profile('Blurb');
 	xajax_UpdateProfile(xajax.getFormValues("myForm"),a[0]);
	return false;	
}
function isEmail(str) {
	  var supported = 0;
	  if (window.RegExp) {
	    var tempStr = "a";
	    var tempReg = new RegExp(tempStr);
	    if (tempReg.test(tempStr)) supported = 1;
	  }
	  if (!supported) 
	  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  return (!r1.test(str) && r2.test(str));
}
function showProcessBar() {
    var ajaxprocess = $('ajax-process');
    var top = window.pageYOffset ? window.pageYOffset : document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop;
    ajaxprocess.style.top = "500px";
   ajaxprocess.innerHTML = "processing request...";
    ajaxprocess.style.display = "inline";
}
function hideProcessBar() {
    var ajaxprocess = $('ajax-process');
   ajaxprocess.innerHTML = "";
    ajaxprocess.style.display = "none";
}
  function DeleteTags(numRow) { 
  	
   var x = window.confirm("Are you sure to delete this tags ?");
   var tagstable = $('tabletags');
    var Delete_List = $('Delete_List');
  var mesg='Not Delete Tag Row 1!!';
 //  mesg2 = encodeURI(mesg);
     if (x) {
     	if (tagstable.rows.length  == 1 ) {
     		alert(mesg);
     		return;
     	}
	 Delete_List.value = Delete_List.value+","+tagstable.rows[numRow].id;
      	  tagstable.deleteRow(numRow);
     } 
   return;
}
function chkUsername() { 
  
  var myForm = $('myForm');	
  var mesg = 'กรุณากรอกชื่อ Planet ที่คุณต้องการ';
 
   with(myForm) {
   	if(isBlank(inputUsername)) {	alert(mesg); inputUsername.focus(); return false; }
	if((inputUsername.value.length < 6 ) || (inputUsername.value.length > 12)) {	
		alert('ชื่อ Planet ต้องความยาวอยู่ระหว่าง 6 - 12 ต้วอักษรค่ะ'); 
		inputUsername.focus(); return false; 
	}
	if(!ajax_chkUsername(inputUsername.value)) {
			return false;
	}
	return false;
}
	
   return;
  }
  function isBlank(myObj) { if(myObj.value=='') { return true; } return false; }
function showHideLayer2(obj) {
	//var obj_show = $('tbl'+obj+'Show');
	//var obj_edit = $('tbl'+obj+'Edit');
	//var obj_edittor = $('input'+obj);
	var obj_content = $(obj);
	var obj_content_hidden = $('input'+obj+'Hidden');
	//editor = tinyMCE.getEditorId('input'+obj);
	//var inst = tinyMCE.getInstanceById(editor);
   	if(obj_show.style.display == '' ) { // ¶éÒà»Ô´ á¡éä¢
	obj_content.innerHTML='<textarea name="input'+obj+'" id="input'+obj+'" cols="60" rows="5">'+obj_content.innerHTML+'</textarea>\n<input type="hidden" name="input'+obj+'Hidden"  id="input'+obj+'Hidden" value="">';
   		inst.getBody().innerHTML = obj_content.innerHTML;
   		//obj_show.style.display = 'none';
   		//obj_edit.style.display = '';
	} else {
		obj_content.innerHTML = inst.getBody().innerHTML;
		obj_content_hidden.value = obj_content.innerHTML;
		obj_show.style.display = '';	
		obj_edit.style.display = 'none';
	}
}

function showHideLayer(objID) {
	var obj_content = $(objID);
	var obj_btn = $('divbtn'+objID);
	tinyMCE.execCommand('mceRemoveEditor', true, 'input'+objID);
	obj_content.innerHTML='<textarea name="input'+objID+'" id="input'+objID+'" cols="60" rows="10">'+obj_content.innerHTML+'</textarea>';
	tinyMCE.execCommand('mceAddEditor', true, 'input'+objID);
	obj_btn.innerHTML='<input type="button" id="btnBlurb" class="submit_btn" value=" บันทึก... " onclick="saveHtml_Profile(\''+objID+'\')" />';
}

function saveHtml_Profile(objID) {
	var editor = tinyMCE.getEditorId('input'+objID);
	var obj_content = $(objID);
	//var obj_btn = $('divbtn'+objID);
	var obj_content_hidden = $('input'+objID+'Hidden');
	if (editor) {
		var inst = tinyMCE.getInstanceById(editor); 
		var codeHTML = inst.getBody().innerHTML;
		obj_content.innerHTML = codeHTML;
	}
	obj_content_hidden.value = obj_content.innerHTML;
}
function saveHtml(obj) {
	var obj_show = $('tbl'+obj+'Show');
	var obj_edit = $('tbl'+obj+'Edit');
	var obj_edittor = $('input'+obj);
	var obj_content = $(obj);
	var obj_content_hidden = $('input'+obj+'Hidden');
	editor = tinyMCE.getEditorId('input'+obj);
	var inst = tinyMCE.getInstanceById(editor);
	obj_content.innerHTML = inst.getBody().innerHTML;
	obj_content_hidden.value = obj_content.innerHTML;
	obj_show.style.display = '';	
	obj_edit.style.display = 'none';
}
function timedText()
{
	countDown = document.getElementById('countDown').value;
	countDown--;
	
	document.getElementById('countDown').value = countDown;
	if (countDown > 0) setTimeout("timedText()",1000);
}

function showImage(myfile,objShowImg,objInputImg) {
	if(myfile!='') {
		myfile = myfile.toLowerCase();
		Temp = myfile.charAt(myfile.length-4) + myfile.charAt(myfile.length-3) + myfile.charAt(myfile.length-2) + myfile.charAt(myfile.length-1);
		if(Temp=='.jpg' || Temp=='.gif' || Temp=='jpeg') {
			//document.getElementById('tbl'+objShowImg).style.display='';
			//document.getElementById(objShowImg).src=myfile;
			//document.getElementById('tbl'+objShowImg).style.display='none';
			/*
			document.getElementById('btnInsertSignup').disabled = true;
			alert('กรุณารอสักครู่...\n กำลังตรวจสอบขนาดภาพค่ะ');
			for(i=0; i<100; i++) setTimeout('return true;', 5000);
			imgWidth = document.getElementById(objShowImg).width;
			imgHeight = document.getElementById(objShowImg).height;
			alert(imgWidth +' == '+ imgHeight);
			document.getElementById('btnInsertSignup').disabled = false;
			if (imgWidth != 80 && imgHeight != 80 ) {
				alert('สามารถใช้ได้แต่รูปภาพขนาด 80 x 80 pixel เท่านั้นค่ะ. ');
				objInputImg.focus();
				return true;
			}
			*/
		} else {
			alert('สามารถใช้ได้แต่รูปภาพเท่านั้นค่ะ');
			objInputImg.focus();
			return true;
		}
	}
	return false;
}
function showImage2(myfile,objShowImg,objInputImg) {
	return true;
	if(myfile!='') {
		myfile = myfile.toLowerCase();
		Temp = myfile.charAt(myfile.length-4) + myfile.charAt(myfile.length-3) + myfile.charAt(myfile.length-2) + myfile.charAt(myfile.length-1);
		if(Temp=='.jpg' || Temp=='.gif' || Temp=='jpeg') {
			document.getElementById('tbl'+objShowImg).style.display='';
			document.getElementById(objShowImg).src=myfile;
			document.getElementById('div'+objShowImg).innerHTML='<img src="'+myfile+'" >';
			//document.getElementById('tbl'+objShowImg).style.display='none';
			/*
			document.getElementById('btnInsertSignup').disabled = true;
			alert('กรุณารอสักครู่...\n กำลังตรวจสอบขนาดภาพค่ะ');
			for(i=0; i<100; i++) setTimeout('return true;', 5000);
			imgWidth = document.getElementById(objShowImg).width;
			imgHeight = document.getElementById(objShowImg).height;
			alert(imgWidth +' == '+ imgHeight);
			document.getElementById('btnInsertSignup').disabled = false;
			if (imgWidth != 80 && imgHeight != 80 ) {
				alert('สามารถใช้ได้แต่รูปภาพขนาด 80 x 80 pixel เท่านั้นค่ะ. ');
				objInputImg.focus();
				return true;
			}
			*/
		} else {
			alert('สามารถใช้ได้แต่รูปภาพเท่านั้นค่ะ');
			objInputImg.focus();
			return true;
		}
	}
	return false;
}
function popupAvatar(obj){
//	alert('objid: '+obj.id+' obj_chk: ' + obj_chk+' obj_source: ' + obj_source+' obj_name: ' + obj_name)
	var tm='t_e_m_p';
	var col=3;
	var i=1;
	var BoxColor='<div class="handle" width="100%" align="right"><img src="images/icon/delete.gif" alt="ปิด/Close" onclick="Element.hide('+tm+');" style="cursor:pointer" hspace="5" vspace="5"></div>';
	BoxColor+='<table border="0" cellspacing="0" cellpadding="0">'
	BoxColor+='<tr><td colspan="2" class="postItcolorSelection">'
	var rowsize=3;
	var defaultBgPic=['avatar001.jpg', 'avatar002.jpg', 'avatar003.jpg', 'avatar004.jpg', 'avatar005.jpg', 'avatar006.jpg', 'avatar007.jpg', 'avatar008.jpg', 'avatar009.jpg', 'avatar010.jpg', 'avatar011.jpg', 'avatar012.jpg'];

	defaultBgPic.each( function(pic){
		BoxColor+='<img src="/files/avatar/'+pic+'" id="bgPicView" style="cursor:pointer" onclick="$(\'tblPrevieIMG\').style.display=\'\';$(\'PrevieIMG\').src=\'/files/avatar/'+pic+'\'; $(\'selectAvatar\').value=\''+pic+'\';resetFile(\'inputAvatar\');Element.hide(\''+tm+'\');" width="90" height="90" border="0"  vspace="5" hspace="5"  />';
		if(i==defaultBgPic.length){
			if( ( (defaultBgPic.length%rowsize) ) ){
				for(j=0; j<rowsize-(defaultBgPic.length%rowsize); j++){
					BoxColor+='<div style="background-color: #efefef; cursor:\'default\' "></div>';
				}
			}
			BoxColor+='</td></tr>';
		}
		else if(i % rowsize==0) BoxColor+='</td></tr><tr><td colspan="2" class="postItcolorSelection">';
		i++
	})
	//defaultBgPic.each(alert('stttt'));
	BoxColor+='</tr>';
	BoxColor+='</table>';
	new Draggable(tm,{revert:false, constraint:'vertical', handle: 'handle'});
	$(tm).innerHTML=BoxColor	
	Element.setStyle(tm, {position:'absolute', display:'block', padding: '0 0 0px', backgroundColor: '#FFFFFF', border:'2px solid #cccccc'});
	var x=(Position.cumulativeOffset(obj)[0]-0)+320-$(tm).offsetWidth;
	var y=Position.cumulativeOffset(obj)[1]-($(tm).offsetHeight/2);
	Element.setStyle(tm, {left: x, top: y});
	Element.show(tm);
}

function showAvatar(PageShow){
//	alert('objid: '+obj.id+' obj_chk: ' + obj_chk+' obj_source: ' + obj_source+' obj_name: ' + obj_name)
	var tm='showAvatar';
	var col=6;
	var i=1;
	var rowsize=6;
	var BoxColor;
	var RecordCount = 12;
	var PageSize = 12;
	var TotalRecordCount = 45;
	if(TotalRecordCount > RecordCount) {
			NoOfPage= Math.ceil(TotalRecordCount/RecordCount);
		} else {
			NoOfPage=1;
		}

	if(PageShow > NoOfPage) { PageShow= NoOfPage; }
		
	
	var RecordStart = ((PageShow-1) * RecordCount)+1;
	var RecordEnd = (RecordStart + RecordCount);
	//alert(RecordStart);
	//alert(RecordEnd);
	if(RecordEnd > TotalRecordCount) RecordEnd = TotalRecordCount;
	var mod_n;
	//BoxColor='<div class="handle" width="60%" align="right"><img src="images/icon/delete.gif" alt="ปิด/Close" onclick="Element.hide('+tm+');" style="cursor:pointer" hspace="5" vspace="5"></div>';
	Element.show(tm);
	BoxColor = "";
	BoxColor+='<table border="0" cellspacing="0" width="60%" cellpadding="0">'
	BoxColor+='<tr>'
	var defaultBgPic=['avatar001.jpg', 'avatar002.jpg', 'avatar003.jpg', 'avatar004.jpg', 'avatar005.jpg', 'avatar006.jpg', 'avatar007.jpg', 'avatar008.jpg', 'avatar009.jpg', 'avatar010.jpg', 'avatar011.jpg', 'avatar012.jpg' ];
	//defaultBgPic.each( function(pic){
	for(n=RecordStart;n<RecordEnd;n++) {	
		pic = 'display'+n+'.gif';
		BoxColor+='<td  class="postItcolorSelection"><img src="http://planet.kapook.com/files/avatar/'+pic+'" id="bgPicView" style="cursor:pointer" onclick="$(\'tblPrevieIMG\').style.display=\'\';$(\'PrevieIMG\').src=\'http://planet.kapook.com/files/avatar/'+pic+'\'; $(\'selectAvatar\').value=\''+pic+'\';resetFile(\'inputAvatar\');Element.hide(\''+tm+'\');" width="90" height="90" border="0"  vspace="5" hspace="5"  /></td>';
		mod_n=i%rowsize;
			       if (i == RecordCount) {
			        	BoxColor+='</tr><tr>';
			        }
			        else  if ( mod_n == 0)
			        	{ 
			        	BoxColor+='</tr>';
			        }  
			
		i++;
	}
	//BoxColor+='</tr>';
	var nextPage = (PageShow+1);
	if (nextPage > NoOfPage) nextPage = NoOfPage;
	var prePage = PageShow-1;
	if (prePage < 1) prePage =1;
	BoxColor+='<tr><td colspan="3" align="left"> <a href="javascript:void(0);" onclick="showAvatar('+prePage+');"> << </a> </td><td colspan="3" align="right"> <a href="javascript:void(0);" onclick="showAvatar('+nextPage+');"> >> </a> </td></tr>';
	BoxColor+='</table>';
	//alert(BoxColor);
	$(tm).innerHTML= BoxColor;	
	
}

function resetFile(objid) {
	//alert(objid);
	$('imgSpan').innerHTML = '<input type="file" name="inputAvatar" id="inputAvatar" onchange="Element.hide(\'t_e_m_p\');tblPrevieIMG_obj=$(\'tblPrevieIMG\');selectAvatar_obj=$(\'selectAvatar\');PrevieIMG_obj=$(\'PrevieIMG\');PrevieIMG_obj.src = \'\';selectAvatar_obj.value = \'\';tblPrevieIMG_obj.style.display = \'none\';" value="">';
	
}
var previoustab=""
function expandcontent(cid, aobject, tabSet,numOfTabs,activeTab){
	if (document.getElementById){
		//switchTab(tabSet,numOfTabs,activeTab) 
		if (previoustab!="") document.getElementById(previoustab).style.display="none"
		document.getElementById(cid).style.display="block"
		previoustab=cid
		if (aobject.blur) aobject.blur()
		return false
	} else return true
}
function switchTab(tabSet,numOfTabs,activeTab){
	alert('tabSet: '+tabSet)
	for (var i=1;i<=numOfTabs;i++) 
	document.getElementById(tabSet + i).className = '';
	var tab = document.getElementById(tabSet + activeTab)
	tab.className = 'inpage';
}
function changProvince(s) {
	province = document.getElementById('inputProvince');
	if(s.value != 210) {
		province.disabled = true;
	} else {
		province.disabled = false;
	}
}