// JavaScript Document
var fileToUse="module/ajax_familyTree.php";
Array.prototype.search=function(value,index){for(i=0;i<this.length;i++){if(isNaN(index)){if(this[i]==value){return i;}}else{if(this[i][index]==value){return i;}}}return -1;};
ie=(document.all)? true:false;
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 fadeUp(Id,step,fps){
	for(var i=0;i<=step;i++){
		setTimeout("fadeOpacity('"+Id+"',"+(Math.round(100/step)*i)+")",i*fps);
	}
};
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 fadeOpacity(Id,Op){
	obj=$(Id);
	if(ie){obj.style.filter="alpha(opacity="+Op+")";}
	else{obj.style.MozOpacity=Op/100;}
}
function checkNodeA(e,f_id,d,m,y,firstDayOfThisMonth,numOfThisMonth,numOfLastMonth,Item,Description,Payment,Amount,Type,keeping_id,action,nameHousekeeping,dateHouse,itemHouse,descriptionHouse,payHouse,typeHouse,amountHouse,incomeHouse,expensHouse){	
	//alert(Description);
	//srcEle=ie?event.srcElement:e.target;
	//alert(srcEle.parentNode.nodeName);
	/*if(srcEle.parentNode.nodeName=="A"){
		top.window.location.replace("housekeeping_show.php?fmb_id="+f_id+"");
		return false;
	}
	if(srcEle.parentNode.nodeName=="LI"){
		
		return false;
	}*/
	loadding(closeManage); 
	addInputHouse(f_id,d,m,y,firstDayOfThisMonth,numOfThisMonth,numOfLastMonth,Item,Description,Payment,Amount,Type,keeping_id,action,nameHousekeeping,dateHouse,itemHouse,descriptionHouse,payHouse,typeHouse,amountHouse,incomeHouse,expensHouse);
	
}
function addInputHouse(f_id,d,m,y,firstDayOfThisMonth,numOfThisMonth,numOfLastMonth,Item,Description,Payment,Amount,Type,keeping_id,action,nameHousekeeping,dateHouse,itemHouse,descriptionHouse,payHouse,typeHouse,amountHouse,incomeHouse,expensHouse){
var	Descrip = Description.replace('<br />','\n');
var html="";
//html+="<dl class=\"popupHouse\">";
html+="<dd class=\"ddTitleInsert\">";
html+="<p class=\"pTitle\">"+nameHousekeeping+"</p>";
html+="<p class=\"pClose\"><a href=\"#\"><img src=\"images/housekeeping/bt_close.gif\" onclick=\"closeManage()\" onmouseover=\"this.src='images/housekeeping/bt_close_over.gif'\" onmouseout=\"this.src='images/housekeeping/bt_close.gif'\" /></a></p>";
html+="</dd>";
html+="<dd class=\"bodyForm\">";
html+="<blockquote class=\"blockquoteHouse\">";
html+="<ul>";
html+="<form name=\"addHouseKeeping\" action=\"accountbook_action.php\" method=\"post\" enctype=\"multipart/form-data\">";
html+="<li class=\"liHouseFile\">";
html+="<p class=\"HouseTopic\">"+dateHouse+"</p>";
html+="<div class=\"inputHouse\">";
html+="<p class=\"boxDay\" id=\"endMonthly\" >"+d+"-"+m+"-"+y+"</p>";
html+="<input type=\"hidden\" name=\"hidEndMonthly\" id=\"hidEndMonthly\" value=\""+y+"-"+m+"-"+d+"\" />";
//html+="<p class=\"inputHouse\"><input name=\"\" type=\"text\" class=\"inputPopup\" /></p>";
html+="<p class=\"iconDay\"><a href=\"#\" onclick=\"createCalendar('radioMonthly','endMonthly','hidEndMonthly','showcalen','"+y+"','"+m+"','"+d+"','"+numOfThisMonth+"','"+numOfLastMonth+"','"+firstDayOfThisMonth+"')\" ><img src=\"images/housekeeping/icon_calendar.gif\" onmouseover=\"this.src='images/housekeeping/icon_calendar_over.gif'\" onmouseout=\"this.src='images/housekeeping/icon_calendar.gif'\" />"+selectDate+"</a></p>";
html+="</div>";
html+="</li>";
html+="<li class=\"liHouseFile\">";
html+="<div class=\"showDate\"  id=\"showcalen\">";
html+="</div>";
html+="</li>";
html+="<li class=\"liHouseFile\">";
html+="<p class=\"HouseTopic\">"+itemHouse+"</p>";
html+="<p class=\"inputHouse\"><input name=\"topic\" type=\"text\" class=\"inputPopup\" value=\""+Item+"\"/></p>";
html+="</li>";
html+="<li class=\"liHouseFile\">";
html+="<p class=\"HouseTopic\">"+descriptionHouse+"</p>";
html+="<p class=\"inputHouse\"><textarea name=\"Description\" cols=\"\" rows=\"\" class=\"textareaPopup\">"+Descrip+"</textarea></p>";
html+="</li>";
html+="<li class=\"liHouseFile\">";
html+="<p class=\"HouseTopic\">"+payHouse+"</p>";
html+="<p class=\"inputHouse\"><input name=\"Payment\" type=\"text\" class=\"inputPopup\"  value=\""+Payment+"\" /></p>";
html+="</li>";
html+="<li class=\"liHouseFile\">";
html+="<p class=\"HouseTopic\">"+typeHouse+"</p>";
html+="<p class=\"boxIN\">";
if(Type=="expense"){
html+="<input name=\"Type\" type=\"radio\" class=\"radio\" value=\"income\" />"+incomeHouse+"";
html+="<input name=\"Type\" type=\"radio\" class=\"radio\" value=\"expenses\" checked=\"checked\" />"+expensHouse+"";
}else{
html+="<input name=\"Type\" type=\"radio\" class=\"radio\" value=\"income\" checked=\"checked\" />"+incomeHouse+"";
html+="<input name=\"Type\" type=\"radio\" class=\"radio\" value=\"expenses\" />"+expensHouse+"";
}
html+="</p>";
html+="</li>";
html+="<li class=\"liHouseFile\">";
html+="<p class=\"HouseTopic\">"+amountHouse+"</p>";
html+="<p class=\"inputHouse\"><input name=\"Amount\" type=\"text\" class=\"inputPopup\"  value=\""+Amount+"\" onkeyup=\"checkNum(Amount)\" /></p>";
html+="</li>";
html+="<input name=\"fmb_id\" type=\"hidden\" value=\""+f_id+"\" />";
html+="<input name=\"keeping_id\" type=\"hidden\" value=\""+keeping_id+"\" />";
html+="<input name=\"action\" type=\"hidden\" value=\""+action+"\" />";
html+="<li class=\"liHouseFile\">";
html+="<p class=\"bt_insert\"><input name=\"\" type=\"submit\" value=\"Save\" class=\"bt_houseLog01\"  onclick=\"return inputNumSubmit()\" />";
html+="<input name=\"\" type=\"reset\" value=\"Clear\" class=\"bt_houseLog01\" />";
html+="</p>";
html+="</li>";
html+="</form>";
html+="	</ul>";
html+="</blockquote>";
html+="</dd>";
//html+="</dl>";
showManageNode=document.createElement('div');	
	showManageNode.className="popupHouse";	
	//showManageNode.style.position="absolute;";	
	showManageNode.setAttribute("id","showManage");	
	showManageNode.innerHTML=html;	
	document.body.appendChild(showManageNode);
	//alert($("showManage").innerHTML);
	if(ie){showManageNode.style.filter="alpha(opacity=0)";}
	else{showManageNode.style.MozOpacity="0";}
	//alert($("showManage").innerHTML);
	setCenter('showManage');
	//alert($("showManage").innerHTML);
	fadeUp('showManage',10,10);

}
function loadding(fnCancel){	
	drawMask(fnCancel);
	loaddingNode=document.createElement('div');
	loaddingNode.setAttribute('id','loadding')
	loaddingNode.style.position="absolute";
	loaddingNode.innerHTML="<img src=\"images/loadding/loading3.gif\" />";
	document.body.appendChild(loaddingNode);
	setCenter('loadding');
	
}

function cancelLoad(){
	document.body.removeChild($('loadding'));
	document.body.removeChild($('mask'));
}
function drawMask(fn){
	html="";
	mask=document.createElement('div');
	mask.setAttribute('id','mask');
	mask.style.left="0px";
	mask.style.top="0px";
	mask.style.position="absolute";
	mask.style.backgroundColor="#000000";
	
	document.body.appendChild(mask);
	mask.style.width=getWindowSizeAll(false)[0]+"px";
	mask.style.height=getWindowSizeAll(false)[1]+"px";
	if(ie){mask.style.filter="alpha(opacity=40)";}
	else{mask.style.MozOpacity=0.4;}
	if(fn){mask.onclick=fn;mask.style.cursor="pointer";}
}
function closeManage(){
	cancelLoad();
	document.body.removeChild($('showManage'));
}
function addCalendar(y,m,d){
	//alert(y+m+d);
	var html="";
	
}
function createCalendar(radio,show,hide,cal,y,m,d,nM,numOfLastMonth,fristDay){
	//alert("Iuput Name");
	$(show).style.display="block";
	Calendar(radio,show,hide,cal,y,m,d,nM,numOfLastMonth,fristDay);
	
}
function Calendar(radio,show,hide,cal,y,m,d,numOfThisMonth,numOfLastMonth,fristDay){
var html="";
var i;
//alert("Iuput Name");
calNode=document.createElement('div');
calNode.setAttribute('id','divcal');
//calNode.style.position="absolute";
		html+="<div id=\"divcal\">";
		html+="<ul class=\"calendar_sd\">";
		html+="<li class=\"headCalendar\">";
		html+="<div class=\"l_arrow\"> <a href=\"#\" onclick=\"backCal('"+radio+"','"+show+"','"+hide+"','"+cal+"','"+y+"','"+m+"','"+d+"','"+numOfThisMonth+"','"+numOfLastMonth+"','"+fristDay+"'); return false;\" ><img src=\"images/schedule/left_arrow.gif\" onmouseover=\"this.src='images/schedule/left_arrow_over.gif'\" onmouseout=\"this.src='images/schedule/left_arrow.gif'\" /></a></div>";
		html+="<div class=\"m_head\">";		
		switch(m){
					case "01":html+="JANUARY";break;
					case "02":html+="FEBUARY";break;
					case "03":html+="MARCH";break;
					case "04":html+="APRIL";break;
					case "05":html+="MAY";break;
					case "06":html+="JUNE";break;
					case "07":html+="JULY";break;
					case "08":html+="AUGUST";break;
					case "09":html+="SEPTEMBER";break;
					case "10":html+="OCTORBER";break;
					case "11":html+="NOVEMBER";break;
					case "12":html+="DECEMBER";break;
		}
		html+="</div>";
		html+="<div class=\"y_head\">"+y+"</div>";
		html+="<div class=\"r_arrow\"><a href=\"#\" ><img src=\"images/schedule/right_arrow.gif\" onclick=\"nextCal('"+radio+"','"+show+"','"+hide+"','"+cal+"','"+y+"','"+m+"','"+d+"','"+numOfThisMonth+"','"+numOfLastMonth+"','"+fristDay+"'); return false;\" onmouseover=\"this.src='images/schedule/right_arrow_over.gif'\" onmouseout=\"this.src='images/schedule/right_arrow.gif'\" /></a></div>";
		html+="</li>";
		html+="<li class=\"dayCalendar\">";
		html+="<p class=\"boxDay_head\">Mo</p>";
		html+="<p class=\"boxDay_head\">Tu</p>";
		html+="<p class=\"boxDay_head\">W</p>";
		html+="<p class=\"boxDay_head\">Th</p>";
		html+="<p class=\"boxDay_head\">Fr</p>";
		html+="<p class=\"boxDay_head\">Sa</p>";
		html+="<p class=\"boxDay_head2\">Su</p>";
		html+="</li>";
		html+="<li class=\"bodyCalendar\">";
		html+="<div class=\"boxSmallCalendar\">";
		switch(fristDay){
				case "0":i="6";break;
				case "1":i="0";break;
				case "2":i="1";break;
				case "3":i="2";break;
				case "4":i="3";break;
				case "5":i="4";break;
				case "6":i="5";break;
		}		
		var lastM="";
		for(lastM=((parseInt(numOfLastMonth)-parseInt(i))+1);lastM<=numOfLastMonth;lastM++){
                  html+="<p class=\"box_pass\">"+lastM+"</p>";
		}	
			for(var thisM=1;thisM<=numOfThisMonth;thisM++){
                  html+="<p class=\"box_w_calendar\"><a href=\"#\" onclick=\"inputDate('"+show+"','"+hide+"','"+cal+"','"+thisM+"','"+m+"','"+y+"'); return false; \">"+thisM+"</a></p>";
			}
	
	var nextM="";
			for(nextM=1;nextM<=(42-(parseInt(numOfThisMonth)+parseInt(i)));nextM++){
                 html+="<p class=\"box_pass\">"+nextM+"</p>";
			 }
	
                html+="</div>";
              html+="</li>";		
		html+="</ul>";		
		html+="</div>";
//document.body.appendChild(calNode);

$(cal).innerHTML=html
}
function nextCal(radio,show,hide,cal,y,m,d,numOfThisMonth,numOfLastMonth,fristDay){
cp.call('module/ajax_schedule2.php','addGetCarlendar',resNextCal,radio,show,hide,cal,y,m,d,numOfThisMonth,numOfLastMonth,fristDay);
}
function resNextCal(result){
	r=eval('('+result+')');
	//alert(r.radio+','+r.show+','+r.hide+','+r.cal+','+r.y+','+r.m+','+r.d+','+r.numOfThisMonth+','+r.numOfLastMonth+','+r.firstDayOfThisMonth);
	Calendar(r.radio,r.show,r.hide,r.cal,r.y,r.m,r.d,r.numOfThisMonth,r.numOfLastMonth,r.firstDayOfThisMonth);
}
function backCal(radio,show,hide,cal,y,m,d,numOfThisMonth,numOfLastMonth,fristDay){
	
cp.call('module/ajax_schedule2.php','addbackGetCarlendar',resBackCal,radio,show,hide,cal,y,m,d,numOfThisMonth,numOfLastMonth,fristDay);
}
function resBackCal(result){
	r=eval('('+result+')');
	Calendar(r.radio,r.show,r.hide,r.cal,r.y,r.m,r.d,r.numOfThisMonth,r.numOfLastMonth,r.firstDayOfThisMonth);
}
function inputDate(show,hide,call,d,m,y){
	if(d.length==1){
		var date="0"+d;		
	}else{
		var date=d;
	}
	$(show).innerHTML=""+y+"-"+m+"-"+date;
	$(hide).value=""+y+"-"+m+"-"+date;
	$(call).innerHTML="";	
}
function changeRepeat(){
	switch($('repeat').value){
		case "0":
				$('reDaily').style.display='none';
				$('reWeekly').style.display='none';
				$('reMonthly').style.display='none';
				$('reYearly').style.display='none';
				$('reEveryWeek').style.display='none';
				$('reEveryHoliday').style.display='none';
				break;
		case "1":
				$('reDaily').style.display='block';
				$('reWeekly').style.display='none';
				$('reMonthly').style.display='none';
				$('reYearly').style.display='none';
				$('reEveryWeek').style.display='none';
				$('reEveryHoliday').style.display='none';
		break;
		case "2":
				$('reDaily').style.display='none';
				$('reWeekly').style.display='block';
				$('reMonthly').style.display='none';
				$('reYearly').style.display='none';
				$('reEveryWeek').style.display='none';
				$('reEveryHoliday').style.display='none';
		break;
		case "3":
				$('reDaily').style.display='none';
				$('reWeekly').style.display='none';
				$('reMonthly').style.display='block';
				$('reYearly').style.display='none';
				$('reEveryWeek').style.display='none';
				$('reEveryHoliday').style.display='none';
		break;
		case "4":
				$('reDaily').style.display='none';
				$('reWeekly').style.display='none';
				$('reMonthly').style.display='none';
				$('reYearly').style.display='block';
				$('reEveryWeek').style.display='none';
				$('reEveryHoliday').style.display='none';
		break;
		case "5":
				$('reDaily').style.display='none';
				$('reWeekly').style.display='none';
				$('reMonthly').style.display='none';
				$('reYearly').style.display='none';
				$('reEveryWeek').style.display='block';
				$('reEveryHoliday').style.display='none';
		break;
		case "6":
				$('reDaily').style.display='none';
				$('reWeekly').style.display='none';
				$('reMonthly').style.display='none';
				$('reYearly').style.display='none';
				$('reEveryWeek').style.display='none';
				$('reEveryHoliday').style.display='block';
		break;
	}	
}
function neverEnd(end,hidEnd,showcal){
	//'endDaily','hidEndDaily'
	$(end).style.display="none";
	$(hidEnd).value="";
	$(showcal).innerHTML="";
}
function checkAllday(){
	if($('boxTime').style.display=='block'){
		$('boxTime').style.display="none";	
	}else{
		$('boxTime').style.display="block";		
	}

}
function checkDataSchedule(){
	if(s_what=$('s_what').value==""){alert("Please, Insert Data"); return false;}		
}
function checkNum(obj){
    var patt1=new RegExp("[\\D]");
    if(patt1.test(obj.value)){
      alert('Only Number');
	//var text=obj.value;
	//var Tsub=obj.value.length;
	//alert(text.substring(0,Tsub-1));
      obj.value = obj.value.substring(0,obj.value.length-1);
    }
  }

/*

*/

