NS = (document.layers) ? 1 : 0;
IE = (document.all) ? 1 : 0;

function IsLeap(year) {
	return( 0 == year % 4 && (( year % 100 != 0 ) || ( year % 400 == 0 )) );
}

function opencal(a,f,flag){
	var frm=document.forms[f];

	var day=frm['day'+a].options[frm['day'+a].options.selectedIndex].value;

	var month = 1;
	var year  = 1;

	if (frm['monthyear'+a]){
		a1=frm['monthyear'+a].options[frm['monthyear'+a].options.selectedIndex].value;
		a2=a1.split('-');
		month = a2[0];
		year  = a2[1];
	}else{
		month=frm['month'+a].options[frm['month'+a].options.selectedIndex].value;
		year=frm['year'+a].options[frm['year'+a].options.selectedIndex].value;
	}

	if (flag=='')
		flag=0;
	var x='/calendar.php?datefirld='+a+'&form='+f+'&day='+day+'&month='+month+'&year='+year+'&flag='+flag;

   window.open(x,"new","resizable=yes,width=220,height=240,left=50,top=50");
   //window.open(x,"new");
}

function setdate(a,b,d,m,y,flag){
	//alert(flag);
	var frm=document.forms[b];
	if (flag==1)
		frm['day'+a].options.selectedIndex=d;
	else
		frm['day'+a].options.selectedIndex=d-1;

	if (frm['monthyear'+a]){
		for (i=0; i<frm['monthyear'+a].options.length; i++){
			if (frm['monthyear'+a].options[i].value==m + '-' + y){
				if (flag)
				frm['monthyear'+a].options.selectedIndex=i-1;
				else
				frm['monthyear'+a].options.selectedIndex=i;
				break;
			}
		}
	}else{
		if (flag =='1')
		frm['month'+a].options.selectedIndex=m;
		else
		frm['month'+a].options.selectedIndex=m-1;
		

		for (i=1;i<frm['year'+a].options.length;i++){
			if (frm['year'+a].options[i].value==y){
				if (flag)
				frm['year'+a].options.selectedIndex=i;
				else
				frm['year'+a].options.selectedIndex=i;
				break;
			}
		}
	}

	if (a=='_'){
		makediffer(b);
	}
}

function makediffer(b){
	var frm=document.forms[b];
	var d1=frm['day_'].options.selectedIndex+(b=='forma'?7:1)+1;
	var m1=frm['month_'].options.selectedIndex+1;
	var y1=frm['year_'].options.selectedIndex;
	var y2=frm['year_'].options[y1].value;
	var mntl = new Array;
	mntl[1]=31;
	mntl[2]=(IsLeap(y2)?29:28);
	mntl[3]=31;
	mntl[4]=30;
	mntl[5]=31;
	mntl[6]=30;
	mntl[7]=31;
	mntl[8]=31;
	mntl[9]=30;
	mntl[10]=31;
	mntl[11]=30;
	mntl[12]=31;

	if (d1>mntl[m1]){
		d1=d1%mntl[m1];
		m1++;
		if (m1>12){
			m1=m1%12;
			y1++;
		}
	}

	frm['day__'].options.selectedIndex=d1-1;
	if (frm['month_']){
		frm['month__'].options.selectedIndex=m1-1;
		frm['year__'].options.selectedIndex=y1;
	}

}

function popwindow (file)
{
	window.open(file, "_new", "width=800,height=600,scrollbars=1")
}


function setStyleOver(item){
    document.getElementById(item).style.backgroundColor='#C20000';
    
}
function setStyleOut(item){
    //document.getElementById(item).className="menuitem";
     document.getElementById(item).style.backgroundColor='';
}
function setStyle1Over(item){
    document.getElementById(item).style.backgroundColor='#E4C6C6';
    
}
function setStyle1Out(item){
    document.getElementById(item).style.backgroundColor='#C6D7E4';
}
function setStyle2Out(item){
    document.getElementById(item).style.backgroundColor='';
}


// open classic popup window
var win_array = [];
function openWin(loc, winName, winWidth, winHeight, winParams){
   if (!win_array[winName]) win_array[winName] = null;
   if (!win_array[winName] || (win_array[winName] && win_array[winName].closed)){
      if (winParams=='full'){
         winParams = 'resizable=yes,menubar=yes,status=yes,toolbar=yes,titlebar=yes,location=yes,directories=yes,scrollbars=yes';
      }
      win_array[winName] = window.open(loc, winName, "width="+winWidth+",height="+winHeight+","+winParams);
   }

   win_array[winName].location = loc;
   win_array[winName].focus();
}


function checkEnter(E){
    var ev = (typeof E != "undefined" ? E : event);
    if (ev.keyCode==13) return false
    return true;
}
