//==============================================================
//  SETTINGS
//==============================================================

// var exts = ".*";
var exts = "doc|pdf|rtf|xls";

//==============================================================
//  SHOW THAT LOADING IMAGE
//==============================================================

function showLoadingImage() {
	document.getElementById('submitbox1').style.display = 'none';
	document.getElementById('submitbox2').style.display = 'block';
	setTimeout('document.images["loading"].src = "images/loading.gif"', 1);
}



//==============================================================
//  UPLOAD FILE STEP 1
//==============================================================

function documents_uploadStep1(form)
{
	var form = document.form;
	var valid = true;
	if (valid)
		{
		showLoadingImage();
		return true;
		}
	else {
		msg = "Please fill the required fields";
		alert ( msg );
		return false;
		}
}


//==============================================================
//  UPLOAD FILE STEP 2
//==============================================================

function showExt()
{
	alert("File extensions allowed to be uploaded:\n"+exts.replace(/\|/g,', ')+" \n\nIf you have a file extension that is not on this list please contact us.");
}

function checkExt(value)
{
    if(value=="")return true;
    var re = new RegExp("^.+\.("+exts+")$","i");
    if(!re.test(value))
    {
        alert("Extension not allowed for file: \"" + value + "\"\nOnly the following extensions are allowed:\n"+exts.replace(/\|/g,', ')+" \n\n");
        return false;
    }
    return true;
}

var UID,NF=0,cx=0;
function openStatusWindow() {
   win1 = window.open('http://www.urbandogtraining.com.au/cgi-bin/documents/upload_status.cgi?upload_id='+UID,'win1','width=320,height=240,resizable=1');
   win1.window.focus();
}

function generateSID()
{
 UID = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random());
 var f1=document.F1;
 f1.action = f1.action.split('?')[0]+'?upload_id='+UID;
}

function documents_uploadStep2(form)
{
	var browseField = document.getElementById('uploadFile').value;
	if(!checkExt(browseField))
		{ return false; }
    generateSID();
	showLoadingImage();
    //openStatusWindow();
	return true;
}


//==============================================================
//  EDIT DOCUMENT 
//==============================================================

function documents_accessLevelGroup(index,thisSelect,editDiv)
{
	var value = document.getElementById(thisSelect).value
	var editDiv = document.getElementById(editDiv);
	if (value == "G") { editDiv.style.display = 'block'; }
	  else { editDiv.style.display = 'none'; }
	if (thisSelect == "documentAccessLevel") {
	  if (value == "P" || value == "N") { document.getElementById('publicViewable').style.display = 'none'; }
		else { document.getElementById('publicViewable').style.display = 'block'; }
	  }
}



function documents_userConfirm(url,message)
{
  var detStatus2=confirm("Are you sure you want to " + message + "?");
  if (detStatus2)
  window.location = url;
}





//==============================================================
//  DOCUMENT MANAGER BROWSE
//==============================================================

function toggleRows(className) {

	var allPageTags=document.getElementsByTagName("*");
	
	var classNameStatus = window[className];
	  
	for (i=0; i<allPageTags.length; i++) {
	
	  if (classNameStatus==null) {
	
		if (allPageTags[i].className==className) {
		
		  allPageTags[i].style.display='none';
		  window[className] = 1;
		  
		}
			
	  }
		
	  if (classNameStatus==1) {
	
		if (allPageTags[i].className==className) {
		
		  allPageTags[i].style.display='';
		  window[className] = null;
		  
		}
			
	  }
		
	}
	
}

