// ---------------------------------------------------
// settings
miniForms = new Array("frmLogin","frmSignup","frmForgotPassword","frmTodosAdd","frmTodosEdit","frmClassAdd","frmClassEdit","frmSettings","frmFilesUpload", "frmScheduleAdd");
nonHidingSelectBoxes = new Array("signup_timezone","todosadd_class", "todosadd_date_day","todosadd_date_month","todosadd_date_year","todosadd_date_class","todosadd_reminder","todosadd_remindday","todosedit_date_day","todosedit_date_month","todosedit_date_year","todosedit_date_class","todosedit_reminder","todosedit_remindday","todosedit_class", "classadd_color","classedit_color","settings_timezone","upload_class");
// ---------------------------------------------------

onerror=handleError;

function handleError(a,b,c,d,e)
{
	txt="";
	txt+="There is an error in mySchoolog JS library.\n";
	txt+="\/\/ --------------------------------------------------- \/\/\n";
	txt+="Error: " + a + "\n";
	txt+="URL: " + b + "\n";
	txt+="Line: " + c + "\n";
	txt+="\/\/ --------------------------------------------------- \/\/\n";
	txt+="No problem, be cool ;) Only click OK to continue.";
alert(txt); 
}

// ---------------------------------------------------
// mySchoolog NiftyCube Builder

function mySchoologNifty(){
		Nifty('div.nbig','big transparent');
		Nifty('div.nnormal','normal transparent');
		Nifty('div.nsmall','small transparent');
		Nifty('div.mini','big transparent');
}

// ---------------------------------------------------

function formHideElements(formid){
	//alert("inputs and other elements are hiding on form."+formid);
	inputsToHide=Form.getElements(formid);
	//alert(print_r(inputsToHide7));
	for (ii = 0; ii < inputsToHide.length; ii++) {
		 $(inputsToHide[ii]).hide();
	}
}

// ---------------------------------------------------

function formShowElements(formid){
	//alert("inputs and other elements are showing on form."+formid);
	inputsToShow=Form.getElements(formid);
	//alert(print_r(inputsToShow));
	for (ii = 0; ii < inputsToShow.length; ii++) {
		$(inputsToShow[ii]).show();
	}
}

// ---------------------------------------------------

function print_r(objArray){
	var arrReturn='';
	for (arrTurn=0; arrTurn<objArray.length; arrTurn++)
	{
		arrReturn += objArray[arrTurn];
			if (arrTurn!=((objArray.length)-1))
			{
			arrReturn +=',';
			}
	}
	return arrReturn;
}
// ---------------------------------------------------

function findForms(objElement){
	if (objElement==''||objElement==null){
		objSelector=document; } else { objSelector=$(objElement);}
	
	arrForms=objSelector.getElementsByTagName("form");
	return arrForms;
}
// ---------------------------------------------------

var openedWindows;
openedWindows = new Array();
function removeopenedWindows(removingWindow) {
		openedWindows.splice(openedWindows.indexOf(removingWindow),1);
}
// ---------------------------------------------------

function getParentElementsByTagName(objElement,strTag) {
	if (objElement==''||objElement==null){
		objSelector=document; } else { objSelector=$(objElement);}

	if (strTag==''||strTag==null){
		strTag=''; }

	return objSelector.getElementsByTagName(strTag);
}


// ---------------------------------------------------

function disableInput(objInput) {
	objInput=$(objInput);

	if (objInput.disabled==false)
	{ objInput.disabled=true; }
	else { objInput.disabled=false; }

}

// ---------------------------------------------------
function center(element,zindex){
	
		element = $(element);

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
		my_width  = window.innerWidth;
		my_height = window.innerHeight;
    }else if ( document.documentElement && 
		     ( document.documentElement.clientWidth ||
		       document.documentElement.clientHeight ) ){
		my_width  = document.documentElement.clientWidth;
		my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
		    ( document.body.clientWidth || document.body.clientHeight ) ){
		my_width  = document.body.clientWidth;
		my_height = document.body.clientHeight;
    }
	
    element.style.position = 'absolute';
    element.style.zIndex   = zindex;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
		scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
		scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
		scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
		scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;
	//alert("window:"+my_width+"*"+my_height+"\ndiv:"+elementDimensions.width+"*"+elementDimensions.height+"\nresult:"+setX+"*"+setY+"\n");

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

}
// ---------------------------------------------------

function miniwindow(objWindow,openingForm){
	if (openingForm.length>0)
	{
	formShowElements(openingForm);
	setTimeout('Form.focusFirstElement(\''+openingForm+'\')',430);
	// CAUTION: this milisecond value must be higher than value of appearance effects.
	// CAUTION: first element must be visible, otherwise an error occurs in MSIE6
	}
	//alert("miniwindow is showing:"+objWindow);
	//Element.setStyle('overlay','width: document.body.clientWidth')
	
	$('overlay').style.width = document.body.clientWidth.toString()+"px"; 
	$('overlay').style.height = document.body.clientHeight.toString()+'px'; // gerek yok?
	$('overlay').style.zIndex = '90';
	//center('overlay',90);

		new Effect.Appear('overlay', { duration: 0.3, from: 0.0, to: 0.9 });
		//openedWindows.splice(0,0,'overlay');

    center(objWindow,990);
		new Effect.Appear(objWindow, { duration: 0.4, from: 0.0, to: 1 });
		openedWindows.splice(0,0,(objWindow));
		//alert("miniwindow finished. open windows:"+openedWindows);

	hideSelectBoxes();
	//alert("miniwindow oldu ve "+Element.visible('overlay'));
}

// ---------------------------------------------------

function hideBox(objWindow,closingForm){

		new Effect.Appear(objWindow, { duration: 0.2, from: 1, to: 0 });
		setTimeout('$(\''+objWindow+'\').style.zIndex =\'-5\'',250);
		removeopenedWindows(objWindow);

		new Effect.Fade('overlay', { duration: 0.2, from: 0.9, to: 0 });

	//alert("hideboxes is hiding:"+closingForm);


		if (closingForm.length>0)
		{
		t_fH=setTimeout('formHideElements(\''+closingForm+'\')',250);
		}


		t_OH=setTimeout('$(\'overlay\').hide()',250);
		showSelectBoxes();
		//alert("hidebox gerçekleştirildi ve "+Element.visible('overlay'));
}
// ---------------------------------------------------

function hideBoxes(){

	//alert("hideboxes are starting! opened windows: "+openedWindows);
	for (closingdivs=0; closingdivs<openedWindows.length ;closingdivs++ )
	{
		//alert("turning!!:"+closingdivs);
		//alert("hideboxes is hiding:"+closingdivs+"["+openedWindows[closingdivs]+"]");
			new Effect.Appear($(openedWindows[closingdivs]), { duration: 0.2, from: 1, to: 0 });
			setTimeout('$(\''+openedWindows[closingdivs]+'\').style.zIndex =\'-5\'',250);
	}

	openedWindows.clear();
	//alert("hideboxes finished.. open windows: "+openedWindows);

	new Effect.Fade('overlay', { duration: 0.2, from: 0.9, to: 0 });

	for (af=0; af<miniForms.length; af++ )
	{	
		if ($(miniForms[af]))
		{
			setTimeout('formHideElements(\''+miniForms[af]+'\')',100);
			//alert("hideboxes is hiding form:"+$(miniForms[af]).id);
		}		
	}

	setTimeout('showSelectBoxes()',100); ;
	setTimeout('$(\'overlay\').hide()',250);
	//alert("hideboxes gerçekleşti ve "+Element.visible('overlay'));
    //$('overlay').hide();
	//alert(Element.getStyle('overlay','display'));
}

// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		if(nonHidingSelectBoxes.indexOf(selects[i].id)==-1){
			//alert("selectbox is showing! : "+selects[i].id);
		selects[i].style.visibility = "visible";
		}
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		if(nonHidingSelectBoxes.indexOf(selects[i].id)<0){
			selects[i].style.visibility = "hidden";
		}
	}
}

// ---------------------------------------------------

function loading(divLoading,strAction){

	if (divLoading==''||divLoading==null)
	{
		divLoading='mainloading'
	}

	objLoading = $(divLoading);

	if (objLoading!==undefined)
	{

		if (strAction=='' || strAction==null || strAction=='show')
		{
			//new Effect.Pulsate(divLoading,{pulses:1, duration:0.7 });
			//new Effect.Appear(divLoading, { duration: 0.25, from: 0, to: 1});
			if (!(objLoading.visible()))
			{ objLoading.show(); }
		} else {
			setTimeout("objLoading.hide();",50);
			//new Effect.Fade(divLoading, { duration: 0.5, from: 1, to: 0 });
			//objLoading.hide();
		}
	}
}

// ---------------------------------------------------

function switchWindow(swWindow,swForm) {
	hideBoxes();
	setTimeout('miniwindow(\''+swWindow+'\',\''+swForm+'\')',600);
}

// ---------------------------------------------------

function myStatus(){

var stat='';

stat += "opened windows : "+print_r(openedWindows)+"\n";
statPageDivs=getParentElementsByTagName('','div');
for(statDivs=0 ; statDivs<statPageDivs.length ; statDivs++ )
{
	statId=statPageDivs[statDivs].id
		if (statId.length>0) { stat += "div#"+statPageDivs[statDivs].id+": "+Element.getStyle(statPageDivs[statDivs],'width')+"*"+Element.getStyle(statPageDivs[statDivs],'height')+" z:"+Element.getStyle(statPageDivs[statDivs],'z-index')+" vis:"+Element.visible(statPageDivs[statDivs])+" \n"; }
}

statPageForms=getParentElementsByTagName('','form');
for(statForms=0 ; statForms<statPageForms.length ; statForms++ )
{
	statFId=statPageForms[statForms].id
		if (statFId.length>0) { stat += "form#"+statPageForms[statForms].id+": z:"+Element.getStyle(statPageForms[statForms],'z-index')+" vis:"+Element.visible(statPageForms[statForms])+" \n"; }
}


stat += "\n";


stat += "window.innerWidth : "+window.innerWidth+"\n";
stat += "window.innerHeight : "+window.innerHeight+"\n";


stat += "document.documentElement.clientWidth : "+document.documentElement.clientWidth+"\n";
stat += "document.documentElement.clientHeight : "+document.documentElement.clientHeight+"\n";


stat += "document.body.clientHeight : "+document.body.clientHeight+"\n";
stat += "document.body.clientWidth : "+document.body.clientWidth+"\n";

alert(stat);

}

// ---------------------------------------------------

function mkLogin() {
	disableInput('login_submit');
	loading('','show');
	xajax_login(xajax.getFormValues('frmLogin'));

}

// ---------------------------------------------------

function mkSignup() {
	disableInput('signup_submit');
	loading('','show');
	xajax_signup(xajax.getFormValues('frmSignup'));
}

// ---------------------------------------------------

function mkForgotPassword() {
	disableInput('forgotpassword_submit');
	loading('','show');
	xajax_forgotpassword(xajax.getFormValues('frmForgotPassword'));
}

// ---------------------------------------------------

function mkContact() {
	disableInput('contact_submit');
	loading('','show');
	xajax_contact(xajax.getFormValues('frmContact'));
}

// ---------------------------------------------------

function mkSettings() {
	disableInput('settings_submit');
	loading('','show');
	xajax_settings(xajax.getFormValues('frmSettings'));
}


// ---------------------------------------------------

var tDYK_hide;
var tDYK_init;
var tDYK_restart;
var tDYK_show;

function showDYK() {
	new Effect.Appear('dyk', { duration: .5});
	tDYK_hide = setTimeout('hideDYK(1)',8500);
}

function hideDYK(act) {
	new Effect.Fade('dyk', { duration: .5});

	if (act==1)
	{
	tDYK_restart = setTimeout('startDYK()',10000);
	}

}

function startDYK() { xajax_dyk('show'); }

function DYKinit() { //setTimeout("startDYK();",5000); 
}

function clearDYKS() {
	clearTimeout(tDYK_hide);
	clearTimeout(tDYK_init);
	clearTimeout(tDYK_restart);
	clearTimeout(tDYK_show);
}

function exitDYK() {
	hideDYK(0);
	clearDYKS();
	$('cntdyk').hide();
	xajax_dyk('exit');
}

// ---------------------------------------------------
var t_mSS;
function mkSuggestSchool(place) {
	if (t_mSS) { clearTimeout(t_mSS); }
	t_mSS = setTimeout("loading('suggestschool_loading','show');xajax_suggestschool($F('"+place+"_school'),'"+place+"');", 350);
}


// ---------------------------------------------------


// ---------------------------------------------------


// ---------------------------------------------------


// ---------------------------------------------------


// ---------------------------------------------------


// ---------------------------------------------------
/*
function MM_preloadimage() { //v3.0
  var d=document; if(d.image){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadimage.arguments; for(i=0; i<a.length; i )
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j ].src=a[i];}}
}
*/