function ViewSelect(el,type){
	MNM.the_type = type;
	if(MNM.$)
		MNM.$.className='tab';
	MNM.$=el||{};
	el.className='tab tab-sel';
	Refresh();
	return true;
}
function ChangeContest(el,id){
	MNM.the_one = id;
	if(!MNM.the_type)MNM.the_type='show';
	if(MNM._)
		MNM._.className='';
	MNM._=el||{};//No nulls allowed
	el.className='sel';
	Refresh();
	return true;
}

function Refresh(){
	targ = _x_(MNM.the_type+MNM.the_one);
	if(targ){
		if(MNM.last_rent)
			MNM.last_rent.parentNode.style.display = (MNM.last_rent.style.display='none');
		MNM.last_rent = targ;
		targ.parentNode.style.display = (targ.style.display = 'block');
		//MNM.last_rent.style.position = 'relative';
		var to = targ.id.substr(0,4);
		if (targ.src=='javascript:')targ.src = '/contest/' + to +"/"+targ.id.substr(4)+(to=='vote'?"/"+MNM.the_email:"/1");
	}
}


var 
_x_=function(_){return document.getElementById(_)}

,_y_=function(_){return MNM.x[_];}

;

function proto(){
	this.x = this.all;
	this.type = 0;
	this.maxIndex = 111;
	var types = {
			'Contest Details':(proto.prototype.CURRENT=1)
			,'Model Ranks':(proto.prototype.WON=2)
			,'Vote Now!':(proto.prototype.HISTORY=3)
			//,'Upcoming Contests':(proto.prototype.UPCOMING=4)
	};
	this.parseType = function(name){
		return types[name]||name;
	};
	var wsLead = /^(\s*)/, wsTrail = /(\s*)$/;
	this.trim = function(val){
		return val.replace(wsLead,'').replace(wsTrail,'');
	}
};

proto.prototype.setType = function(to){
	var next = this.type;
	this.type = this.parseType(to);
	return (this.type!=next);
};

var MNM = new proto();

delete proto;

proto = function(){
	ContestTypeClick(_x_('y')); 
	return ContestChoiceClick(_x_('x'));
}

function ContestClick(){
	if(MNM.$)
		MNM.$.className='tab';
	MNM.$=this||{};
	this.className='tab tab-sel';
	if (MNM.setType(this.innerText || this.textContent))
	{
		DisplayContest();
	}
	return true;
}

function DisplayContest(){
	if(MNM.type&&MNM.cur)
	switch(MNM.parseType(MNM.type)){
	case MNM.CURRENT:
		_x_('xContestTable').style.display = 'block';
		_x_('xWinTable').style.display = 'none';
		_x_('xVoteTable').style.display = 'none';
		return;
	case MNM.WON:
		_x_('xContestTable').style.display = 'none';
		_x_('xWinTable').style.display = 'block';
		_x_('xVoteTable').style.display = 'none';
		return;
	case MNM.HISTORY:
		_x_('xContestTable').style.display = 'none';
		_x_('xWinTable').style.display = 'none';
		_x_('xVoteTable').style.display = 'block';
		return;
	}
}

function ContestChoiceClick(el){
	if(MNM._)
		MNM._.className='';
	MNM._=el||{};//No nulls allowed
	MNM._.className='sel';
	var name = MNM.trim(MNM._.innerText || MNM._.textContent);//Make IE happy...
	if(!name)return true;//This is an error; shouldn't happen

	MNM.cur=_y_(name);//Parse out the text name of the contest and retrieve from data store
	
	DisplayContest();
	return true;
}

function dateUnload(el,cal){
	el.style.display='none';
	el.nextSibling.style.display='none';
	el.previousSibling.style.display='block';
	(el=el.previousSibling.previousSibling).disabled=0;
	el.value=parseDate(window[el.name].getSelectedDates()[0]);
}
function dateLoad(el,btn){
	if(!btn)el=el.nextSibling;
	el.style.display='none';
	el.nextSibling.style.display='block';
	el.nextSibling.nextSibling.style.display='block';	
	el=el.previousSibling;
	el.disabled=1;console.log(el,el.value);
	window[el.id].select(el.value);
	window[el.id].render();
}
function parseDate(time){
da = new Date(time);
dy = da.getFullYear();
dm = da.getMonth() + 1;
dd = da.getDate();
if ( dy < 1970 ) dy = dy + 100;// We still have to fix the millennium bug
ys = new String(dy);
ms = new String(dm);	 
ds = new String(dd); 	 
if ( ms.length == 1 ) ms = "0" + ms;// Add leading zeros to month and date if required
if ( ds.length == 1 ) ds = "0" + ds; 	 
return ms+"/"+ds+"/"+ys;
}


