// JavaScript Document

function ClearTextBox(id,deval){	//when we focus on the text box

	var val=document.getElementById(id).value;

	if (val==deval){

		document.getElementById(id).style.color="#000";

		document.getElementById(id).value="";

	}else{

		document.getElementById(id).style.color="#000";

	}

}



function ResetTextBox(id,deval){	//when we blur on the text box

	var val=document.getElementById(id).value;

	if (val==""){

		document.getElementById(id).value=deval;

		document.getElementById(id).style.color="#ccc";

	}else{

		document.getElementById(id).style.color="#000";

	}

}



function getdatas(url,divName){

	var xmlhttp;

	xmlhttp=GetXmlHttpObject();	

	if (xmlhttp == null){

	  alert ("Your browser does not support XMLHTTP!");

	  return;

	}

	

	xmlhttp.onreadystatechange=function StateChanged(){		

		if (xmlhttp.readyState==4){

		  document.getElementById(divName).innerHTML=xmlhttp.responseText;

		}

	}

	xmlhttp.open("GET",url,true);

	xmlhttp.send(null);	

}



function GetXmlHttpObject(){

	if (window.XMLHttpRequest){

	  // code for IE7+, Firefox, Chrome, Opera, Safari

	  return new XMLHttpRequest();

	}

	if (window.ActiveXObject){

	  // code for IE6, IE5

	  return new ActiveXObject("Microsoft.XMLHTTP");

	}

	return null;

}



function submitform(id,url){

	//alert(id+" : "+url);

	document.getElementById(id).action=url;

	document.getElementById(id).submit();

}





function message(id){



	var answer;

	answer=confirm("Do you want to be disable this  user ");

	if(answer){

		document.location.href="delete_user.php?id=" + id ;

	}

	else{

	document.location.href="#";

	}

	

}

function validate_control(){

	var username=document.getElementById("idusername").value;

	var passwords=document.getElementById("idpassword").value;

	//var email=document.getElementById("idemail").value;

	var value=true;

	if(username==""){

		document.getElementById("errorusername").innerHTML="<font color='red'>Please, Input The UserName</font>";

		value= false;

	}

	else{

		document.getElementById("errorusername").innerHTML="";

	}

	

	if(passwords==""){

		document.getElementById("errorpassword").innerHTML="<font color='red'>Please, Input The Password</font>";

		value= false;

	}

	else{

		document.getElementById("errorpassword").innerHTML="";

	}

	return value;

}



function ChnageBackground(id,color){

	document.getElementById(id).style.backgroundColor=color;

}



function RedirectURL(url){

	document.location.href=url;

}



function ChangeClassName(NameClass,id){

	document.getElementById(id).className=NameClass;

}





function ChangeImage(id,value){

	document.getElementById(id).style.opacity=value;

}



function SubmitForm(formid,url){

	document.getElementById(formid).action=url;

	document.getElementById(formid).submit();

}





function Calendar(calevents){

	for (var i=0;i<calevent.length;i++){

		alert("Hello");

	}

}



function DaysOfMonth(month,year){

	if ((month==4)||(month==6)||(month==9)||(month==11)){

		return 30;

	}else if (month!=2){

		return 31;

	}else if (((year%4==0)&&(year%100 != 0) ) || (year%400==0)){

		return 29;

	}else{

		return 28;

	}

}



function GetFullMonth(index){

	//alert(index);

	montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

	return montharray[index-1];

}



function Convert2Digit(num){

	if (num<10){

		return "0"+num;

	}

	return num;

}







function DisplayCalendar(month,year){

	var premonth=month-1;

	var preyear=year;

	var nextmonth=month+1;

	var nextyear=year;

	if (premonth==0){
		premonth=12;
		preyear=year-1;
	}
	

	if (nextmonth>12){
		nextmonth=1;
		nextyear=year+1;
	}
	

	var nbday=DaysOfMonth(month,year);

	

	var CalHTML="<table cellspacing='0' class='calendarleft'><tr><td colspan='7' class='tabhead'><div class='premonth'><a href='javascript:DisplayCalendar("+premonth+","+preyear+")'><img src='images/leftcal.gif' border='0' width='21' height='20' /></a></div><div class='labelmonth'><a href='calendar-event.php?pageid=3&subpageid=48'>"+GetFullMonth(month)+" "+year+"</a></div><div class='nextmonth'><a href='javascript:DisplayCalendar("+nextmonth+","+nextyear+")'><img src='images/rightcal.gif' width='21' height='20' border='0' /></a></div></td></tr>";

	// style='float:left; margin-left:3px;'(Premonth)        style='float:left; font-size:12px; width:120px;'(label)           style='float:left;'(nerxtmonth)

	// style='background:#C7D0DB; padding-bottom:0px; padding-top:3px; text-align:center;'(tabhead)

	CalHTML+="<tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr>";

	

	var temdate=new Date(year+"/"+month+"/1");

	var startday=temdate.getDay();

	var nbdaypre=DaysOfMonth(premonth,preyear);

	

	//alert(year+" : "+month+" : "+temdate.getDay());

	CalHTML+="<tr>";

	

	var newrow=1;

	for (var i=(startday-1);i>=1;i--){

		CalHTML+="<td style='color:#999;'>"+(nbdaypre-i+1)+"</td>";

		newrow++;

	}

	

	var datenow=new Date();

	var daynow=datenow.getDate();

	var monthnow=datenow.getMonth()+1;

	var yearnow=datenow.getFullYear();

	var edate="";

	for (var i=1;i<=nbday;i++){

		edate=year+"-"+Convert2Digit(month)+"-"+Convert2Digit(i);

		if (newrow==8){

			CalHTML+="<tr>";

			newrow=1;

		}

		if (daynow==i && monthnow==month && yearnow==year){

			CalHTML+="<td";

			if (events[edate]!=undefined){

				CalHTML+=" class='date_has_event'";

			}else{

				CalHTML+=" class='today'";

			}

			CalHTML+=">"+i+"";

			// class="date_has_event"

			if (events[edate]!=undefined){

				CalHTML+=events[edate];

			}

			CalHTML+="</td>";

		}else{

			//alert(edate+" : "+events['"'+edate+'"']);

			CalHTML+="<td";

			if (events[edate]!=undefined){

				//alert("Hello");

				CalHTML+=" class='date_has_event' onmouseover=\"mouseoverevent();\"";

				// onmouseover=\"mouseoverevent('Hello')\"

			}

			CalHTML+=">"+i+"";

			if (events[edate]){

				//alert("sdfasdfadf");

				CalHTML+=events[edate];

			}

			CalHTML+="</td>";

		}

		

		if (newrow==8){

			CalHTML+="</tr>";

		}

		newrow++;

	}

	

	var count=1;

	for (i=newrow;i<8;i++){

		CalHTML+="<td style='color:#999;'>"+count+"</td>";

		if (newrow==8){

			CalHTML+="</tr>";

		}

		count++;

	}

	CalHTML+="</table>";

	//document.write(CalHTML);

	document.getElementById("leftcalendar").innerHTML=CalHTML;

}





function mouseoverevent(){

	$('.date_has_event').each(function () {

		// options

		var distance = 0;//10;

		var time = 0;//250;

		var hideDelay = 0;//500;



		var hideDelayTimer = null;



		// tracker

		var beingShown = false;

		var shown = false;



		var trigger = $(this);

		var popup = $('.events ul', this).css('opacity', 0);

		

		// set the mouseover and mouseout on both element

		$([trigger.get(0), popup.get(0)]).mouseover(function () {

			// stops the hide event if we move from the trigger to the popup element

			if (hideDelayTimer) clearTimeout(hideDelayTimer);



			// don't trigger the animation again if we're being shown, or already visible

			if (beingShown || shown) {

				return;

			} else {

				beingShown = true;

				//var winH = $(window).height()/2+$(id).height;

				//var winW = $(window).width()/2-$(id).width;

				// reset position of popup box

				popup.css({

					bottom: -140,

					left: 30,

					display: 'block' // brings the popup back in to view

				})



				// (we're using chaining on the popup) now animate it's opacity and position

				.animate({

					bottom: '+=' + distance + 'px',

					opacity: 1

				}, time, 'swing', function() {

					// once the animation is complete, set the tracker variables

					beingShown = false;

					shown = true;

				});

			}

		}).mouseout(function () {

			// reset the timer if we get fired again - avoids double animations

			if (hideDelayTimer) clearTimeout(hideDelayTimer);



			// store the timer so that it can be cleared in the mouseover if required

			hideDelayTimer = setTimeout(function () {

				hideDelayTimer = null;

				popup.animate({

					bottom: '-=' + distance + 'px',

					opacity: 0

				}, time, 'swing', function () {

					// once the animate is complete, set the tracker variables

					shown = false;

					// hide the popup entirely after the effect (opacity alone doesn't do the job)

					popup.css('display', 'none');

				});

			}, hideDelay);

		});

	});

}









function DisplayCalendar1(month,year){

	var premonth=month-1;

	var preyear=year;

	var nextmonth=month+1;

	var nextyear=year;

	if (premonth==0){

		premonth=12;

		preyear=year-1;

	}

	

	if (nextmonth>12){

		nextmonth=1;

		nextyear=year+1;

	}

	

	var nbday=DaysOfMonth(month,year);

	

	var CalHTML="<table cellspacing='0' class='calendarleft'><tr><td colspan='7' class='tabhead'><div class='premonth'><a href='javascript:DisplayCalendar("+premonth+","+preyear+")'><img src='images/leftcal.gif' border='0' width='21' height='20' /></a></div><div class='labelmonth'><a href='calendar-event.php?pageid=3&subpageid=48'>"+GetFullMonth(month)+" "+year+"</a></div><div class='nextmonth'><a href='javascript:DisplayCalendar("+nextmonth+","+nextyear+")'><img src='images/rightcal.gif' width='21' height='20' border='0' /></a></div></td></tr>";

	// style='float:left; margin-left:3px;'(Premonth)        style='float:left; font-size:12px; width:120px;'(label)           style='float:left;'(nerxtmonth)

	// style='background:#C7D0DB; padding-bottom:0px; padding-top:3px; text-align:center;'(tabhead)

	CalHTML+="<tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr>";

	

	var temdate=new Date(year+"/"+month+"/1");

	var startday=temdate.getDay();

	var nbdaypre=DaysOfMonth(premonth,preyear);

	

	//alert(year+" : "+month+" : "+temdate.getDay());

	CalHTML+="<tr>";

	

	var newrow=1;

	for (var i=(startday-1);i>=1;i--){

		CalHTML+="<td style='color:#999;'>"+(nbdaypre-i+1)+"</td>";

		newrow++;

	}

	

	var datenow=new Date();

	var daynow=datenow.getDate();

	var monthnow=datenow.getMonth()+1;

	var yearnow=datenow.getFullYear();

	var edate="";

	for (var i=1;i<=nbday;i++){

		edate=year+"-"+Convert2Digit(month)+"-"+Convert2Digit(i);

		if (newrow==8){

			CalHTML+="<tr>";

			newrow=1;

		}

		if (daynow==i && monthnow==month && yearnow==year){

			CalHTML+="<td";

			if (events[edate]!=undefined){

				CalHTML+=" class='date_has_event'";

			}else{

				CalHTML+=" class='today'";

			}

			CalHTML+=">"+i+"";

			// class="date_has_event"

			if (events[edate]!=undefined){

				CalHTML+=events[edate];

			}

			CalHTML+="</td>";

		}else{

			//alert(edate+" : "+events['"'+edate+'"']);

			CalHTML+="<td";

			if (events[edate]!=undefined){

				//alert("Hello");

				CalHTML+=" class='date_has_event' onmouseover=\"mouseoverevent1();\"";

				// onmouseover=\"mouseoverevent1('Hello')\"

			}

			CalHTML+=">"+i+"";

			if (events[edate]){

				//alert("sdfasdfadf");

				CalHTML+=events[edate];

			}

			CalHTML+="</td>";

		}

		

		if (newrow==8){

			CalHTML+="</tr>";

		}

		newrow++;

	}

	

	var count=1;

	for (i=newrow;i<8;i++){

		CalHTML+="<td style='color:#999;'>"+count+"</td>";

		if (newrow==8){

			CalHTML+="</tr>";

		}

		count++;

	}

	CalHTML+="</table>";

	//document.write(CalHTML);

	document.getElementById("leftcalendar").innerHTML=CalHTML;

}





function mouseoverevent1(){

	$('.date_has_event').each(function () {

		// options

		var distance = 0;//10;

		var time = 0;//250;

		var hideDelay = 0;//500;



		var hideDelayTimer = null;



		// tracker

		var beingShown = false;

		var shown = false;



		var trigger = $(this);

		var popup = $('.events ul', this).css('opacity', 0);

		

		// set the mouseover and mouseout on both element

		$([trigger.get(0), popup.get(0)]).mouseover(function () {

			// stops the hide event if we move from the trigger to the popup element

			if (hideDelayTimer) clearTimeout(hideDelayTimer);



			// don't trigger the animation again if we're being shown, or already visible

			if (beingShown || shown) {

				return;

			} else {

				beingShown = true;

				//var winH = $(window).height()/2+$(id).height;

				//var winW = $(window).width()/2-$(id).width;

				// reset position of popup box

				popup.css({

					bottom:1 ,

					left: 10,

					border:1,

					display: 'block' // brings the popup back in to view

					

				})



				// (we're using chaining on the popup) now animate it's opacity and position

				.animate({

					bottom: '+=' + distance + 'px',

					opacity: 1

				}, time, 'swing', function() {

					// once the animation is complete, set the tracker variables

					beingShown = false;

					shown = true;

				});

			}

		}).mouseout(function () {

			// reset the timer if we get fired again - avoids double animations

			if (hideDelayTimer) clearTimeout(hideDelayTimer);



			// store the timer so that it can be cleared in the mouseover if required

			hideDelayTimer = setTimeout(function () {

				hideDelayTimer = null;

				popup.animate({

					bottom: '-=' + distance + 'px',

					opacity: 0

				}, time, 'swing', function () {

					// once the animate is complete, set the tracker variables

					shown = false;

					// hide the popup entirely after the effect (opacity alone doesn't do the job)

					popup.css('display', 'none');

				});

			}, hideDelay);

		});

	});

}
