var requiredVersion = 6; // required flash version
var maxVersion = 9;
var actualVersion = 0;
var v_flashInstalled = false;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
jsVersion = 1.1;
for (var x = 2; x <= maxVersion; x++){
    eval("var flash" + x + "Installed = false")
}

if(isIE && isWin){
   document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
   document.write('on error resume next \n');
   for (var y = 2; y <= maxVersion; y++){
   eval(document.write('flash'+y+'Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+y+'"))) \n'));
   }
   document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}


function detectFlash(){
    if (navigator.plugins){
        if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){
            var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
            var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
            var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
            for (var z = 2; z <= maxVersion; z++){
                eval("flash" + z + "Installed = flashVersion == " + z)
            }
        }
    }
    for (var i = 2; i <= maxVersion; i++){
        if (eval("flash" + i + "Installed") == true) actualVersion = i;
    }
    if (actualVersion >= requiredVersion){
        v_flashInstalled = true;
    } else {
        v_flashInstalled = false;
    }
}

detectFlash();

function Initialize() {
// Initializes the document when loaded.
// Uses ChangeMenu(), UpdateLinks().
if (document.URL.search("&qm=menu") == -1) {
if (document.URL.charAt(document.URL.length-1) != "/") {
ChangeMenu('0','0','0');
}
}
UpdateLinks();
}

////////////////////////////
//       ChangeMenu       //
////////////////////////////

function ChangeMenu(v1,v2,v3) {
// Used to change the menu when the menulink is empty.
oldURL = document.URL;
if (oldURL.indexOf("?") != -1) {
newURL = oldURL.slice(0, oldURL.indexOf("?")) + "?Open&qm=menu," + v1 + "," + v2 + "," + v3;
} else {
newURL = oldURL + "?Open&qm=menu," + v1 + "," + v2 + "," + v3;
}
location.replace(newURL);
}


////////////////////////////
//       OpenPopup        //
////////////////////////////

function OpenPopup(windowName) {
// Used to open popup windows.
if (windowName == "papersearch") {
window.open('',windowName,'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,width=550,height=500');
}
}

////////////////////////////
//           GoTo         //
////////////////////////////

function GoTo(ref) {
// Used to navigate from dropdown menus.
// Can be called from any menu; <select> tag must have "gopage" as its name.
if (ref.gopage.options[ref.gopage.selectedIndex].value != "") {
dbPath = document.URL.slice(0, document.URL.indexOf(".nsf")) + ".nsf/";
goTo = ref.gopage.options[ref.gopage.selectedIndex].value;
if (goTo.search("http://") == -1) {
location = dbPath + goTo;
} else {
location = goTo;
}
}
}

////////////////////////////
//      UpdateLinks       //
////////////////////////////

function UpdateLinks() {
// Updates links with no menu information with the current page's menu attributes.
// Does not modify external links.
zeroMenu = "&qm=menu,0,0,0";
if(document.URL.charAt(document.URL.lastIndexOf) == "/") {
baseURL = document.URL.toLowerCase().slice(7, document.URL.lastIndexOf);
} else {
baseURL = document.URL.toLowerCase().slice(7, document.URL.indexOf(".nsf")) + ".nsf";
}
basePath = baseURL.slice(baseURL.indexOf("/"));
for (i = 0; i < document.links.length; i++) {
oldURL = document.links[i].href.toLowerCase() + "?";
if (oldURL.search(basePath) != -1) {
if (oldURL.search("javascript:") == -1) {
if (oldURL.search("&qm=menu") == -1) {
if (oldURL.search("/?") == -1) {
newURL = oldURL.slice(0, oldURL.indexOf("/?")) + "?Open" + zeroMenu;
} else if (oldURL.search(".xml?") == -1) {
menu = document.URL.slice(document.URL.indexOf("&qm=menu"), document.URL.length);
newURL = oldURL.slice(0, oldURL.indexOf("?")) + "?OpenDocument" + menu;
} else {
newURL = oldURL.slice(0, oldURL.indexOf("?"));
}
document.links[i].href = newURL;
}
}
}
}
}

function CreateResponse(id, dbfp, winwidth, winheight)	{
var dlgPath= "/" + dbfp + "/frmFeedbackToAuthorWeb?OpenForm&id=" + id;
Stats='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + winwidth + ',height=' + winheight +',left=250,top=100'
dlgBox = window.open (dlgPath, "Comments", Stats)
}


function Trim(string) 
{
// Removes leading, trailing, and redundant spaces from string 
	var re = /^ */g
	string = string.replace(re, "")
	re = / *$/g
	string = string.replace(re, "")
	re = / {2,}/g
	string = string.replace(re, " ")
	return string
}

function validateDocument(this_form)
{
	var validation = validateFields(this_form);
	if ( validation != -1 )
	{
		alert(this_form.txtError.value)
	}else
	{
		this_form.submit();
	}
}

function validateFields(this_form)
{
	var validated = -1;
	if (this_form.FeedbackRequired.value == ""){return -1;}
	var validate_fields = this_form.FeedbackRequired.value.split("; ");
	for (i = 0 ; i < validate_fields.length ; i++)
	{
		if ( validate_fields[i] != "" )
		{
		var active_field = eval( "this_form." + validate_fields[i] ) ;
		switch(active_field.type)
		{
			case "text" :
				if ( Trim(active_field.value) == "" )
				{					
					validated = i;
					return validated;
				}
				break
			case "hidden" :
				if ( Trim(active_field.value) == "" )
				{					
					validated = i;
					return validated;
				}
				break
			case "textarea" :
				if ( Trim(active_field.value) == "" )
				{					
					validated = i;
					return validated;
				}
				break
			case "select-one" :				
				if ( active_field.options[active_field.selectedIndex].text == 'Select value' )
				{					
					validated = i;
					return validated;
				}
				break
			case "select-multiple" :				
				if ( active_field.selectedIndex == -1)
				{					
					validated = i;
					return validated;
				}
				break
			default:					
				if (active_field[0].type == "radio" || active_field[0].type == "checkbox") 
				{					
					chk = 'false';
					for (m = 0; m < active_field.length; m++)
					{
						if (active_field[m].checked)
						{
							chk = 'true'
							break
						}
					}
					if (chk == 'false')
					{	
						validated = i;					
						return validated;
					}					
				} 
		}
		}
	}
	return validated;
}