// JavaScript Document

// ---------------------------------------------
// Dreamweaver rollover scripts
// ---------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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];}
}

// ---------------------------------------------
// Custom scripts
// ---------------------------------------------
var menuSelected = null;
var timeoutID = null;
function showHide(elementID) { // For showing or hiding page elements
   element = document.getElementById(elementID); 
   if (element.className=="show") { element.className="hide"; } 
   else { element.className="show"; } 
} 
function showMenu(menuID) { // For showing menus
	clearTimeout(timeoutID);
	hideMenu(); // Hides the currently selected menu
	document.getElementById(menuID).className = 'show';
	menuSelected = menuID; // Make this the currently selected menu
} 
function hideMenu() { // For hiding menus
	if (menuSelected != null) document.getElementById(menuSelected).className = 'hide';
}
function menuTimeout() { // Timeout the current menu
	if (timeoutID != null) { clearTimeout(timeoutID); }
	timeoutID = setTimeout("hideMenu()",500);
}
function showHide(item) { // Shows/hides an item

	var toggle = document.getElementById(item);
	if (toggle.className == 'hiddenNote') toggle.className= 'shownNote';
	else toggle.className = 'hiddenNote';

} // End of showHide 
function toggle(item) { // Shows/hides an item

	var toggle = document.getElementById(item);
	if (toggle.className == 'hide') toggle.className= 'show';
	else toggle.className = 'hide';

} // End of showHide 

/******************************************
* CLEAR FIELD
* Actually creates a new field!
* (c)2008 Simon Jamie
*******************************************/
function clearField(item,initialValue,password) {

	if (item.value == initialValue) { // The field still uses the original value -> change it!

		// Create a new input object
		var newItem = document.createElement('input');

		// Create the right kind of item
		if (password) newItem.type = 'password';
		else newItem.type = 'text';
		
		// Set any attributes
		newItem.name = item.getAttribute('name');
		newItem.size = item.getAttribute('size');
		newItem.className = 'normal';
		
		// Replace the original item
		item.parentNode.replaceChild(newItem,item);
		
		// Short timeout before focusing -> IE fix
		setTimeout("newItem.focus();",10);
		newItem.focus();
		
	} // End of changing original value
	
} // End of function clearField

// ---------------------------------------------
// Upload scripts
// ---------------------------------------------
var exts = "jpg|jpeg|mp3|wma";
//var exts = ".*"; //Use this to accept all Extensions

var UID,NF=0,cx=0;
function openStatusWindow() { 
	// if(document.getElementById('fileUpload').value.length > 0) {
		uploadWin = window.open('/cgi-bin/XUpload/upload_status.cgi?upload_id='+UID,'win1','width=320,height=240,resizable=1');
		uploadWin.window.focus();
	// }
}

function generateSID() {
	
	UID = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random());
	var f1 = document.uploadForm;
	f1.action = f1.action.split('?')[0]+'?upload_id='+UID;

}

function StartUpload() {

	// if (!checkExt(document.getElementById('fileUpload').value) return false; // Check extension
	generateSID(); // Generate ID code
	openStatusWindow(); // Open status window

}

function checkExt(value) {

	if (value == "") return true; // If there's no file, ignore
	var re = new RegExp("^.+\.("+exts+")$","i"); // Set up a regExp to find extensions
	if(!re.test(value)) { // Check value
		alert("Extension not allowed for file: \"" + value + "\"\nOnly these extensions are allowed: "+exts.replace(/\|/g,',')+" \n\n");
		return false; // Extension not allowed
	} // End of checking
	return true; // If everything okay

}
