// ********************************************************** //
// *** FORM VALIDATION FUNCTIONS                          *** //
// ********************************************************** //

function validateForm(){
	if (document.contactForm.contactName.value==""){
		alert("Please enter your Name.");
		document.contactForm.contactName.focus();return false
	}
	if (document.contactForm.contactEmail.value==""|document.contactForm.contactEmail.value.indexOf("@")==-1|document.contactForm.contactEmail.value.indexOf(".")==-1){
		alert("Please enter a valid Email Address.");
		document.contactForm.contactEmail.focus();return false
	}
	if (document.contactForm.contactTelephone.value==""){
		alert("Please enter your Telephone Number.");
		document.contactForm.contactTelephone.focus();return false
	}
	if (document.contactForm.contactMessage.value==""){
		alert("Please enter your Message.");
		document.contactForm.contactMessage.focus();return false
	}
	else{document.contactForm.submit();}	
}

// ********************************************************** //
// *** GALLERY FUNCTIONS                                  *** //
// ********************************************************** //

function fadeSwich(obj){
	if (obj.filters.alpha.opacity==100){
		obj.filters.alpha.opacity=40;}
	else{
		obj.filters.alpha.opacity=100;}
}

function changeImage(imageSrc){
	document.images['largePic'].src=imageSrc}

// ********************************************************** //
// *** NAVIGATION FUNCTIONS                               *** //
// ********************************************************** //

var lastMenu="null"; 

function langMenuOn(imgName){
	if (imgName.indexOf("prev")!=-1){
		document.images[imgName].src='images/cj_previousarrow.gif';}
	else if (imgName.indexOf("next")!=-1){
		document.images[imgName].src='images/cj_nextarrow.gif';}
	else{
		document.images[imgName].src='images/cj_dotarrow_red.gif';}
}

function langMenuOff(imgName){
	if (imgName.indexOf("prev")!=-1){
		document.images[imgName].src='images/cj_previousarrow_grey.gif';}
	else if (imgName.indexOf("next")!=-1){
		document.images[imgName].src='images/cj_nextarrow_grey.gif';}
	else{
		document.images[imgName].src='images/spacer.gif';}
}

function navItemOn(cellName, imgName){
if (document.getElementById){
		document.images[imgName].src='images/cj_dotarrow.gif';
		document.getElementById(cellName).style.backgroundColor='#CC3300';
	}
}

function navItemOff(cellName, imgName){
	if (document.getElementById){
		document.images[imgName].src='images/spacer.gif';
		if (imgName.indexOf("0")!=-1){
			document.getElementById(cellName).style.backgroundColor='#E4E4E4';}
		else{
			document.getElementById(cellName).style.backgroundColor='#CCCCCC';}
	}
}
 
function showMenu(menuName){
	if (document.getElementById){
		if (lastMenu=='null'){
			document.getElementById(menuName).style.visibility='visible'
		}
		else if (menuName==lastMenu){
			if (document.getElementById(menuName).style.visibility=='visible')
			{document.getElementById(menuName).style.visibility='hidden'}
			else
			{document.getElementById(menuName).style.visibility='visible'}
		}
		else {
		document.getElementById(menuName).style.visibility='visible'
		document.getElementById(lastMenu).style.visibility='hidden'
		}
	}
	
	if (document.layers){
		if (lastMenu=='null'){
			document.layers[menuName].visibility='visible'
		}
		else if (menuName==lastMenu){
			if (document.layers[menuName].visibility=='visible')
			{document.layers[menuName].visibility='hidden'}
			else
			{document.layers[menuName].visibility='visible'}
		}
		else {
		document.layers[menuName].visibility='visible'
		document.layers[lastMenu].visibility='hidden'
		}
	}	
	
	lastMenu=menuName
}

// ********************************************************** //
// *** IMAGE MANAGER FUNCTIONS                            *** //
// ********************************************************** //

var lastFolder="null";
var lastFilename="null";
var lastError="null";
var valid=false;


function showContents(Folder){
//alert("boo2");
//	if (lastFolder=='null'){
//		document.getElementById(Folder).style.display=''}
//	else {
		if (document.getElementById(Folder).style.display=='none'){
			document.getElementById(Folder).style.display=''}
		else {
			document.getElementById(Folder).style.display='none'}
//	}
//lastFolder=Folder
}

function highlightFile(Filename){
	if (lastFilename=='null'){
		document.getElementById(Filename).style.color='#FF0000'}
	else {
		if (lastFilename==Filename){
			document.getElementById(Filename).style.color='#FF0000';}
		else{
			document.getElementById(Filename).style.color='#FF0000';
			document.getElementById(lastFilename).style.color='#666666'}
	}
lastFilename=Filename
}

function checkForImages(slotNum){
var theForm=document.image_upload;
	if (theForm(slotNum).value==""){
		alert("Please select an Image as well as a Thumbnail.");
		lastError=slotNum+"_image";
		document.getElementById(slotNum+"_image").style.color='#FF0000';
		}
	if (theForm(slotNum+'_thumb').value==""){
		alert("Please select a Thumbnail as well as an Image.");
		lastError=slotNum+"_thumb";
		document.getElementById(slotNum+"_thumb").style.color='#FF0000';
		}		
}

function checkFormat(slotNum){
var theForm=document.image_upload;
	if (theForm(slotNum).value.indexOf(".jpg")==-1){
		alert("Image must be a JPG.");
		lastError=slotNum+"_image";
		document.getElementById(slotNum+"_image").style.color='#FF0000';
		return false
	}

	if (theForm(slotNum+"_thumb").value.indexOf(".gif")==-1){
		alert("Thumbnail must be a GIF");
		lastError=slotNum+"_thumb";
		document.getElementById(slotNum+"_thumb").style.color='#FF0000';
		return false
	}
}

function validateUpload(){
var theForm=document.image_upload;
var Empty=true;

	if (lastError!="null"){
		document.getElementById(lastError).style.color='#000000';
	}
	
	for (i=0; i<theForm.length; i++){
		if (theForm(i).type=="file" && theForm(i).value!=""){
			Empty=false;
		}
	}
	
	for (i=1; i<5; i++){
		if ((theForm('slot_'+i).value!="" && theForm('slot_'+i+'_thumb').value=="") || +
			(theForm('slot_'+i).value=="" && theForm('slot_'+i+'_thumb').value!="")){
			checkForImages('slot_'+i);
			return false
		}
		else if ((theForm('slot_'+i).value.indexOf(".jpg")==-1 && theForm('slot_'+i).value!="") || +
			(theForm('slot_'+i+'_thumb').value.indexOf(".gif")==-1 && theForm('slot_'+i+'_thumb').value!="")){
			checkFormat('slot_'+i);
			return false
		}
		else if ((theForm('slot_'+i).value!="" && theForm('slot_'+i+'_thumb').value!="") && +
			(theForm('slot_'+i+'_gallery').value=="null")){
			alert("Please select a gallery for Slot "+i+".");
			theForm('slot_'+i+'_gallery').focus();
			return false
		}		
	}
	
	if (Empty!=true){
		return true
	}
	else{
		alert("Empty")
		return false		
	}
	
}

function confirmDelete(image){
	var confirmBox = confirm ("Are you sure you want to remove the image <%=fileName%>?")
	if (confirmBox){
		document.location="../cms/cj_deleteimage.asp?image="+image
	}
}

function confirmMove(image){
	var gallery = document.image_functions.move_galleries.options[document.image_functions.move_galleries.selectedIndex].value
	var confirmBox = confirm ("Are you sure you want to move the image <%=fileName%> to the gallery "+gallery+"?")
	if (confirmBox){
		document.location="../cms/cj_moveimage.asp?image="+image+"&gallery="+gallery
	}				
}	
