function checkalldays(i,totald,fieldname)
{
	var m=0, d=0;
	m=document.getElementById(fieldname+'[month]['+i+']');
	if (m && m.checked)
	{
		for(var j=1;j<=totald;++j)
		{
			d=document.getElementById(fieldname+'[day]['+i+']['+j+']');
			if (d) d.checked=true;
		}
	}
	else if(m)
	{
		for(var j=1;j<=totald;++j)
		{
			d=document.getElementById(fieldname+'[day]['+i+']['+j+']');
			if (d) d.checked=false;
		}
	}
}

function disabledElement(id)
{
	document.getElementById(id).disabled=true;
}

function enabledElement(id)
{
	document.getElementById(id).disabled=false;
}

/* IE use - drop down menu */
IEMhover = function() {
	if (document.getElementById('menunav'))
	{
		var IEMh = document.getElementById('menunav').getElementsByTagName('li');
		for (var i=0; i<IEMh.length; i++)
		{
			IEMh[i].onmouseover=function(){this.className+=' iemhover';}
			IEMh[i].onmouseout=function(){this.className=this.className.replace(new RegExp(' iemhover\\b'), '');}
		}
	}
}
if (window.attachEvent) window.attachEvent('onload', IEMhover);

function show(id)
{
	document.getElementById(id).style.display="block";
}

function hide(id)
{
	document.getElementById(id).style.display='none';
}

function trimAll(sString)
{
	// left trim
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	// right trim
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return trim(sString);
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function checkAll(object, name, id, total)
{
	for(var i=1; i<=total; ++i)
	{
		var objcity=document.getElementById(name+"["+id+"]["+i+"]");
		if (object.checked) objcity.checked=true;
		else objcity.checked=false;
	}
	objcity=document.getElementById(name+"["+id+"]["+total+"]");
	displayTextbox(objcity, id, total);
}
function checkTips(object, name, id, total)
{
	var n;
	n=0;
	for(var i=1; i<=total; ++i)
	{
		var objcity=document.getElementById(name+"["+id+"]["+i+"]");
		if (objcity.checked) ++n;
	}
	if (total == n) object.checked=true;
	else object.checked=false;
	
	objcity=document.getElementById(name+"["+id+"]["+total+"]");
	displayTextbox(objcity, id, total);
}
function displayTextbox(object, id, total)
{
	var otherbox=document.getElementById("Others["+id+"]");
	var objbox = document.getElementById("Others["+id+"]["+total+"]");
	if (object.checked)
	{
		if (otherbox)
		{
			otherbox.style.display='block';
			objbox.select();
		}
	}
	else 
	{
		if (otherbox) otherbox.style.display='none';
	}
}
function refreshing(url)
{
	window.location=url;
}
function existing(file,labelfield)
{
	alert("The "+labelfield+" was already exists!");
	window.location=file;
}

function noenter(id,e)
{
	var objwordcount=document.getElementById('wordcount_'+id);
	var code=0;
	if (objwordcount && objwordcount.innerHTML<1)
	{
		if(window.event) code = e.keyCode;
		else if(e.which) code = e.which;
	
		{
		e.returnValue = false;
		}
		return false;
	}
}
var words='';
function wordCount(id,numwords,e,typecount)
{
	var txt=document.getElementById('field_'+id);
	var objwordcount=document.getElementById('wordcount_'+id);
	var objwordtext=document.getElementById('word');
	var fieldvalue=trimAll(txt.value);
	
	if (typecount=='char')
	{
		var valuelength=fieldvalue.length;
		if (objwordcount && valuelength>numwords)
		{
			if (window.event) code=e.keyCode;
			else if (e) code=e.which;
			if (code!=8) txt.value=words.substr(0);
		}
		else
		{
			if (fieldvalue=='')
			{
				objwordcount.innerHTML=numwords;
				objwordtext.innerHTML='&nbsp;Chars';
			}
			else if (objwordcount.innerHTML <=1)
			{
				objwordcount.innerHTML=numwords - valuelength;
				objwordtext.innerHTML='&nbsp;Char';
			}
			else
			{
				objwordcount.innerHTML=numwords - valuelength;
				objwordtext.innerHTML='&nbsp;Chars';
			}
		}
	}
	else
	{
		fieldvalue.replace(/  /,' ');
		var valuelength=fieldvalue.split(' ').length;
		if (objwordcount && valuelength>numwords)
		{
			if (window.event) code=e.keyCode;
			else if (e) code=e.which;
			if (code!=8) txt.value=words.substr(0);
		}
		else
		{
			if (fieldvalue=='')
			{
				objwordcount.innerHTML=numwords;
				objwordtext.innerHTML='&nbsp;Words';
			}
			else if (objwordcount.innerHTML <=1)
			{
				objwordcount.innerHTML=numwords - valuelength;
				objwordtext.innerHTML='&nbsp;Word';
			}
			else
			{
				objwordcount.innerHTML=numwords - valuelength;
				objwordtext.innerHTML='&nbsp;Words';
			}
		}
	}
	words=txt.value;
}
function selectAll(total)
{
	for(var i=0; i<total; ++i)
	{
		var selecteach=document.getElementById('list_'+i);
		if (document.getElementById('selectall').checked)
		{
			selecteach.checked=true;
			document.getElementById('trlist_'+i).style.backgroundColor='#f3dada';;
		}
		else
		{
			selecteach.checked=false;
			document.getElementById('trlist_'+i).style.backgroundColor='#fff';;
		}
	}
}

function clickthisrow(thisid)
{
	if (thisid>=0)
	{
		var selectrow=document.getElementById('list_'+thisid);
		if (selectrow.checked)
		{
			selectrow.checked=false;
			document.getElementById('trlist_'+thisid).style.backgroundColor='#fff';;
		}
		else
		{
			selectrow.checked=true;
			document.getElementById('trlist_'+thisid).style.backgroundColor='#f3dada';;
		}
	}
}

function selectthis(total)
{
	var selectall=document.getElementById('selectall');
	var count=0;
	for(var i=0; i<total; ++i)
	{
		if (document.getElementById('list_'+i).checked)
		{
			if (document.getElementById('trlist_'+i))
				document.getElementById('trlist_'+i).style.backgroundColor='#f3dada';;
			++count;
		}
		else
		{
			document.getElementById('trlist_'+i).style.backgroundColor='#fff';;
		}
	}
	if (total==count) selectall.checked=true;
	else selectall.checked=false;
}
function checkdeleteselected(total,thisform)
{
	var count=0;
	for(var i=0; i<total; ++i)
	{
		if (document.getElementById('list_'+i).checked==false) ++count;
	}
	if (total==count)
	{
		alert('Please select at lease one!');
		return false;
	}
	else
	{
		if (confirm('Are you sure?'))
		{
			document.forms[thisform].submit();
			return true;
		}
		else return false;
	}
}

function add_pfile(id, i, label) 
{
if (label==null || label=='') label='Picture';
if (document.getElementById(id + '_' + i))
	document.getElementById(id + '_' + i).innerHTML = '<input type="text" name="captions['+ (i+1) +']" class="field_input_text" value="'+label+' '+(i+1)+'">&nbsp;&nbsp;Image Caption<br style="clear:left;"><input type="text" name="url['+ (i+1) +']" class="field_input_text" value="">&nbsp;&nbsp;URL Link<br style="clear:left;"><input type="file" name="' + id + '['+ (i+1) +']" class="field_input_file" onchange="return add_pfile(\'' + id + '\', ' + (i+1) + ', \''+label+'\');"><br style="clear:left"><span id="'+ id +'_'+(i+1)+'"></span>\n';
}

function add_mfile(id, i, label) 
{
if (label==null || label=='') label='File';
if (document.getElementById(id + '_' + i))
	document.getElementById(id + '_' + i).innerHTML = '<input type="text" name="captions['+ (i+1) +']" class="field_input_text" value="'+label+' '+(i+1)+'">&nbsp;&nbsp;File Caption<br style="clear:left;"><input type="text" name="url['+ (i+1) +']" class="field_input_text" value="">&nbsp;&nbsp;URL Link<br style="clear:left;"><input type="file" name="' + id + '['+ (i+1) +']" class="field_input_file" onchange="return add_mfile(\'' + id + '\', ' + (i+1) + ', \''+label+'\');"><br style="clear:left"><span id="'+ id +'_'+(i+1)+'"></span>\n';
}

function add_mdata(id, i, label) 
{
if (label==null || label=='') label='Data';
if (document.getElementById(id + '_' + i))
	{
	document.getElementById(id + '_' + i).innerHTML = '<input type="text" name="'+id+'['+ (i+1) +'][label]" id="'+id+'['+ (i+1) +'][label]" class="field_input_text" value="'+label+' '+(i+1)+'">&nbsp;&nbsp;Label Text<br style="clear:left;"><input type="text" name="'+id+'['+ (i+1) +'][value]" id="'+id+'['+ (i+1) +'][value]" class="field_input_text" value="">&nbsp;&nbsp;Value Text&nbsp;&nbsp;<input type="button" name="button['+ (i+1) +']" id="button['+ (i+1) +']" class="field_input_submit" value="Done" onclick="return add_mdata(\'' + id + '\', ' + (i+1) + ', \''+label+'\');"><br style="clear:left"><br style="clear:left;"><span id="'+ id +'_'+(i+1)+'"></span>\n';
	}
}

function displayimg(src, alt, h)
{
	if (document.getElementById('displayimage'))
	{
		document.getElementById('displayimage').innerHTML='<img src="'+src+'" alt="'+alt+'">';
		document.getElementById('displayimage').style.height=h+'px';
	}
}

var dir='', prevID=0, nextID=0, stoppnum1=0, stoppnum2=0, mytime1='', mytime2='';

function initialize(command,gettype,total)
{
	startslideshow(command,gettype,total);
}

function actionfor(gettype,command,total) // for click
{
	if (command>0)
	{
		if (gettype=='topbanner')
		{
			stoppnum1=command;
			clearTimeout(mytime1);
			startslideshow(command,gettype,total);
			acting(gettype,command,total);
		}
		if (gettype=='flashbanner')
		{
			stoppnum2=command;
			clearTimeout(mytime2);
			startslideshow(command,gettype,total);
			acting(gettype,command,total);
		}
	}
}

function acting(gettype,command,total)
{
// alert(command+':'+gettype);
	for(var i=1;i<=total;++i)
	{
		var getid=document.getElementById(gettype+'_'+i);
		var getpageid=document.getElementById('page_'+gettype+'_'+i);
		if (getid)
		{
			if (i==command)
			{
				getid.style.display='block';
				if (getpageid) getpageid.className='pagenumnav selected';
			}
			else
			{
				getid.style.display='none';
				if (getpageid) getpageid.className='pagenumnav';
			}
		}
	}
}

function stopslideshow(gettype,spnum)
{
	if (gettype=='topbanner')
	{
		clearTimeout(mytime1);
		stoppnum1=spnum;
	}
	if (gettype=='flashbanner')
	{
		clearTimeout(mytime2);
		stoppnum2=spnum;
	}
}

function startslideshow(command,gettype,total) // for auto slide
{
	// alert(command+' : '+gettype);
	if (stoppnum1>0)
	{
		clearTimeout(mytime1);
		command=stoppnum1;
		stoppnum1=0;
	}
	if (stoppnum2>0)
	{
		clearTimeout(mytime2);
		command=stoppnum2;
		stoppnum2=0;
	}
	if (command>total) command=1;
	acting(gettype,command,total);
	if (gettype=='topbanner') mytime1=setTimeout('startslideshow('+(command+1)+',\''+gettype+'\','+total+')',7000);
	if (gettype=='flashbanner') mytime2=setTimeout('startslideshow('+(command+1)+',\''+gettype+'\','+total+')',10000);
}