var win = null;

var delay=3000 //3 seconds


//Counter for array 
var count = 1;
var unierr = "";

var cubeimage=new Array()

for (i=0;i<specifyimage.length;i++){
	cubeimage[i]=new Image()
	cubeimage[i].src=specifyimage[i]
}

function textCounter(field, countfield, maxlimit){
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
  		} else {
		countfield.value = maxlimit - field.value.length;
	}
}

function movecube(){
	if (window.createPopup)
		document.images['cube'].filters[0].apply()
		document.images['cube'].src=cubeimage[count].src;
	if (window.createPopup)
		document.images['cube'].filters[0].play()
		count++;
	if (count==cubeimage.length)
		count=0;
	setTimeout("movecube()",delay)
}

function NewWindow(url, winname, hgh, wid){
	win = window.open(url, winname, 'width=' + wid + ',height=' + hgh + ',menubar=no,resizable=no,scrollbars=no,toolbar=no,location=no');
}
	
if (document.images) {	
	tab_aboutBeige = new Image ;
	tab_aboutBeige.src = "/_images/tab_about.gif" ;
	tab_packagesBeige = new Image ;
	tab_packagesBeige.src = "/_images/tab_packages.gif" ;
	tab_galleryBeige = new Image ;
	tab_galleryBeige.src = "/_images/tab_gallery.gif" ;
	tab_eventsBeige = new Image ;
	tab_eventsBeige.src = "/_images/tab_events.gif" ;
	tab_bookingBeige = new Image ;
	tab_bookingBeige.src = "/_images/tab_booking.gif" ;
	
	tab_aboutRed = new Image ;
	tab_aboutRed.src = "/_images/tabRoll_about.gif" ;
	tab_packagesRed = new Image ;
	tab_packagesRed.src = "/_images/tabRoll_packages.gif" ;
	tab_galleryRed = new Image ;
	tab_galleryRed.src = "/_images/tabRoll_gallery.gif" ;
	tab_eventsRed = new Image ;
	tab_eventsRed.src = "/_images/tabRoll_events.gif" ;
	tab_bookingRed = new Image ;
	tab_bookingRed.src = "/_images/tabRoll_booking.gif" ;
}

function chgImg(navImg,newImg) {
	if (document.images) {
		document[navImg].src=eval(newImg + ".src") ;
	}
}

function MM_findObj(n, d) { //v3.0
  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_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,msg,errors='',args=MM_validateForm.arguments;
  if (GC("DNSRO") == 1 ){
  var msg
	msg  = "_______________________________________        \n\n" ;
	msg += "You do not have permission to save information!\n";
	msg += "_______________________________________\n" ;
	  alert(msg) ;
	  document.MM_returnValue = False ;	
  }
  document.cookie="save=1" ;
	msg  = "____________________________________________________\n\n" ;
	msg += "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "____________________________________________________\n" ;

  for (i=0; i<(args.length-2); i+=3)
 {
 test=args[i+2]; val=MM_findObj(args[i]);
    if (val)
	 {
	 nm=val.name;
	 if ((val=val.value)!="")
		 {
     		 if (test.indexOf('isEmail')!=-1)
			 {
			 p=val.indexOf('@');
        		if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain a valid e-mail address.\n';
			 }
		 else if (test!='R')
			 {
			 num = parseFloat(val);
		         if (val!==''+num) errors+='- '+nm+' must contain a number.\n';
		         if (test.indexOf('inRange') != -1)
				 {
				   p=test.indexOf(':');
			           min=test.substring(8,p);
				   max=test.substring(p+1);
			           if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
				 }
		  	 }		  
	 	 }
	 else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
 }

  }

 checkRadios()
 errors += unierr;
 if (errors) {
	 alert(msg+'\n'+errors);
	 document.cookie="save=0" ;
  }
//  else if (GC("mod") == 1 ) AskTechie() ;
  document.MM_returnValue = (errors == '');
}

function popUpGallery(page,PWidth,PHeight,id){
	eval("designerwiz"+id+"=window.open('"+page+"','designerwiz','toolbar=0,scrollbars=1,location=0,status=0,menubars=0,resizable=1,width="+PWidth+",height="+PHeight+"')")
}

function checkRadios() {
 unierr = ""
 var el = document.forms[0].elements;
 for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "radio") {
   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   var itemchecked = false;
   for(var j = 0 ; j < radiogroup.length ; ++j) {
    if(radiogroup[j].checked) {
	 itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
	unierr = "- Please specify either Enquiry or Booking";
//  alert("Please choose an answer for "+el[i].name+".");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 return true;
}



function GC (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return GCVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function GCVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function UnlockAdmin(x) {
		var sURL = unescape(window.location.pathname);
		var msg, cms;
		msg  = "___________________________________        \n\n" ;
		if (x == 'exitCMS'){
			msg += "Are You sure you wish exit the Administration Console?\n";
			cms = 'lh_loginaccessCMS';
		} else {
			msg += "Are You sure you wish unlock the Administration Console?\n";
			cms = '';
		}	
		msg += "___________________________________\n" ;
		if(confirm(msg)) {
			document.cookie="lgCMS='" + cms + "'"
			document.cookie="edi=0"
			window.location.href = sURL;
			return true;
			}
			else {
		alert("__________________________        \n\nYour request was not processed.\n__________________________");
		return false;
		}
}

function MenuAction(x,y,z) {
	var sURL = unescape(window.location.pathname);
	var a = GC("idx") ;
	var b = GC("id") ;
	var c = GC("rec") ;
	
	switch (x) {
	    case '0':	//switch to homepage
	     	document.cookie="id=0"
		document.cookie="edi=0"
	     	document.cookie="rec="
		window.location.href = sURL //+ '?idx=' + a + '&id=' + b + '&rec=' + c 
	    	break;
	    case '1':	//switch between edit page information and site page admin
		if ( b == 0 ) {
		     	document.cookie="idx=mnu_aH"
		     	document.cookie="id=0"
			document.cookie="edi=0"
		     	document.cookie="rec="
		} else {
			if (GC("edi") == 1 ) {
			 	document.cookie="edi=0"
				}
				 else {
			 	document.cookie="edi=1"
			}
		}
		window.location.href = sURL + '?idx=' + a + '&id=' + b + '&rec=' + c 
	    	break;
	    case '2':	//switch between page details and page text
		if (GC("rec") == 0){
		         alert("Please configure the document details before you create a new page.")
		} else {
			if (GC("mem") == 1 ) {
			 	document.cookie="mem=0"
				}
				 else {
			 	document.cookie="mem=1"
			}
		}
		window.location.href = sURL + '?idx=' + a + '&id=' + b + '&rec=' + c 
	    	break;
	    case '3':	//related links page display
		window.location.href = sURL + '?qry=' + y
	    	break;
	    case '6':	//creation of a blank page for additional content or menu
		switch (y) {
		    case '1':	// creation of a blank page for additional content
		     	document.cookie="idx=mnu_hH"
		     	document.cookie="id=0"
			document.cookie="edi=0"
		     	document.cookie="rec="
			window.location.href = sURL + '?idx=mnu_hH&id=0&rec='
			break;		
		    case '2':	// creation of a new website menu
		     	document.cookie="id=0"
			document.cookie="edi=0"
	     		document.cookie="rec="
			window.location.href = sURL + '?idx=' + a + '&id=0&rec='
			break;		
		}
		break;		
	    case '7':	// town or activity information
	     	document.cookie="id=0"
	     	document.cookie="rec="
		switch (y) {
		    case '1':	// town information display
		     	document.cookie="idx=mnu_fH"
			window.location.href = sURL + '?idx=mnu_fH'
			break;		
		    case '2':	// activity information display
		     	document.cookie="idx=mnu_gH"
			window.location.href = sURL + '?idx=mnu_gH'
			break;		
		}
		break;		
	    case '8':	// town or activity information dropbox information
		if ( y == 'mnu_fH' ) { mnuidx = document.forms[0].mnu_fH.value ; }
		else {mnuidx = document.forms[0].mnu_gH.value ;}
		window.location.href = 'default.asp?mnq=' + mnuidx
		break;	

	    case 'DEL':	// delete page information
		var sURL = unescape(window.location.pathname);
		var msg;
		msg  = "___________________________________        \n\n" ;
		msg += "Are You sure you wish to delete this page?\n"; 	
		msg += "___________________________________\n" ;
		if(confirm(msg)) {
			msg  = "____________________________________________        \n\n" ;
			msg += "Your request has been accepted and will be processed!\n";
			msg += "____________________________________________\n" ;
			alert(msg);			
			window.location.href = sURL + '?idx=' + x + '&id=' + b + '&rec=' + c 
			return true;
			}
			else {
		alert("__________________________        \n\nYour request was not processed.\n__________________________");
		return false;
		}
	    	break;
		
	    default:		
	     	alert('Cookie not determined! path is ' + sURL + '?idx=' + a + '&id=' + b + '&rec=' + c)
	 }
}

function move(fbox, tbox) {
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	for (i = 0; i < tbox.options.length; i++) {
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for(i = 0; i < fbox.options.length; i++) {
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != "") {
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
		}
		else {
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
		}
	}
	arrFbox.sort();
	arrTbox.sort();
	fbox.length = 0;
	tbox.length = 0;
	var c;
	for(c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}
	for(c = 0; c < arrTbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
	}

	List1(); 
}

function List1() {
	var list = document.frmContent.list1;
	var theList = ",";
	// start with a "?" to make it look like a real query-string
	for (i = 0; i <= list.options.length-1; i++) { 
		theList += list.options[i].value;
		if (i != list.options.length-1) theList += ",";
	}
	document.cookie="pages=" + theList + ",";
}

function moveuser(fbox, tbox) {
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	for (i = 0; i < tbox.options.length; i++) {
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for(i = 0; i < fbox.options.length; i++) {
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != "") {
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
		}
		else {
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
		}
	}
	arrFbox.sort();
	arrTbox.sort();
	fbox.length = 0;
	tbox.length = 0;
	var c;
	for(c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}
	for(c = 0; c < arrTbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
	}

	Lista(); 
}


function Lista() {
	var list = document.frmContent.lista;
	var theList = ",";
	// start with a "?" to make it look like a real query-string
	for (i = 0; i <= list.options.length-1; i++) { 
		theList += list.options[i].value;
		if (i != list.options.length-1) theList += ",";
	}
	document.cookie="users=" + theList + ",";
}
