///////////////////////////////////////////////////////////////////////////////////////////////
//Dropdown menus
///////////////////////////////////////////////////////////////////////////////////////////////

var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

function showmenu(e,whichitem,x,y){

if (!whichitem) {
	clearhidemenu()
	hidemenu2()
} else {
	
	if (!document.all&&!document.getElementById&&!document.layers)
	return
	
	clearhidemenu()
	
	topmenuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
	topmenuobj.thestyle=(ie4||ns6)? topmenuobj.style : topmenuobj
	
	if (ie4||ns6)
	topmenuobj.innerHTML=whichitem
	else{
	topmenuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+whichitem+'</layer>')
	topmenuobj.document.close()
	}
	topmenuobj.contentwidth=(ie4||ns6)? topmenuobj.offsetWidth : topmenuobj.document.gui.document.width
	topmenuobj.contentheight=(ie4||ns6)? topmenuobj.offsetHeight : topmenuobj.document.gui.document.height
	eventX=x
	eventY=y
	
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
	var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
	
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<topmenuobj.contentwidth)
	//move the horizontal position of the menu to the left by it's width
	topmenuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-topmenuobj.contentwidth : ns6? window.pageXOffset+eventX-topmenuobj.contentwidth : eventX-topmenuobj.contentwidth
	else
	//position the horizontal position of the menu where the mouse was clicked
	topmenuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
	
	//same concept with the vertical position
	if (bottomedge<topmenuobj.contentheight)
	topmenuobj.thestyle.top=ie4? document.body.scrollTop+eventY-topmenuobj.contentheight : ns6? window.pageYOffset+eventY-topmenuobj.contentheight : eventY-topmenuobj.contentheight
	else
	topmenuobj.thestyle.top=ie4? document.body.scrollTop+eventY : ns6? window.pageYOffset+eventY : eventY
	topmenuobj.thestyle.visibility="visible"
	return false
	}
}
	
function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(section){
MM_swapImgRestore()
if (window.topmenuobj) {
topmenuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}
MenuOn(section)
//alert(section)
}

function hidemenu2(section){
if (window.topmenuobj) {
topmenuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}
}

function dynamichide(e,section){
if (ie4&&!topmenuobj.contains(e.toElement))
hidemenu(section)
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu(section)
}

function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout("hidemenu()",500)
}

function delayhidemenu2(Section){
if (ie4||ns6||ns4)
delayhide=setTimeout("hidemenu("+Section+")",500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
else{
while(source_el.id!="popmenu"){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
}
}
}

//if (ie4||ns6)
//document.onclick=hidemenu

///////////////////////////////////////////////////////////////////////////////////////////////
//Rollover for graphics
///////////////////////////////////////////////////////////////////////////////////////////////

function MenuOn(WhichOne) {
	if (WhichOne == 2) {
		eval("MM_swapImage('Menu"+WhichOne+"','','/graphics/menu1on.gif','','','','','','',3)");
	}
	if (WhichOne == 3) {
		eval("MM_swapImage('Menu"+WhichOne+"','','/graphics/menu2on.gif','','','','','','',3)");
	}
	if (WhichOne == 4) {
		eval("MM_swapImage('Menu"+WhichOne+"','','/graphics/menu4on.gif','','','','','','',3)");
	}
	if (WhichOne == 5) {
		eval("MM_swapImage('Menu"+WhichOne+"','','/graphics/menu3on.gif','','','','','','',3)");
	}
	if (WhichOne == 6) {
		eval("MM_swapImage('Menu"+WhichOne+"','','/graphics/menu5on.gif','','','','','','',3)");
	}
	if (WhichOne == 7) {
		eval("MM_swapImage('Menu"+WhichOne+"','','/graphics/menu6on.gif','','','','','','',3)");
	}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImgRestore(SectionID) {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  MenuOn(SectionID)
}
function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Dropdown third menu
///////////////////////////////////////////////////////////////////////////////////////////////

function goUrl(listObj)
{
if(listObj[listObj.selectedIndex].value != '')
document.location.href = listObj[listObj.selectedIndex].value;
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Valid email checker
///////////////////////////////////////////////////////////////////////////////////////////////

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail Address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail Address")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail Address")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail Address")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail Address")
	    return false
	 }

		 return true	
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Delete Confirmation
///////////////////////////////////////////////////////////////////////////////////////////////

function DeleteConfirm(PageID){
	if (confirm("Are you sure you want to delete?")) {
		location = '/cms/submit.asp?PageID='+PageID+'&SubmitType=DeletePage'
	} else {
		return false
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Feedback Checker
///////////////////////////////////////////////////////////////////////////////////////////////

function FeedbackFormCheck(FormType) {
	var emailID=document.FeedbackForm.Email
	var i = ""
	if (document.FeedbackForm.Name.value == "") {
		alert("Please enter a name")
		document.FeedbackForm.Name.focus()
		i = "Error"
		return false
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		i = "Error"
		return false
	}
	if (echeck(emailID.value)==false){
		//emailID.value=""
		emailID.focus()
		i = "Error"
		return false
	}
	if (document.FeedbackForm.Comments.value == "") {
		if (FormType == "ContactUsEmail") {
			alert("Please enter an enquiry")
		} else {
			alert("Please enter a comment")
		}
		document.FeedbackForm.Comments.focus()
		i = "Error"
		return false
	}
	if (document.FeedbackForm.Alerts.checked == true) {
		alertsplease = "yes";
	} else {
		alertsplease = "no";
	}
	if (i == "") {
		if (FormType == "ContactUsEmail") {
			window.open('/popup.asp?Name='+document.FeedbackForm.Name.value+'&Email='+document.FeedbackForm.Email.value+'&Telephone='+document.FeedbackForm.Telephone.value+'&Comments='+document.FeedbackForm.Comments.value+'&Alerts='+alertsplease+'&Type='+FormType+'', 'windowNew', 'width=310,height=460,status=no,toolbar=no,menubar=no,scrollbars=no,screenX=200,screenY=200,left=300,top=200');
		} else {
			window.open('/popup.asp?Name='+document.FeedbackForm.Name.value+'&Email='+document.FeedbackForm.Email.value+'&Telephone='+document.FeedbackForm.Telephone.value+'&Comments='+document.FeedbackForm.Comments.value+'&Type='+FormType+'', 'windowNew', 'width=310,height=370,status=no,toolbar=no,menubar=no,scrollbars=no,screenX=200,screenY=200,left=300,top=200');
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//Check CMS Form
///////////////////////////////////////////////////////////////////////////////////////////////

function CheckCMSForm() {
	if (document.CMS.SubmitType == "Add") {
		if (document.CMS.MenuUnder[0].checked || document.CMS.MenuUnder[1].checked) {
			if (document.CMS.NewMenuPosition.value == "") {
				alert("Please enter a menu position")
				document.CMS.NewMenuPosition.focus()
				return false
			} else {
				if (isNaN(document.CMS.NewMenuPosition.value)) {
					alert("Please enter a number")
					document.CMS.NewMenuPosition.focus()
					return false
				} else {
					return true
				}
			}
		}
	}
	if (document.CMS.SubmitType.value == "Add" || document.CMS.SubmitType.value == "Edit") {
		if (document.CMS.LeftMenuPic) {
			if (document.CMS.LeftMenuPic.value != "") {
				strImage = document.CMS.LeftMenuPic.value
				strChecked = strImage.substring(1, 4)
				if ((strChecked == "IMG") || (strChecked == "img")){
					return true
				} else {
					alert("Please enter an image")
					document.CMS.LeftMenuPic.focus()
					return false
				}
			}
			return true
		}
	}
	if (document.CMS.SubmitType.value == "AddPressRelease" || document.CMS.SubmitType.value == "EditPressRelease") {
		if (document.CMS.TempPDF.value != "") {
			fullString = document.CMS.TempPDF.value
			testString = "pdf"
			tempAlert = ""
			istrue = false
    	    fullLength = fullString.length
	        testLength = testString.length
			for (i=0;i<=fullLength;i++) {
                comp=fullString.substring(i-1,fullLength);
                comp=comp.substring(0,testLength);
                if (comp == testString) {
	                tempAlert = "Yes"
					StringValue = fullString
					FirstPosition = StringValue.indexOf("\"")
					SecondPosition = StringValue.indexOf("\"",FirstPosition+1)
					FinalValue = StringValue.substring(FirstPosition+1,SecondPosition)
					document.CMS.PDF.value = FinalValue
                }
        	}
			if (tempAlert != "Yes") {
				alert("Please enter a PDF")
				document.CMS.TempPDF.focus()
				return false
			}
		}
		if (document.CMS.Day.options[document.CMS.Day.selectedIndex].value == "00") {
			alert("Please select a day")
			document.CMS.Day.focus()
			return false
		}
		if (document.CMS.Day.options[document.CMS.Month.selectedIndex].value == "00") {
			alert("Please select a month")
			document.CMS.Month.focus()
			return false
		}
		if (document.CMS.Day.options[document.CMS.Year.selectedIndex].value == "00") {
			alert("Please select a year")
			document.CMS.Year.focus()
			return false
		}
	}
}
