// JavaScript Document
window.onload = function() {
    $$('.grid tr').each(function(e,i){
        if((i%2==0) && (!(e.hasClass('buttons') || e.hasClass('ignore')))) e.addClass('alt');
    });

    $$('input').each(function(e,i){
        if((e.getProperty('type')=="text") || (e.getProperty('type')=="password"))
            e.addClass('text');
    });
    $$('a').each(function(e,i){
        if((e.getProperty('rel')!=null) && (e.getProperty('rel')=='popup')){
            e.onclick = function(){
                openPopup1(e.href);
                return false;
            }
        } else if((e.getProperty('rel')!=null) && (e.getProperty('rel')=='popup2')){
            e.onclick = function(){
                openPopup2(e.href);
                return false;
            }
        } else if((e.getProperty('rel')!=null) && (e.getProperty('rel')=='popup3')){
            e.onclick = function(){
                openPopup3(e.href);
                return false;
            }
        } else if((e.getProperty('rel')!=null) && (e.getProperty('rel')=='popup4')){
            e.onclick = function(){
                openPopup4(e.href);
                return false;
            }
        }
    });
    $$('.fadinglink').each(function(e,i){
        e.t = $(e).effects({duration:200});
        e.setStyle('opacity', 0.6);
        e.onmouseover = function(){
            e.t.stop();
            e.t.start({'opacity':1});
        }
        e.onmouseout = function(){
            e.t.stop();
            e.t.start({'opacity':0.6});
        }
    });
    $$('.faq .item').each(function(e,i){
        e.opened = false;
        e.getElement('h5').addEvent('click', function(){
            this.getParent().opened = !this.getParent().opened;
            this.getParent().getElement('.desc').setStyle('display', this.getParent().opened?'block':'none');
        });
    });
    $$('#topmenu ul li ul').each(function(e){
        e.getParent().getElement('a').submenu = e;
        e.getParent().getElement('a').addEvent('mouseenter', function(){
            this.submenu.setStyle('display', 'block');
            $clear(this.submenutimer);
        });
        e.getParent().getElement('a').addEvent('mouseleave', function(){
            this.submenutimer = function(){ this.submenu.setStyle('display', 'none')}.bind(this).delay(500);
        });
        e.addEvent('mouseenter', function(){
            $clear(this.getParent().getElement('a').submenutimer);
        });
        e.addEvent('mouseleave', function(){
            this.getParent().getElement('a').submenutimer = function(){ this.submenu.setStyle('display', 'none')}.bind(this.getParent().getElement('a')).delay(500);
        });
    });
    $$('.editinplace').each(function(e){
        e.getElement('input[type=button]').addEvent('click', function(){
            e.getElement('input[type=submit]').setStyle('display', 'inline');
            e.getElement('input.cancel').setStyle('display', 'inline');
            this.setStyle('display', 'none');
            f = e.getElement('.field');
            e.getElements('.field').removeProperty('disabled');
            if(f.tagName=='select')
                f.initialValue = f.selectedIndex;
            else
                f.initialValue = f.value;
        });
        e.getElement('input.cancel').addEvent('click', function(){
            e.getElement('input[type=submit]').setStyle('display', 'none');
            this.setStyle('display', 'none');
            e.getElement('input[type=button]').setStyle('display', 'inline');
            f = e.getElement('.field');
            e.getElements('.field').setProperty('disabled','disabled');
            if(f.tagName=='select')
                f.selectedIndex = f.initialValue;
            else
                f.value = f.initialValue;
        });
    });
	showTime();
}

function setAction(action){
    if(action=='next'){
        document.forms[0].method.value="save";
        document.forms[0].submit();
    }
    if(action=='reset'){
        document.forms[0].reset();
    }
}

function setParam(paramName, val) {
    var f = document.forms[0];
    f[paramName].value = val;
}

function checkButtonDisablity(checks, butt) {
    var dis = 'disabled';
    for(var i=0; i<checks.length; i++) {
        if(checks[i].checked) {
            dis = '';
            break;
        }
    }
    butt.disabled = dis;
}

function setMethodAndSubmit(val) {
    var f = document.forms[0];
    f['method'].value = val;
    f.submit();
}

function confirmForDelete(value) {
    if(confirm("Are you sure?")) {
        setMethodAndSubmit(value)
    }
}

function submitParentAndClose(val) {
    var f = window.opener.document.forms[0];
    f['method'].value=val;
    f.submit();
    window.close();
}

function openPopupT(url, w, h, s){
    window.open(url,"mcm_popup","statusbar=no, menubar=no, width=" + w + ", height=" + h + ", scrollbars=" + s);
    return false;
}
function openPopup(url, w, h){
	return openPopupT(url, w, h, "no");
}
function openPopup1(url){
    window.open(url,"mcm_popup1","statusbar=no, menubar=no, width=700, height=900, scrollbars=yes");
    return false;
}
function openPopup2(url){
    window.open(url,"mcm_popup2","statusbar=no, menubar=no, width=300, height=220, scrollbars=yes");
    return false;
}
function openPopup3(url){
    window.open(url,"mcm_popup3","statusbar=no, menubar=no, width=700, height=1500, scrollbars=yes");
    return false;
}
function openPopup4(url){
    window.open(url,"mcm_popup4","statusbar=no, menubar=no, width=700, height=550, scrollbars=yes");
    return false;
}
function openPopup5(url){
    window.open(url,"mcm_popup5","statusbar=no, menubar=no, width=300, height=320, scrollbars=yes");
    return false;
}
function getValue(elementID)
{
	return document.getElementById(elementID).value;
}

function showTime()
{
	var date			=	new String(getValue('date'));
	var dateArray		=	new Array();
	dateArray			=	date.split('/');
	var day				=	new Number(dateArray[0]);
	var month			=	new Number(dateArray[1]);
	var year			=	new Number(dateArray[2]);
	
	if(year%4 == 0)
		var numDays			=	new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	else
		var numDays			=	new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
	var now				=	new String(getValue('now'));
	var timeArray		=	new Array();
	timeArray			=	now.split(":");
	var hour			=	new Number(timeArray[0]);
	var minute			=	new Number(timeArray[1]);
	var second			=	new Number(timeArray[2]);
	
	second				+=	1;
	if(second == 60)
	{
		second			=	0;
		minute			+=	1;
		if(minute == 60)
		{
			minute		=	0;
			hour		+=	1;
			if(hour == 24)
			{
				hour	=	0;
				day		+=	1;
				if(day > numDays[month-1])
				{
					day		=	1;
					month	+=	1;
					if(month == 13)
					{
						month	=	1;
						year	+=	1;
					}
				}
			}
		}
	}
	
	if(hour < 10)
		hour			=	String('0'+hour)
	if(hour == 0)
		hour			=	String('00');
		
	if(minute < 10)
		minute			=	String('0'+minute)
	if(minute == 0)
		minute			=	String('00');
		
	if(second < 10)
		second			=	String('0'+second)
	if(second == 0)
		second			=	String('00');
	
	if(day < 10)
		day				=	String('0'+day);
	if(month < 10)
		month				=	String('0'+month);
	
	date				=	day+'/'+month+'/'+year;
	now					=	hour+':'+minute+':'+second;
	
	var newDate			=	new Date(month+'/'+day+'/'+year);
	var dayNumber		=	new String(newDate.getDay());
	
	var dayOfWeek		=	new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
	var monthName		=	new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	
	document.getElementById('time').innerHTML = String(dayOfWeek[dayNumber]+'&nbsp;'+day+'&nbsp;-&nbsp;'+monthName[Number(month)-1]+'&nbsp;-&nbsp;'+year+'&nbsp;&nbsp;'+now);
	document.getElementById('date').value = date;
	document.getElementById('now').value = now;
	
	setTimeout("showTime()", 1000);
}
