var fadeFilter="progid:DXImageTransform.Microsoft.RandomDissolve";
//hide every second table row


window.onload=init;

var browserIdx=1;


if((navigator.userAgent.indexOf('MSIE')!=-1)&(navigator.userAgent.indexOf('Opera')==-1)){
	--browserIdx;

}



var gblVars=new Array();
var images=new Array();

images[0]=new Image;
images[0].src="images/up_arrow.gif";

images[1]=new Image;
images[1].src="images/down_arrow.gif";



function hideRows(){

var menu=document.getElementById('MainMenu');
var childRows=menu.getElementsByTagName('TR');


	for(var x=0;x<childRows.length;x++){
	    if(childRows[x].className=="sub"){
		childRows[x].style.display="none";
	    }
	}

// Now change images

	for(var x=0;x<childRows.length;x++){
	    if(childRows[x].className=="main"){

		if((navigator.userAgent.indexOf('MSIE')!=-1)&(navigator.userAgent.indexOf('Opera')==-1)){
			var imgObj=childRows[x].childNodes[1].firstChild;
		} else{
			var imgObj=childRows[x].childNodes[3].firstChild;
		}

		imgObj.src=images[1].src;
		//alert(imgObj.className);
	    }
	}


}


function showRows(){

var menu=document.getElementById('MainMenu');
var childRows=menu.getElementsByTagName('TR');


	for(var x=0;x<childRows.length;x++){
	    if(childRows[x].className=="sub"){
		childRows[x].style.display="";
	    }
	}

}


function expandRow(arg){

   if((navigator.userAgent.indexOf('MSIE')!=-1)&(navigator.userAgent.indexOf('Opera')==-1)){
	
       if(arg.nextSibling.style.display=="none"){
		//hideRows();
		arg.nextSibling.style.display=""
		//gblVars[3]=arg.nextSibling;        	
		//mainfadeUpByObj(gblVars[3]);
		//window.setTimeout('gblVars[3].style.display="";',700);
		arg.childNodes[1].firstChild.src=images[0].src;
	} else {
        	arg.nextSibling.style.display="none";
		//gblVars[3]=arg.nextSibling;   
		//mainfadeOutByObj(arg.nextSibling);
		//window.setTimeout('gblVars[3].style.display="none";',700);
		arg.childNodes[1].firstChild.src=images[1].src;

	}

	//get the triangle image handle



   } else {

	var imgObj=arg.childNodes[3].firstChild;
   // alert(arg.nextSibling.nextSibling.tagName);
    
	if(arg.nextSibling.nextSibling.style.display=="none"){
		//hideRows();
       	arg.nextSibling.nextSibling.style.display="";
		imgObj.src=images[0].src;
		
	} else {
    
		arg.nextSibling.nextSibling.style.display="none";
		imgObj.src=images[1].src;
	}

   }

}



function mo(arg){
	//alert(arg.tagName);

	if(browserIdx == 0){
	
		gblVars[0]=arg.className;
		arg.className="subMo";
		//change over the hyperlink class name too
		gblVars[1]=arg.childNodes[1].childNodes[0].className;
		arg.childNodes[1].childNodes[0].className = "menub"

		//change yellow bar sideBoxOn
		gblVars[2]=arg.childNodes[0].className
		arg.childNodes[0].className="sideBoxOn";
		info.innerHTML=arg.childNodes[1].childNodes[0].innerHTML;
	
	} else {
		
		gblVars[0]=arg.className;
		arg.className="subMo";
		
		gblVars[1]=arg.childNodes[3].childNodes[1].className;
		arg.childNodes[3].childNodes[1].className="menub"
	}
}



function mout(arg){
	if(browserIdx == 0){
		
		arg.className=	gblVars[0];
		
		//change back hyperlink
		arg.childNodes[1].childNodes[0].className = gblVars[1];
		arg.childNodes[0].className = gblVars[2];
		info.innerHTML="&nbsp";
		
	} else {
	
		arg.className=	gblVars[0];
	
		arg.childNodes[3].childNodes[1].className=gblVars[1];
		
	}
}


function checkDDState(){

	var menu=document.getElementById('MainMenu');
	var childRows=menu.getElementsByTagName('TR');

	//======================================
	//check drop down icon is correct
	//======================================

	for(var x=0;x<childRows.length;x++){
	    if(childRows[x].className=="main"){

		//now check the next sibling to see if it is open
  	        var imgObj=childRows[x].childNodes[1].firstChild;

	  if(browserIdx == 0){
		if(childRows[x].nextSibling.style.display=="") {
		   	imgObj.src=images[0].src;						

		} else {

		   	imgObj.src=images[1].src;		
		}
       } else {
				//alert(childRows[x].childNodes.length);
			if(childRows[x].nextSibling.nextSibling.style.display=="") {
				imgObj.src=images[0].src;						

			} else {

				imgObj.src=images[1].src;		
			}
	   	   
	   }
	    }
	}


}


function init(){
	checkDDState();
	//hideRows();



}


function mainfadeUpById(id){
    if(browserIdx==0){
	document.getElementById(id).style.filter=fadeFilter;
	document.getElementById(id).filters[0].Apply();
	document.getElementById(id).style.visibility='visible';
	document.getElementById(id).filters[0].Play();
    } else {
	document.getElementById(id).style.visibility='visible';
    }
}

function mainfadeUpByObj(obj){
    if(browserIdx==0){
	obj.style.filter=fadeFilter;
	obj.filters[0].Apply();
	obj.style.visibility='visible';
	obj.filters[0].Play();
    } else {
	obj.style.visibility='visible';
    }
}


function mainfadeOutByObj(obj){
    if(browserIdx==0){
	obj.style.filter=fadeFilter;
	obj.filters[0].Apply();
	obj.style.visibility='hidden';
	obj.filters[0].Play();
    } else {
	obj.style.visibility='hidden';
    }
}

function checkForFile(){
	var obj=document.getElementById('NewFile');

	if(obj.value==""){
		alert('no file selected');
		return false;
	} else {
		return true;
	}
	
}


function _mover(arg){
	arg.className="menu_hover";
}

function _mouseout(arg){
	arg.className="menu";
}




function previewDisplay(){

	var obj1=document.getElementById('eventDetails');
	var obj2=document.getElementById('preview');
	//alert(obj1.value);
	var tmp=obj1.value.replace(/{data}/gi,dataStg);
	var tmp=tmp.replace(/{title}/gi,titleStg);
	var tmp=tmp.replace(/{location}/gi,locationStg);
	var tmp=tmp.replace(/{date}/gi,dateStg);
	
	obj2.innerHTML=tmp;
	
	window.setTimeout('previewDisplay()',1000);

}


function polechars(){
//check no characters to detect for back space
var objs=document.getElementsByTagName("TEXTAREA");

//alert(objs.length);



//alert(_form.elements.length);

for(var x=0;x<objs.length;x++){

	var chars=objs[x].value.length
	var txt=objs[x].parentNode.childNodes[2];
	
	alert(txt.innerHTML);
	
	if(txt.id.indexOf('description')==-1){
	
		if(chars <= 250 ){
			txt.innerHTML=(250-chars)+" Characters Left";
		} else {
			objs[x].value=objs[x].value.substr(0,250);
		}
	
	} else {
		
		if(chars <= 1000 ){
			txt.innerHTML=(1000-chars)+" Characters Left";
		} else {
			objs[x].value=objs[x].value.substr(0,1000);
		}
	
	}
	
}

window.setTimeout('polechars()',150);

	
}


 function checkinput(arg){
    
    	//cleans input to avoid malicious attacks
    	obj=document.getElementById('eventDetails');
	stg=arg;
	stg=stg.replace(/<applet>/gi,"");   // /g - global match  /i case insensitive
	stg=stg.replace(/<\/applet>/gi,"");
	stg=stg.replace(/<script>/gi,"");
	stg=stg.replace(/<\/script>/gi,"");
	stg=stg.replace(/<object>/gi,"");
	stg=stg.replace(/<\/object>/gi,"");
	stg=stg.replace(/<embed>/gi,"");
	stg=stg.replace(/<\/embed>/gi,"");
	stg=stg.replace(/<cf.*?>/gi,"");               //coldfusion tags
	stg=stg.replace(/<\/cf.*?>/gi,"");
	stg=stg.replace(/<%/gi,"");              //asp tags
	stg=stg.replace(/\/%.*?>/gi,"");
	
	if(stg != arg){
		
		obj.value=stg;
	}
    }
    
    
    
    	function assignTags(){
	//alert(document.forms[1].elements[0].value);
		
		titleStg=document.forms[1].elements[0].value;
		if(titleStg==""){
			titleStg="undefined";
		}
		dateStg=document.forms[1].elements[1].value;
		if(dateStg==""){
			dateStg="undefined";
		}
		locationStg=document.forms[1].elements[2].value;
		if(locationStg==""){
			locationStg="undefined";
		}
		window.setTimeout('assignTags()',5000);
	}
    


