// JavaScript Document
var fileToUse="../module/ajax_newdiary.php";
function $$(id){return document.getElementsByName(id);};

function getWindowSizeAll(a){var myWidth=0,myHeight=0;if(typeof(window.innerWidth)=='number'){scrollSize=16;myWidth=(a)?window.innerWidth:window.screen.width;myHeight=(a)?window.innerHeight:document.body.parentNode.scrollHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth=(a)?document.documentElement.clientWidth:document.body.offsetWidth;myHeight=(a)?document.documentElement.clientHeight:document.body.parentNode.scrollHeight;scrollSize=2;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth=(a)?document.body.clientWidth:document.body.offsetWidth;myHeight=(a)?document.body.clientHeight:document.body.offsetHeight;scrollSize=2;}return[myWidth-scrollSize,myHeight];}
function getScrollXY(){var scrOfX=0,scrOfY=0;if(typeof(window.pageYOffset)=='number'){scrOfY=window.pageYOffset;scrOfX= window.pageXOffset;}else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){scrOfY=document.body.scrollTop;scrOfX=document.body.scrollLeft;}else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){scrOfY=document.documentElement.scrollTop;scrOfX=document.documentElement.scrollLeft;}return[scrOfX,scrOfY];}
function $(id){return document.getElementById(id);};
function spacialTag(txt){txt=txt.replace(/>/g,'&gt;');txt=txt.replace(/</g,'&lt;');return txt;}
function spacialChar(txt){txt=txt.replace(/\\u000a|\\u000d/g," ");txt=txt.replace(/\\u0026/g,"&");return txt;}
function getDataNode(p,t){try{return p.getElementsByTagName(t)[0].firstChild.nodeValue;}catch(e){return "";}};
function setCenter(id){$(id).style.left=((getWindowSizeAll(true)[0]-$(id).offsetWidth)/2+getScrollXY()[0])+"px";$(id).style.top=((getWindowSizeAll(true)[1]-$(id).offsetHeight)/2+getScrollXY()[1])+"px";};

function drawMask(fn){
	html="";
	mask=document.createElement('div');
	mask.setAttribute('id','mask');
	mask.style.left="0px";
	mask.style.top="0px";
	mask.style.bottom="0px";
	mask.style.position="absolute";
	mask.style.backgroundColor="#000000";
	
	document.body.appendChild(mask);
	mask.style.width=getWindowSizeAll(true)[0]+"px";
	mask.style.height=getWindowSizeAll(true)[1]+"px";
	if(ie){mask.style.filter="alpha(opacity=40)";}
	else{mask.style.opacity=0.4;}
	if(fn){mask.onclick=fn;mask.style.cursor="pointer";}
}
function fadeUp(Id,step,fps){
	for(var i=0;i<=step;i++){
		setTimeout("fadeOpacity('"+Id+"',"+(Math.round(100/step)*i)+")",i*fps);
	}
};
function fadeOpacity(Id,Op){
	obj=$(Id);
	if(ie){obj.style.filter="alpha(opacity="+Op+")";}
	else{obj.style.MozOpacity=Op/100;}
}
function loadding(fnCancel){
	drawMask(fnCancel);
	loaddingNode=document.createElement('div');
	loaddingNode.setAttribute('id','loadding')
	loaddingNode.style.position="absolute";
	loaddingNode.innerHTML="<img src=\"../images/icon/loading_2.gif\" />";
	document.body.appendChild(loaddingNode);
	setCenter('loadding');
}
function cancelLoad(){
	document.body.removeChild($('loadding'));
	document.body.removeChild($('mask'));
}
function closeManage(){
	cancelLoad();
	document.body.removeChild($('showManage'));
}

<!--     ------log in--------     -->

function loginBlog(pathLogin,fmb_id){
	loadding(closeManage); 
	inputlogin(pathLogin,fmb_id);	
}
function inputlogin(pathLogin,fmb_id){
var html="";
	
	html+="<form name=\"LogIn\" action=\""+pathLogin+"\" method=\"post\" enctype=\"multipart/form-data\" >";
	html+="<dd class=\"bodyForm2\"><ul>";
	html+="<li class=\"liHouseFile2\"><p class=\"pTitle\">Please, Log in again.</p>";
	html+="<p class=\"pClose\"><img src=\"../images/icon/icon_close.gif\" onmouseout =\"this.src='../images/icon/icon_close.gif'\" onmouseover =\"this.src='../images/icon/icon_close_over.gif'\" onclick =\"closeManage()\" /></p></li>";
	html+="<li class=\"liHouseFile2\"><p class=\"houseTopic2\">Username:</p><input name=\"txt_username\" type=\"text\" /></li>";
	html+="<li class=\"liHouseFile2\"><p class=\"houseTopic2\">Password:</p><input name=\"txt_password\" type=\"password\" /></li>";
	html+="<li class=\"liRemember\"><input name=\"\" type=\"button\" value=\"Login\" class=\"bt_edit3\" onclick=\"return inputCheckSubmit("+fmb_id+")\" /></li>";
	html+="</ul></dd>";
	html+="</form>";
		
	showManageNode=document.createElement('div');	
	showManageNode.className="popupHouse";		
	showManageNode.setAttribute("id","showManage");	
	showManageNode.innerHTML=html;	
	document.body.appendChild(showManageNode);
	if(ie){showManageNode.style.filter="alpha(opacity=0)";}
	else{showManageNode.style.MozOpacity="0";}
	setCenter('showManage');
	fadeUp('showManage',10,10);

}
function inputCheckSubmit(fmb_id){
	   if(document.getElementsByName("txt_username")[0].value==""){
	   	 document.getElementsByName("txt_username")[0].focus();
	   	alert("Iuput Username");
	   	return false;
	   }else if(document.getElementsByName("txt_password")[0].value==""){
	   	 document.getElementsByName("txt_password")[0].focus();
	   	alert("Iuput Password");
	   	return false;
	   }else{
		   ajaxAddDiary(fmb_id)
		//document.forms.LogIn.submit();
	   }
}



/*-------------Diary-------------*/
function ajaxSaveDiary(fmb_id){
	hWup=$$("hWup")[0].value;				mWup=$$("mWup")[0].value;
	wUap=$$("wUap")[0].value;				hBed=$$("hBed")[0].value;
	mBed=$$("mBed")[0].value;				bEdap=$$("bEdap")[0].value;
	txtB=$$("txtB")[0].value;				txtL=$$("txtL")[0].value;
	txtS=$$("txtS")[0].value;				algTxt=$$("algTxt")[0].value;
	dTopic=$$("dTopic")[0].value;			areaDetail=$$("areaDetail")[0].value;
	colorA1=$$("colorA1")[0].value;			dAir=$$("dAir")[0].value;
	dEmo=$$("dEmo")[0].value;				dStatus=$$("dStatus")[0].value;
	dateCreate=$$("dateCreate")[0].value;	imgDiary=$$("imgDiary").value;
	temp=$$("temp")[0].value;
	
	dAir=document.getElementById("airVarChk").value;
	dEmo=document.getElementById("emoVarChk").value;	
	dStatus=document.getElementById("dStatusChk").value;	
	
	cp.call(fileToUse,'addDiary',resAddDiary,fmb_id,hWup,mWup,wUap,hBed,mBed,bEdap,txtB,txtL,txtS,algTxt,dTopic,areaDetail,colorA1,dAir,dEmo,dStatus,dateCreate,imgDiary,temp);
}
function resAddDiary(result){
	dateCreatelink=$$("dateCreatelink")[0].value;
	rObj=eval('('+result+')');
	if(rObj.add==1){
		alert("Save Done");
		window.location.replace("diary_show.php?fmb_id="+rObj.sesuserID+"&"+dateCreatelink);
	}else{
		alert("Error");
	}
}
function ajaxAddDiary(fmb_id){
	hWup=$$("hWup")[0].value;				mWup=$$("mWup")[0].value;
	wUap=$$("wUap")[0].value;				hBed=$$("hBed")[0].value;
	mBed=$$("mBed")[0].value;				bEdap=$$("bEdap")[0].value;
	txtB=$$("txtB")[0].value;				txtL=$$("txtL")[0].value;
	txtS=$$("txtS")[0].value;				algTxt=$$("algTxt")[0].value;
	dTopic=$$("dTopic")[0].value;			areaDetail=$$("areaDetail")[0].value;
	colorA1=$$("colorA1")[0].value;			dAir=$$("dAir")[0].value;
	dEmo=$$("dEmo")[0].value;				dStatus=$$("dStatus")[0].value;
	dateCreate=$$("dateCreate")[0].value;	imgDiary=$$("imgDiary").value;
	temp=$$("temp")[0].value;
	
	cp.call(fileToUse,'add2Diary',resAdd2Diary,fmb_id,hWup,mWup,wUap,hBed,mBed,bEdap,txtB,txtL,txtS,algTxt,dTopic,areaDetail,colorA1,dAir,dEmo,dStatus,dateCreate,imgDiary,temp);
}
function resAdd2Diary(result){
	dateCreatelink=$$("dateCreatelink")[0].value;
	rObj=eval('('+result+')');
	if(rObj.add==1){
		//alert("Save Done");
		window.location.replace("diary_edit.php?fmb_id="+rObj.sesuserID+"&diaId="+rObj.diaID+"&diaD="+rObj.dateD+"&diaY="+rObj.dateY+"&diaM="+rObj.dateM);
	}else{
		alert("Error");
	}
}


