//SCRIPT:2
//THIS IS USED FOR CHECKING NUMERIC VALUE IN ORDER PAGE.


function checkvalue(fld) {
		var valid = "0123456789"
		var chk = "val";
		var temp;
		for (var i=0; i<fld.value.length; i++) {
			temp = "" + fld.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") chk = "invalid";
		}
		if (chk == "invalid") {
			window.status="Please enter valid data";
			fld.focus();
			fld.select();
		}
}

//SCRIPT:2
//THIS IS USED TO CLEAR TEXT BOX FOR ALBUM SEARCH.
function clearBox() { 
        if (document.displayResultForm.srchString.value == "type here->"){
		document.displayResultForm.srchString.value = '';
	}
	
}

//SCRIPT:2A
//THIS IS USED TO CLEAR TEXT BOX FOR ALBUM SEARCH.
function clearBoxQucikSearch() { 
	if (document.SearchForm.search_string.value == "Enter the search criteria"){
		document.SearchForm.search_string.value = "";
	}	
}

//SCRIPT 2B FOR QUICK SEARCH.
function submitSearchForm(act) { 
	document.SearchForm.command.value = act; 
	document.SearchForm.submit(); 
}


//SCRIPT:3
//USED FOR CLOSING OF WINDOW.
function closeWin(newWindow) {
	newWindow.close();    // close small window and depart
}

//SCRIPT:4
//THIS IS USED FOR CONVERSION IN ORDER PAGE -- PRICE ESTIMATION FOREIGN CURRENCY.
function conv(usd,oth)  
{
  var usdAmt = usd;
  if (usdAmt < 0 || isNaN(usdAmt))   {
       usdAmt = 0;
    }
  document.estmform.result.value =   parseFloat(usdAmt * oth * 100) / 100;
}

//SCRIPT:5
//TO GET ELEMENT INFO 
function getElementInfo(dbname, eleid, action, id, fileSrc,prevCommand,url) { 
	
    document.displayResultForm.command.value = action; 
	document.displayResultForm.dbname.value = dbname;
	document.displayResultForm.elementid.value = eleid; 
	document.displayResultForm.recno.value = id;
	document.displayResultForm.fileSource.value = fileSrc;
	document.displayResultForm.prevCommand.value = prevCommand;
	document.displayResultForm.url.value = url;
	document.displayResultForm.submit();
	
}


//SCRIPT:6
//THIS SCRIPT IS USED TO SUBMIT ORDER FORM WITH VALIDATION
function orderSubmit(command,mode) {
	document.orderform.command.value = command;
	document.orderform.mode.value = mode;
	if (
	     ( command == "OrderProcess") || 
	     ( command == "OrderProcess-GUEST") 
           ){
		if (validateOrderForm()){
			document.orderform.submit();
		}
	}else {
		document.orderform.submit();
	}	
}


//SCRIPT:7
//THIS IS USED FOR DISPLAY OF POPUP WINDOW FOR LIMITATIONS.

function popupWin(eleid, fname,limit) {
	msg =  "<html><head><title>Digital Media Repository</title><body>";
	msg += "<strong>File Name:</strong>";
	msg += fname;
	msg += "<BR><strong>Element-id:</strong>";  
	msg += eleid;
	msg += "<BR><strong>Limitations:</strong>";  
	msg += limit;
	msg += "<hr>";
	//msg += "<small>This window will close automatically in <FONT COLOR=RED> 15 </FONT>secs</small>";
	msg += "</body></html>";
	winPop(msg);   
}

//SCRIPT:8A
//THIS IS USED TO DISPLAY LEGEND

function popupWinLegend(eleid, fname,legText) {
	msg =  "<html><head><title>Digital Media Repository</title><body>";
	msg += "<strong>File Name:</strong>";
	msg += fname;
	msg += "<BR><strong>Element-id:</strong>";  
	msg += eleid;
	msg += "<BR><strong>Legend:</strong>";  
	msg += legText;
	msg += "<hr>";
	//msg += "<small>This window will close automatically in <FONT COLOR=RED> 15 </FONT>secs</small>";
	msg += "</body></html>";
	winPop(msg);   
}


//SCRIPT:9
//SUBMIT FORM FOR ALBUM VIEW.
function submitForm(act,mode) { 

	document.displayResultForm.command.value = act; 
	document.displayResultForm.mode.value = mode; 
	document.displayResultForm.submit(); 
}

//SCRIPT:10
//SUBMIT FORM FOR ALBUM PAGE BY PAGE BROWSE.
function submitAlbumForm(act,mode,page) { 
	document.displayResultForm.command.value = act; 
	document.displayResultForm.mode.value = mode; 
	document.displayResultForm.oldpage.value = page; 
	document.displayResultForm.submit(); 
}



//SCRIPT:11
//THIS SCRIPT WILL BE USED IN ORDER FORM TO VALIDATE THE FIELDS.
function validateOrderForm(){
  var validOrder = true;
  var errorMessage = "";
  if (document.orderform.email.value == ""){
	errorMessage += "Missing Email Address\n";
	validOrder = false;
  }else if ( (document.orderform.email.value.indexOf ('@',0) == -1) ||
	     (document.orderform.email.value.indexOf ('.',0) == -1) &&
	     (document.orderform.email.value != "")
   	   ){
  	  errorMessage += "Not a valid Email Address\n";
	  validOrder = false;
  	}
  		  
  	if (document.orderform.acctnum.value==null || document.orderform.acctnum.value==""){
  		errorMessage +="Enter a valid Account Number.\n";
  		validOrder = false;
  	}

  	if (document.orderform.person.value==null || document.orderform.person.value==""){
  		errorMessage +="Person Name is missing in order information\n";
    		validOrder = false;
  	}

  	if (document.orderform.shipping.options[0].selected == true){
  		errorMessage +="Please select a valid shipping mode from the drop-down list\n";
  		validOrder = false;
	}

  	
  	if (document.orderform.address.value==null || document.orderform.address.value==""){
  		errorMessage += "Please enter a valid order destination address\n";
  		validOrder = false;
  	}

	 if (document.orderform.orderTypeCheck.value =='quickOrder'){
	    if (document.orderform.quickdigital.options[0].selected == true){
	  		errorMessage += "Please select a valid Media Type for quick order\n";
	  		validOrder = false;
	    }else{
	        if (document.orderform.quickqty.value == '0' || document.orderform.quickqty.value == ""){
		  		errorMessage += "The quantity for quick Media type seems to be invalid\n";
		  		validOrder = false;
		     }
		}
	 }

  	if (errorMessage!=""){
  		alert("The following fields are not valid\n\n" + errorMessage + "\nResubmit your order.\n" );
  	}
  	return validOrder;
}

//SCRIPT:12
// THIS IS USED TO DISPLAY WINDOW FOR LIMIATIONS.
function winPop(text) {
	newWindow = window.open("","newWin","Scrollbars=yes,width=500,height=200");
	newWindow.document.write(text);
	newWindow.focus();
	//setTimeout('closeWin(newWindow)', 15 * 1000); // delay 15 secs before auto-closing
}


//SCRIPT:
//This is used for deselect all in the album,search,workspace page etc.
var startcnt = 0;
var endcnt = 0;
var selectAllCounter = 0;
var deSelectAllCounter = 1;
function findlistvals () {
	var n;
	if ((startcnt == 0) && (endcnt == 0)) { 
		for (n = 0; n < document.displayResultForm.elements.length; n++) { 
			if (document.displayResultForm.elements[n].name == "startelementlist") {
				startcnt = n+1;
			}
			if (document.displayResultForm.elements[n].name == "endelementlist") { 
				endcnt = n;
				if (startcnt > 0) {
					break;  
				}
			}
		}
	 }
}
//select all in album/search etc.
function checkAll() {
	var n;
	findlistvals();
	for (n = startcnt; n < endcnt; n++) { 
		document.displayResultForm.elements[n].checked = true;
	}
	selectAllCounter++;
	deSelectAllCounter = 0;
}

function unCheckAll(){
	var n;
	findlistvals();
	for (n = startcnt; n < endcnt; n++) {
		document.displayResultForm.elements[n].checked = false;
	}
	selectAllCounter = 0;
	deSelectAllCounter++;
}


//SCRIPT:
//THIS IS USED TO OPEN URL IN A NEW WINDOW of destined height/width.
function popUp(url, wid, hgt)
{
        if (wid == "" || wid == null){
	    wid = 400;
	}
	if (hgt == "" || hgt == null){
	   hgt = 550;
	}
	var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes" + ",width=" + wid + ",height=" + hgt;
	myWin=window.open(url,"DMR",windowprops);
	myWin.focus();                                  
}


//SCRIPT:
//THIS IS USED FOR CALCULATING FILE DOWNLOAD TIME.
function compute(fsize){
  fileRatio = new Array( new Array("28.8 Modem","3.5156"),new Array("56 modem","6.8359"),new Array("T1 (1.54 Mb)","187.9883"));
  // This is the  function that calculates times

  if (fsize==null||fsize.length==0)
  {
     fsize=0;
  }
  msg =  "<html><head><title>Digital Media Repository</title><body>";
  msg += "<strong>File Size: </strong>";
  msg += fsize + ' Mb';
  msg += "<BR><strong>The following are the file download Estimates:</strong>";
  msg += "<BR><BR>";
  msg += "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"350\">";
  msg += "<tr>";
  msg += "<td width=\"100\"><p align=\"center\"><strong>Connection</strong></td>";
  msg += "<td width=\"250\"><p align=\"center\"><strong>Estimated Time(H:M:S)</strong></td>";
  msg += "</tr>";
  // test input for error values and make zero if wrong
  for (i=0; i < 3; i++){
      msg += "<tr>";
      msg += "<td width=\"100\"><p align=\"center\">" + fileRatio[i][0] + "</td>";
      with (Math){
            var speed = fileRatio[i][1];
            var TotalTime = ((fsize)*1024/speed);
            var TotalHours = floor((TotalTime/3600));
	    var TotalHoursMod = (TotalTime%3600);
	    var TotalMin = floor(TotalHoursMod/60);
	    var TotalMinMod = (TotalHoursMod%60);
	    var TotalSec = floor(TotalMinMod);
	    var dispTime = TotalHours + ':' + TotalMin + ':' + TotalSec;
	    msg += "<td width=\"250\"><p align=\"center\">" + dispTime + "</td>";
     }
     msg += "</tr>";
  }
  msg += "</table><hr>";
  msg += "</body></html>";
  winPop(msg);
}

//SCRIPT
//THIS SCRIPT IS USED FOR PHOTO LIBRARY USERS.
function setVisible(What,Value) {

    if (document.layers && document.layers[What] != null) document.layers[What].visibility = Value;
    else if (document.all) eval('document.all.'+What+'.style.visibility ="'+ Value+'"');
}

//SCRIPT
//THIS SCRIPT IS USED FOR PHOTO LIBRARY USERS.

function setStatus(Form,Radio,Layer) {

    for (var i=0; i<Form[Radio].length; i++) {
        if (Form[Radio][i].checked) setVisible(Layer,Form[Radio][i].value);
    }
}  

//SCRIPT
//THIS SCRIPT IS USED FOR PHOTO LIBRARY USERS.

function photoUserSubmitForm() {
   for(i=0;i<document.photoForm1.stat.length;i++){
       if(document.photoForm1.stat[i].checked==true){
          document.photoForm3.user.value=document.photoForm1.stat[i].value;
       }
   }
document.photoForm3.country.value=document.photoForm2.country[document.photoForm2.country.selectedIndex].value;
document.photoForm3.submit();
}

//SCRIPT
//FOR ALBUM MANAGE CODE

function submitAlbumManageForm() {
	for (var i=0; i< document.albumManageForm.manage.length; i++) {
		if (document.albumManageForm.manage[i].checked){

			document.albumManageForm.command.value = document.albumManageForm.manage[i].value;
                if (document.albumManageForm.manage[i].value == "AlbumUserProcess-Delete"){
					   if (confirm("Are you sure you want to delete the Album  \""+ document.albumManageForm.albumJobId[document.albumManageForm.albumJobId.selectedIndex].text +"\"?")) {
							 document.albumManageForm.submit();	
					   }	
                }else if (document.albumManageForm.manage[i].value == "AlbumProcess-Copy"){
						 if (
						 		(document.albumManageForm.albumName.value == 'Not Available')		||
						 		(document.albumManageForm.albumName.value == 'Enter Album Name')
						 	){	
									alert("Album Name is invalid! re-enter a valid name");
                         }else if (
									     (document.albumManageForm.albumPassword.value ==  '') ||
								 	    (document.albumManageForm.albumPassword1.value ==  '')
     			                     ){
										alert("Password cannot be blank! enter a Valid Password");
                         }else if 
                            (document.albumManageForm.albumPassword.value != document.albumManageForm.albumPassword1.value)	 {
									alert("Password re-entered does not match! make sure both password entered matches");
						 }else{
								document.albumManageForm.submit();
						 }
				}else {
					    document.albumManageForm.submit();
	            }
    	}//end of if.
	}//end of for
}

//SCRIPT
//FOR ALBUM MANAGE CODE

function lockField()  {   
    document.albumManageForm.albumName.disable=true;
    document.albumManageForm.albumPassword.disable=true;
    document.albumManageForm.albumPassword1.disable=true;

    document.albumManageForm.albumName.value="Not Available";
    document.albumManageForm.albumPassword.value='Not Available';
    document.albumManageForm.albumPassword1.value='Not Available';

}

//SCRIPT
//FOR ALBUM MANAGE CODE

function unLockField(val){
    document.albumManageForm.albumName.disable=false;
    document.albumManageForm.albumName.value='Enter Album Name';

    document.albumManageForm.albumPassword.disable=false;

    document.albumManageForm.albumPassword.value='';
    document.albumManageForm.albumPassword1.value='';
    document.albumManageForm.albumPassword1.disable=true;
    if (val == '1'){		
	    document.albumManageForm.albumPassword1.disable=false;
	    document.albumManageForm.albumPassword1.value='';

    }
}

//SCRIPT
//FOR ALBUM MANAGE CODE
	 
function clearValue(){
  if ( document.albumManageForm.albumName.value == 'Enter Album Name'){
    document.albumManageForm.albumName.value='';
  }
  for (var i=0; i< document.albumManageForm.manage.length; i++) {
       if (document.albumManageForm.manage[i].checked){
	if (document.albumManageForm.manage[i].value == "AlbumProcess-ManageView"){
                         lockField();
                  }
       }
  }
}


//SCRIPT: FOR USE IN ALBUM MANAGE.
//FOR ALBUM UPDATE FORM

function lockUnlock(_v)
{

    if(_v==1){
        if (document.albumUpdateForm.expireUpdate.checked){
			document.albumUpdateForm.expirYYYY.disabled = false;
			document.albumUpdateForm.expirMM.disabled = false;
			document.albumUpdateForm.expirYYYY.disable = false;
			document.albumUpdateForm.expirMM.disable = false;
        }else{
			document.albumUpdateForm.expirYYYY.disabled = true;
			document.albumUpdateForm.expirMM.disabled = true;
			document.albumUpdateForm.expirYYYY.disable = true;
			document.albumUpdateForm.expirMM.disable = true;
        }
    }else  if(_v==2){
	   if (document.albumUpdateForm.passwordChange.checked){
            document.albumUpdateForm.albumPassword.disabled = false;
            document.albumUpdateForm.albumPassword1.disabled = false;
            document.albumUpdateForm.albumPassword.disable = false;
            document.albumUpdateForm.albumPassword1.disable = false;

        }else{
            document.albumUpdateForm.albumPassword.disabled = true;
            document.albumUpdateForm.albumPassword1.disabled = true;
            document.albumUpdateForm.albumPassword.disable = true;
            document.albumUpdateForm.albumPassword1.disable = true;

        }
     }else if (_v ==3){
        if (document.albumUpdateForm.supplierCodeAll.checked){
				document.albumUpdateForm.supplierCode.disabled = true;
				document.albumUpdateForm.supplierCode.disable = true;
        }else{
        		document.albumUpdateForm.supplierCode.disabled = false;
			document.albumUpdateForm.supplierCode.disable = false;
        }
     }
}

//SCRIPT: FOR USE IN ALBUM MANAGE

function submitAlbumUpdateForm() {
  // PrepareLanguage_SelectedTexts(document.forms[1]);
   PrepareLanguage_SelectedTexts(document.albumUpdateForm);

   if (document.albumUpdateForm.passwordChange.checked){
       if (
	     (document.albumUpdateForm.albumPassword.value ==  '') ||
	     (document.albumUpdateForm.albumPassword1.value ==  '')
       ){
	  alert("Password cannot be blank! enter a Valid Password");
       }else if (	
	    (document.albumUpdateForm.albumPassword.value != document.albumUpdateForm.albumPassword1.value)
       ){
	    alert("Password re-entered does not match! make sure both password entered matches");
       }else{
	       document.albumUpdateForm.submit();
       }
   }else if ( 
         	(document.albumUpdateForm.testPrefix_class2_string[document.albumUpdateForm.testPrefix_class2_string.selectedIndex].text == '----------------------------------------------------------------')	||
 			(document.albumUpdateForm.testPrefix_class2_string[document.albumUpdateForm.testPrefix_class2_string.selectedIndex].text == '')
 			){
 				alert("Select a valid language qualifier from the drop down list");
   }else{
	   document.albumUpdateForm.submit();
   }
}

//SCRIPT : FOR USE IN ALBUM CREATE
function checkField()
{
   if (document.albumCreateForm.supplierCodeAll.checked){
	document.albumCreateForm.supplierCode.disabled = true;
	document.albumCreateForm.supplierCode.disable = true;
   }else{
	document.albumCreateForm.supplierCode.disabled = false;
	document.albumCreateForm.supplierCode.disable = false;
   }
}

//SCRIPT : FOR USE IN PHOTO LIBRARY
function unlockPhoto()
{
	document.photoActivation.country.disabled = false;
	document.photoActivation.country.disable = false;
}

function lockPhoto()
{
	document.photoActivation.country.disable = true;
	document.photoActivation.country.disabled = true;
}


function submitPhotoUser(){
	if (validatephotoActivationForm()){
	   document.photoActivation.submit();
	}
}

function validatephotoActivationForm(){

  var validPhoto = true;
  var errorMessage = "";
  if (document.photoActivation.email.value == ""){
	errorMessage += "Missing Email Address\n";
	validPhoto = false;
  }else if ( (document.photoActivation.email.value.indexOf ('@',0) == -1) ||
	     (document.photoActivation.email.value.indexOf ('.',0) == -1) &&
	     (document.photoActivation.email.value != "")
   	   ){
  	  errorMessage += "Not a valid Email Address\n";
	  validPhoto = false;
  }
  		  
  if (document.photoActivation.pin.value==null || document.photoActivation.pin.value==""){
  	errorMessage +="Enter a valid Pin.\n";
  	validPhoto = false;
  }

  if (document.photoActivation.person.value==null || document.photoActivation.person.value==""){
  	errorMessage +="Person Name is missing in the information\n";
  	validPhoto = false;
  }
  if (document.photoActivation.phone.value==null || document.photoActivation.phone.value==""){
  	errorMessage +="Telephone number is missing in the information\n";
  	validPhoto = false;
  }

  if (document.photoActivation.supName.value==null || document.photoActivation.supName.value==""){
  	errorMessage +="Supervisor/Manager Name is missing in the information\n";
  	validPhoto = false;
  }
 //added by subbarao as part of converting photouser screen as jsp
 if (document.photoActivation.comment.value==null || document.photoActivation.comment.value==""){
  	errorMessage +="Catalog name is missing in the information\n";
  	validPhoto = false;
  }
//end changes
  if (errorMessage!=""){
     alert("The following fields are not valid\n\n" + errorMessage + "\nResubmit your user activation request.\n" );
  }

   return (validPhoto);
}

//SCRIPT:
//FOR CONTACT SUBMIT.

function submitContactUser(){
	if (validateContactUserForm()){
	   document.contactUserForm.submit();
	}
}

function validateContactUserForm(){
  var validContact = true;
  var errorMessage = "";
  if (document.contactUserForm.email.value == ""){
	errorMessage += "Missing Email Address\n";
	validContact = false;
  }else if ( (document.contactUserForm.email.value.indexOf ('@',0) == -1) ||
	     (document.contactUserForm.email.value.indexOf ('.',0) == -1) &&
	     (document.contactUserForm.email.value != "")
   	   ){
  	  errorMessage += "Not a valid Email Address\n";
	  validContact = false;
  	}
  		  
  	if (document.contactUserForm.person.value==null || document.contactUserForm.person.value==""){
  		errorMessage +="Person Name is missing in the contact information\n";
    		validContact = false;
  	}
  	//added by subbarao as part of converting dmrcontact screen as JSP
  	if (document.contactUserForm.comment.value==null || document.contactUserForm.comment.value==""){
  		errorMessage +="Comments are missing in the contact information\n";
    		validContact = false;
  	}
    //end changes
   	if (errorMessage!=""){
  		alert("The following fields are not valid\n\n" + errorMessage + "\nResubmit your contact form.\n" );
  	}
  	return (validContact);
}
//SCRIPT FOR USERREGISTRATION.
function submitUserRegistration(){
	if (document.registrationUserForm.userID.value == ""){
	    alert("Invalid User-ID");
	}else{	
	   document.registrationUserForm.submit();
	}

}


//SCRIPT FOR SHIFTING CATEGORY ADVANCED SEARCH.
function CheckAndAdjust (box,field,action){
	box.checked=(field.selectedIndex != 0);
	var i = field.options.selectedIndex;
	var value = field.options[field.options.selectedIndex].value
	if (value == "ID"	|| value == "RESOLN"	|| value == "HEIGHT"	|| value == "WIDTH"	|| value == "FILESIZE"	|| value == "SCREENRES"	|| value == "PRINTRES"	|| value == "PROOFCNT"	|| value == "FINALCNT"	|| value == "TOUCHCNT"	|| value == "BITS_PIXEL"	|| value == "LOG_DATE"	|| value == "LOG_TIME"	|| value == "TOUCHDATE"	|| value == "LSTPRNTON"	|| value == "NUMPLANES") {
        SetActionMenu("number",action);
    } else if(value == "GROUPNAME"){
   	    SetActionMenu("VSRM",action);
    } else {
        if (value == "INUSE"	    || value == "LOCKED"	    || value == "PRINTVF"	    || value == "HASRGBVF"	    || value == "SCHEDULED") {
	    SetActionMenu("boolean",action);
        } else {
	    // default case
   	    SetActionMenu("string",action);
		}
    }
}


function skip () { this.blur(); }

function disableTextField (field)
{
    field.oldOnFocus = field.onfocus;
    field.onfocus = skip;
    field.disabled = true;
}

function enableTextField (field) 
{
    field.onfocus = ""; //field.oldOnFocus;
    field.disabled = false;
}

function Enable(booleanField,field,action, textfield)
{
	var value = booleanField.options[booleanField.options.selectedIndex].text;
	if (value == "")
	{
		field.options.selectedIndex = 0;
		disableTextField(field);
		action.options.selectedIndex = 0;
		disableTextField(action);
		textfield.value = "";
		disableTextField(textfield);
	}
	else
	{
		enableTextField(field);
		enableTextField(action);
		enableTextField(textfield);
	}
}

function enableSearchSelections()
{
   form = document.searchform;

   var action1Index = form.c1_action.options.selectedIndex;
   CheckAndAdjust(form.c1_field,form.c1_realfield,form.c1_action)
   form.c1_action.options.selectedIndex = action1Index;
   var action2Index = form.c2_action.options.selectedIndex;
   CheckAndAdjust(form.c2_field,form.c2_realfield,form.c2_action)
   form.c2_action.options.selectedIndex = action2Index;
   var action3Index = form.c3_action.options.selectedIndex;
   CheckAndAdjust(form.c3_field,form.c3_realfield,form.c3_action)
   form.c3_action.options.selectedIndex = action3Index;
   var action4Index = form.c4_action.options.selectedIndex;
   CheckAndAdjust(form.c4_field,form.c4_realfield,form.c4_action)
   form.c4_action.options.selectedIndex = action4Index;
   var action5Index = form.c5_action.options.selectedIndex;
   CheckAndAdjust(form.c5_field,form.c5_realfield,form.c5_action)
   form.c5_action.options.selectedIndex = action5Index;

   enableNextRow(form.c1_action, form.c2_field, form.c2_realfield, form.c2_action, form.c2_string);
   enableNextRow(form.c2_action, form.c3_field, form.c3_realfield, form.c3_action, form.c3_string);
   enableNextRow(form.c3_action, form.c4_field, form.c4_realfield, form.c4_action, form.c4_string);
   enableNextRow(form.c4_action, form.c5_field, form.c5_realfield, form.c5_action, form.c5_string);
   
   adjust(form.class1_string,form.class1_string.selectedIndex,1,form.class1_field);
	if (form.class2_search.value != "0")
	{
		for (i = 0; i < form.class2_string.length; i++) 
		{
			if (form.class2_string[i].text == form.class2_search.value) 
			{
				form.class2_string.selectedIndex = i;
			   adjust(form.class2_string,form.class2_string.selectedIndex,2,form.class2_field);
			}
		}

	}
	if (form.class3_search.value != "0")
	{
		for (i = 0; i < form.class3_string.length; i++) 
		{
			if (form.class3_string[i].text == form.class3_search.value) 
			{
				form.class3_string.selectedIndex = i;
			   adjust(form.class3_string,form.class3_string.selectedIndex,3,form.class3_field);
			}
		}

	}
}


function enableNextRow(action1, booleanField, field, action, textfield)
{
	var value = action1.options[action1.options.selectedIndex].text;
	if (value == "")
	{
		booleanField.options.selectedIndex = 0;
		disableTextField(booleanField);
		field.options.selectedIndex = 0;
		disableTextField(field);
		action.options.selectedIndex = 0;
		disableTextField(action);
		textfield.value = "";
		disableTextField(textfield);
	} else
	{
		enableTextField(booleanField);
		Enable(booleanField,field,action, textfield);		
	}
}

function SetActionMenu(type,actionfield) {
    actionfield.options.length = 0;  // clear old options
    actionfield.options[0] = new Option("","0",true);
    if (type == "number") {
	actionfield.options[1] = new Option("is equal to","is equal to",false);
	actionfield.options[2] = new Option("is greater than","is greater than",false);
	actionfield.options[3] = new Option("is less than","is less than",false);
	actionfield.options[4] = new Option("is greater than or equal to","is greater than or equal to",false)
	actionfield.options[5] = new Option("is less than or equal to","is less than or equal to",false);
    } else {
	if (type == "boolean") {
	    actionfield.options[1] = new Option("is true","is true",false);
	    actionfield.options[2] = new Option("is false","is false",false);
	} else if (type == "VSRM") {
	    actionfield.options[1] = new Option("is","is",false);
	    actionfield.options[2] = new Option("starts with","starts with",false);
	    actionfield.options[3] = new Option("contains","contains",false);
	    actionfield.options[4] = new Option("is blank","is blank",false);
	    actionfield.options[5] = new Option("is not blank","is not blank",false);
	} else {
	    actionfield.options[1] = new Option("is","is",false);
	    actionfield.options[2] = new Option("is not","is not",false);
	    actionfield.options[3] = new Option("starts with","starts with",false);
	    actionfield.options[4] = new Option("contains","contains",false);
	    actionfield.options[5] = new Option("is blank","is blank",false);
	    actionfield.options[6] = new Option("is not blank","is not blank",false);
	}
    }
}
function Family (parent,parentid,children,level) {
	this.parent = parent;
	this.parentid = parentid;
	this.children = children;
	this.level = level;
}

function adjust (parentmenu,value,level,checkbox) {
    treeSubjects();
    var chosenText = parentmenu[value].text;
    var chosenValue = parentmenu[value].value;
	if (done == "advancedsearch") 
	{
		checkbox.checked = (value != 0);
    	for (q = 0; q <= document.searchform.elements.length; q++) 
		{
			if (document.searchform.elements[q] == parentmenu) 
			{
				if (level < 3) 
				{
					kidmenu = document.searchform.elements[q+4];
					blankmenu(kidmenu);
					kidcheckbox = document.searchform.elements[q+1];
					kidcheckbox.checked = 0;
				}
				if (level < 2) 
				{
					baby = document.searchform.elements[q+8];
					blankmenu(baby);
					babycheckbox = document.searchform.elements[q+5];
					babycheckbox.checked = 0;
			    }

			    break;
			}
		}
	} else 	if (done == "Language") 
	{
    	for (q = 0; q <= document.forms[0].elements.length; q++) 
		{
			if (document.forms[0].elements[q] == parentmenu) 
			{
				if (level < 2) 
				{
					kidmenu = document.forms[0].elements[q+1];
					blankmenu(kidmenu);
				}
			    break;
			}
		}
	} else 
	{
		checkbox.checked = (value != 0);
    	for (q = 0; q <= document.searchform.elements.length; q++) 
    	{
			if (document.searchform.elements[q] == parentmenu) 
			{
			    if (level < 5) 
			    {
					kidmenu = document.searchform.elements[q+3];
					blankmenu(kidmenu);
					kidcheckbox = document.searchform.elements[q+1];
					kidcheckbox.checked = 0;
				}
				if (level < 4) 
				{
					baby = document.searchform.elements[q+6];
					blankmenu(baby);
					babycheckbox = document.searchform.elements[q+4];
					babycheckbox.checked = 0;
				}
				if (level < 3) 
				{
					baby = document.searchform.elements[q+9];
					blankmenu(baby);
					babycheckbox = document.searchform.elements[q+7];
					babycheckbox.checked = 0;
				}
				if (level < 2) 
				{
					baby = document.searchform.elements[q+12];
					blankmenu(baby);	
					babycheckbox = document.searchform.elements[q+10];
					babycheckbox.checked = 0;
				}
				break;
			}
	    }
    }

    var len = families.length;
    for (x = 0; x < len; x++) 
    {
		if (families[x].parent == chosenText
			&& families[x].parentid == chosenValue
			&& families[x].level == level) 
		{
			var kids = families[x].children.length;
			var kiddies = new Array;
			kiddies = families[x].children;

		    with (kidmenu) 
		    {
			// sort the kids out by name

				options[0] = new Option(blankstring,"0",true);
                for (var i=0; i < kids;i++) 
                {
                    options[options.length]=kiddies[i];
	        	}
          		options[0].selected=true;
		    }
		}
	}
}

function blankmenu (blankee) {
    with (blankee) {
	options.length = 0;
	options[0] = new Option(blankstring, "0", "1", "1");
     }
}

function NameSort (a,b) {
    if (a.text < b.text) {
        return -1;
    }
    if (a.text > b.text) {
        return 1;
    }
    return 0;
}
function PrepareSelectedTexts() {
    searchmenus = new Array;
    searchmenus[searchmenus.length] = document.searchform.class1_string;
    searchmenus[searchmenus.length] = document.searchform.class2_string;
    searchmenus[searchmenus.length] = document.searchform.class3_string;
 
    hiddens = new Array;
    hiddens[hiddens.length] = document.searchform.class1_search;
    hiddens[hiddens.length] = document.searchform.class2_search;
    hiddens[hiddens.length] = document.searchform.class3_search;
    hiddens[hiddens.length] = document.searchform.class4_search;
    hiddens[hiddens.length] = document.searchform.class5_search;

    for (i = 0; i < searchmenus.length; i++) {
	menu = searchmenus[i];
	if (menu.options[menu.selectedIndex].text == blankstring) {
            // do nothing; it's just the sizer string
        } else {
            hiddens[i].value = menu.options[menu.selectedIndex].text;
        }
    }
}


function saveInfoPopupWin() {
  msg =  "<html><head><title>Digital Media Repository</title><body>";
  msg += "<strong>Hi , What does <i>Save Info </i>  Mean &#63 </strong><br> Your browser can remember your Name, email-id, account number and address";
  msg += " that you enter while placing the order.  If you check the box, then you are not required to enter the information each time you come back.<br>";
  msg += "<br><strong>What happens if I want change information that is been displayed &#63</strong><br> If you want to update information"; 
  msg += " like change of delivery address, account number etc. type the new information and check the <strong>Save Info</strong> box. ";
  msg += " Next time when you come back, the new information will be displayed.<br> If you prefer to retain old information, and use the changes only for this session, do not check the <strong>Save Info </strong> box.";
  msg += "<hr>";
  msg += "</body></html>";
  winPop(msg);   
}

//SCRIPT TO VALIDATE GROUP

function validateGroup()
{
 var validGroup = false;
  for(var i=0;i<document.chooseagroup.groupName.length;i++){
    if(document.chooseagroup.groupName[i].checked == true){
	validGroup = true;		
    }
  }
  if (validGroup){
      document.chooseagroup.submit();
  }else{
	alert ("Choose a group to continue login");
  }
}

//SCRIPT XX FOR Toggle between QUICK/DETAIL ORDER display.
function toggleQuickDetailOrder(act) { 
	document.orderform.command.value = act; 
	document.orderform.submit(); 
}

function copyIT(){
   document.displayResultForm.albumUrlDisplay.value = document.displayResultForm.albumURL.value;
}

function countIt(chkbox)
{

  
  var cnt = 0;
  //we will get previous selected element count.
  var previousCount = parseInt(document.displayResultForm.elementCount.value);
  var obj_ = "document.displayResultForm.action"+chkbox+".checked";
  if (eval(obj_)){
      cnt++;
  }else{
      cnt--;
  }
  //this will return already select element in a given page.
  var alreadySelected = parseInt(document.displayResultForm.selectedElementCount.value);
  var newElementCount = alreadySelected + cnt;
  document.displayResultForm.selectedElementCount.value = newElementCount.toString();
  newElementCount = previousCount + cnt;
  document.displayResultForm.elementCount.value= newElementCount.toString();
}

function countItAll(){
  with (document.displayResultForm) {
    var selecting = false;
    var previousTotal = parseInt(document.forms["displayResultForm"].elementCount.value);
    var currentCount = 0 - parseInt(document.forms["displayResultForm"].selectedElementCount.value);
    var currentSelect = 0;
    document.forms["displayResultForm"].selectedElementCount.value=0;
    var totalCheckBox = 0;
    for (var i=0; i < elements.length; i++) {
        if (elements[i].type == 'checkbox'){
           totalCheckBox++;
           //we are looking for action	
            var elementName = elements[i].name.substring(0,6);
            if (elementName == "action"){
					elements[i].checked?currentSelect++:currentSelect--;
           }
        }
     }//end of for loop
   }//end of with.
    var newCount = 0;

    if (currentSelect > 0){
        if (selectAllCounter > 1){
			currentSelect = 0;
		}        
	}else{
	   if (deSelectAllCounter > 1){
	       currentSelect = 0;
	   }
	 }  

    newCount = previousTotal + currentCount + currentSelect;
    if (newCount < 0){
         newCount = 0;
    }
    document.forms["displayResultForm"].elementCount.value =  newCount.toString();
}
function submitMultiLanguageForm(act,mode,page) { 
	document.mkplNameForm.command.value = act; 
	document.mkplNameForm.mode.value = mode; 
	document.mkplNameForm.oldpage.value = page; 
	document.mkplNameForm.submit(); 
}

function submitToMultiLanguageForm(dbname,mode,id)
{
	document.displayResultForm.command.value = 'MultiLanguageUpdate';
	document.displayResultForm.dbname.value = dbname; 
	document.displayResultForm.mode.value = mode; 
	document.displayResultForm.dmrId.value = id; 
	document.displayResultForm.submit(); 
}

//SCRIPT:
//This form is to refresh the album based on language selected
function refreshAlbum(act,mode) { 
   PrepareLanguage_SelectedTexts(document.forms[0]);
	document.displayResultForm.command.value = act; 
	document.displayResultForm.mode.value = mode; 
	document.displayResultForm.submit(); 
}

//SCRIPT:  
//THIS SCRIPT IS USED FOR ALBUM CREATE SUBMIT.
//THIS WILL VALIDATE THE LANGUAGE QUALIFIER DROP-DOWN LIST.
function submitAlbumCreateForm() {
		//changes made by subbarao as look and feel chnages
		//PrepareLanguage_SelectedTexts(document.forms[1]);
		PrepareLanguage_SelectedTexts(document.albumCreateForm);
		//end
			if ( 
				(document.albumCreateForm.testPrefix_class2_string[document.albumCreateForm.testPrefix_class2_string.selectedIndex].text == '----------------------------------------------------------------')	||
			 	(document.albumCreateForm.testPrefix_class2_string[document.albumCreateForm.testPrefix_class2_string.selectedIndex].text == '')
			){
				alert("Select a valid language qualifier from the drop down list");
	        }else if  (document.albumCreateForm.albumName.value == ''){
								alert("Album name cannot be blank");
            }else if (
					     (document.albumCreateForm.albumPassword.value ==  '') ||
					     (document.albumCreateForm.albumPassword1.value ==  '')
		                ){
								alert("Password cannot be blank! enter a Valid Password");
            }else if   (document.albumCreateForm.albumPassword.value != document.albumCreateForm.albumPassword1.value) {
								alert("Password re-entered does not match! make sure both password entered matches");
			}else{
				   document.albumCreateForm.submit();
			}
}
	//SCRIPT:  
	//THIS SCRIPT IS USED FOR NAVIGATION THROUGH ALBUM CONTROL 
	//DROP DOWN BY TYPING NAME.
	function getIt(theForm,theValue,theSelect) {
	  theValue = theValue.toLowerCase(); 
	  var theIndex = theSelect.selectedIndex;
	  if (theIndex ==-1) theIndex = 0;
	  for (var i=0,n=theSelect.options.length;i<n;i++) {
	     if (theSelect.options[i].text.toLowerCase().indexOf(theValue) == 0) {
	        theSelect.selectedIndex=i;
	        break;
	     }
	  }
	} 
	
//SCRIPT:
//ThIS SCRIPT IS USED FOR SUBMITTING ALBUM VERSION FORM
//WITH VALIDATION
function submitAlbumVersionForm() {
       if (
	     (document.albumVersionForm.albumPassword.value ==  '') ||
	     (document.albumVersionForm.albumPassword1.value ==  '')
       ){
		  alert("Password cannot be blank! enter a Valid Password");
       }else if (	
	    (document.albumVersionForm.albumPassword.value != document.albumVersionForm.albumPassword1.value)
       ){
		    alert("Password re-entered does not match! make sure both password entered matches");
       }else if ( 
         	(document.albumVersionForm.dmrPin.value == '')	||
 			(document.albumVersionForm.dmrPin1.value  == '')
 		){
 				alert("3M pin entered should not be blank");
 		}else if ( 
         	(document.albumVersionForm.dmrPin.value.toUpperCase() == 'GUEST')	||
 			(document.albumVersionForm.dmrPin1.value.toUpperCase()  == 'guest')
 		){
 				alert("Guest is not a valid 3M Pin");
 		}else if (
 		 		(document.albumVersionForm.dmrPin.value != document.albumVersionForm.dmrPin1.value)
        ){
		    alert("3M pin re-entered does not match! make sure both pin entered matches");
	   }else{
		   document.albumVersionForm.submit();
 	   }
}
//SCRIPT 
//THIS IS USED FOR ORDER FORM SUBMIT.
function submitOrderFormOne(act) { 
	if (
			(document.orderform.supplierCode.value ==  '' )  ||
			(document.orderform.supplierCode.value ==  'none' ) 
		){
		   alert('Select a valid supplier');
		 }else{
				document.orderform.submit(); 
		}
}

//SCRIPT 
//THIS IS USED TO LOCK FIELDS FOR ORDER PAGE
function lockDigital() {
  var _T = "locked";
  document.orderform.quickdigital.disabled=_T; 
}


//SCRIPT 
//THIS IS USED TO LOCK FIELDS FOR ORDER PAGE
function lockSupplier() {
  var _T = "locked";
  document.orderform.supplierCode.disabled=_T; 
}

//SCRIPT 
//THIS IS USED TO LOCK FIELDS FOR ORDER PAGE
function lockShipping() {
  var _T = "locked";
  document.orderform.shipping.disabled=_T; 
}

//SCRIPT 
//THIS SCRIPT IS USED FOR REPORT GENERATION
function submitReportForm() { 
	document.ReportForm.command.value = 	document.ReportForm.reportType[document.ReportForm.reportType.selectedIndex].value; 
	document.ReportForm.submit(); 
}
function lockReportField() {
    if  (document.ReportForm.reportType[document.ReportForm.reportType.selectedIndex].value == 'ReportDesktopClient'){
		document.ReportForm.startMonth.disabled = true;
		document.ReportForm.startDay.disabled = true;
		document.ReportForm.startYear.disabled = true;
		document.ReportForm.reportFormat.disabled = true;
    }else{
		document.ReportForm.startMonth.disabled = false;
		document.ReportForm.startDay.disabled = false;
		document.ReportForm.startYear.disabled = false;
		document.ReportForm.reportFormat.disabled = false;
    }
}
//Scritp for DMRWEB/Desktop report generation.
function prefillReportForm() {
	for (var i=0; i< document.reportForm.reportSubType.length; i++) {
	      if (document.reportForm.reportSubType[i].checked){
			if (document.reportForm.reportSubType[i].value == "buTotal"){
				    document.reportForm.action_businessUnit.checked = true;
				    document.reportForm.action_media.checked = false;	
				    document.reportForm.action_status.checked  = true;	
				    document.reportForm.action_contentType.checked = false;
				    document.reportForm.action_ownerpin.checked = false;
				    document.reportForm.action_uploadedBy.checked = false;
			   	    document.reportForm.action_errorReport.checked = false;
				    document.reportForm.action_logDate.checked = false;
				    document.reportForm.action_filename.checked = false;
				    document.reportForm.action_marketplaceName.checked = false;
	 	   	}else if (document.reportForm.reportSubType[i].value == "mediaContentTotal"){
				    document.reportForm.action_businessUnit.checked = false;
				    document.reportForm.action_media.checked = true;	
				    document.reportForm.action_status.checked  = true;	
				    document.reportForm.action_contentType.checked = true;
				    document.reportForm.action_ownerpin.checked = false;
				    document.reportForm.action_uploadedBy.checked = false;
			   	    document.reportForm.action_errorReport.checked = false;
				    document.reportForm.action_logDate.checked = false;
				    document.reportForm.action_filename.checked = false;
				    document.reportForm.action_marketplaceName.checked = false;
			}else if (document.reportForm.reportSubType[i].value == "errorReportTotal"){
				    document.reportForm.action_businessUnit.checked = false;
				    document.reportForm.action_media.checked = false;	
				    document.reportForm.action_status.checked  = false;	
				    document.reportForm.action_contentType.checked = true;
				    document.reportForm.action_ownerpin.checked = true;
				    document.reportForm.action_uploadedBy.checked = true;
			   	    document.reportForm.action_errorReport.checked = true;
				    document.reportForm.action_logDate.checked = false;
				    document.reportForm.action_filename.checked = false;
				    document.reportForm.action_marketplaceName.checked = false;
			}else if (document.reportForm.reportSubType[i].value == "blankReportTotal"){
				    document.reportForm.action_businessUnit.checked = false;
				    document.reportForm.action_media.checked = false;	
				    document.reportForm.action_status.checked  = false;	
				    document.reportForm.action_contentType.checked = false;
				    document.reportForm.action_ownerpin.checked = false;
				    document.reportForm.action_uploadedBy.checked = false;
			   	    document.reportForm.action_errorReport.checked = false;
				    document.reportForm.action_logDate.checked = true;
				    document.reportForm.action_filename.checked = true;
				    document.reportForm.action_marketplaceName.checked = false;
			}else if (document.reportForm.reportSubType[i].value == "all"){
				    document.reportForm.action_businessUnit.checked = false;
				    document.reportForm.action_media.checked = false;	
				    document.reportForm.action_status.checked  = false;	
				    document.reportForm.action_contentType.checked = false;
				    document.reportForm.action_ownerpin.checked = false;
				    document.reportForm.action_uploadedBy.checked = false;
			   	    document.reportForm.action_errorReport.checked = false;
				    document.reportForm.action_logDate.checked = false;
				    document.reportForm.action_filename.checked = false;
				    document.reportForm.action_marketplaceName.checked = false;
				    alert ('The default condition will be enabled, set the log Date for Blank report');
			}
	      }
	}
}

//SCRIPT:  For right click menu for download in favorite/search reuslt, JJ BROWSE page.
// Modified on 1/10/2005 by dave for new menu script to work with NS.
var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

////No need to edit beyond here

var ie4=document.all
var ns6=document.getElementById&&!document.all
var ns4=document.layers

var mymenu=0;
//function showmenu(e,which, s){
function showmenu(e){

	//which = populateMenu(s);


	if (!document.all&&!document.getElementById&&!document.layers)
	return

	clearhidemenu()

	menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
	menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

	if (ie4||ns6)
		menuobj.innerHTML=linkset[0]
	else{
		menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+linkset[0]+'</layer>')
		menuobj.document.close()
	}
	
	menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
	menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
	eventX=ie4? event.clientX : ns6? e.clientX : e.x
	eventY=ie4? event.clientY : ns6? e.clientY : e.y
	


	//Find out how close the mouse is to the corner of the window
	
	var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
	var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
	
	var scLeft = 0;
	var scTop = 0;

	//for ie6
	var theTop = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		theLeft = document.documentElement.scrollLeft;
	else if (document.body)
		theLeft = document.body.scrollLeft;

	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<menuobj.contentwidth)
		//move the horizontal position of the menu to the left by it's width
		//menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
		scLeft=ie4? theLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
	else
		//position the horizontal position of the menu where the mouse was clicked
		//menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
		scLeft=ie4? theLeft+eventX : ns6? window.pageXOffset+eventX : eventX
		
	menuobj.thestyle.left=scLeft+'px';
	
	//for ie6
	if (document.documentElement && document.documentElement.scrollTop)
		theTop = document.documentElement.scrollTop;
	else if (document.body)
		theTop = document.body.scrollTop;

		
	//same concept with the vertical position
	if (bottomedge<menuobj.contentheight)
		//menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
		scTop = ie4? theTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
	else
		//menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
		scTop=ie4? theTop + event.clientY : ns6? window.pageYOffset+eventY : eventY
	
	menuobj.thestyle.top=scTop+'px';
	menuobj.thestyle.visibility="visible"

	
	return false
	//}
}

function contains_ns6(a, b) {
	//Determines if 1 element in contained in another- by Brainjar.com
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function hidemenu(){
	mymenu=0;
	if (window.menuobj)
		menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}

function dynamichide(e){
	if (ie4&&!menuobj.contains(e.toElement))
		hidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		hidemenu()
}

function delayhidemenu(){
	document.oncontextmenu=dummy
	//document.onclick=dummy1
	if (ie4||ns6||ns4)
		delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
	if (window.delayhide)
		clearTimeout(delayhide)
}

function highlightmenu(e,state){
	if (document.all)
		source_el=event.srcElement
	else if (document.getElementById)
		source_el=e.target
	if (source_el.className=="menuitems"){
		source_el.id=(state=="on")? "mouseoverstyle" : ""
	}else{
		while(source_el.id!="popmenu"){
			source_el=document.getElementById? source_el.parentNode : source_el.parentElement
			if (source_el.className=="menuitems"){
				source_el.id=(state=="on")? "mouseoverstyle" : ""
			}
		}
	}
}

if (ie4||ns6)
	document.onclick=hidemenu


function redrawMenu(e,a,s) {
	var tempTokens = s.split(",");
	
	s=populateMenu(s,tempTokens[5],tempTokens[6]);
	if (ie4||ns6||ns4){
//		document.oncontextmenu=dummy
//		document.onclick=dummy1
		document.oncontextmenu=showmenu
		//document.onclick=delayhidemenu

	}
}

function dummy() {
	return false;
}
function dummy1() {
	return true;
}


// till here by Dave

//  End -->
//SCRIPT :
//This will close any open window in about 10 seconds delay.
//Just call timer() function within HTML.
function closeWin(){
        window.close()
}
function timer(){
        timerID = setTimeout("closeWin()", 10000)
}


//SCRIPT :
//This is used for fileupload.

function submitFileUploadForm() {
	var valid = "0123456789abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ-._"
	var chk = "val";
	var temp;
	fld = document.fileupload.FILE1.value ;
	if (fld != ""){
		var l = fld.lastIndexOf("\\");
		if (l > 0){  fileName = fld.substring(l + 1)};
		for (var i=0; i<fileName.length; i++) {
			temp = "" + fileName.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") {chk = "invalid"};
		}
	}else{
	   chk = "invalid";
	}
	if (chk == "invalid") {
	       alert("The File Name " + fld + " is invalid and cannot be accepted by the system ");
	}else{
		document.fileupload.submit();
	}	
}

//SCRIPT:  TO update metadata of an element.

function submitUpdateMetadata(dbname,mode,elemid, id)
{
	document.displayResultForm.command.value = 'Metadata-Display-System';
	document.displayResultForm.dbname.value = dbname; 
	document.displayResultForm.mode.value = mode; 
	document.displayResultForm.dmrId.value = elemid; 
	document.displayResultForm.recno.value = id;
	document.displayResultForm.submit(); 
}

//Script:  For the toggle of images in metadata view/update.
var imgloc ="";
function makenav(str,w,h) {
	this.off=new Image (w,h);
	this.off.src=imgloc+str+".gif";
	this.on=new Image (w,h);
	this.on.src=imgloc+str+"-on.gif";
}


function toggleMainMenu(n,on,loc){
	imgloc = loc;
	navIMG=new Array(4);
	navIMG[0]=new makenav ("dmrSystem",90,23);
	navIMG[1]=new makenav ("dmrUpdate",90,23);
	navIMG[2]=new makenav ("dmrMarketPlaceName",90,23);
	navIMG[3]=new makenav ("dmrSecurity",90,23);


	if (on==1) {
		document.images["nav"+n].src=navIMG[n].on.src;
	} else {
		document.images["nav"+n].src=navIMG[n].off.src;
	}
}

//SCRIPT:
//To submit metadata view form.
function submitElementMetadataForm(command)
{
	document.metaDataResultForm.command.value = command;
	document.metaDataResultForm.submit(); 
}


//SCRIPT:
//To submit metadata view form.
function submitElementMetadataUpdateForm(command)
{
	if (command == 'Metadata-Update-Category'){
		PrepareCategories_SelectedTexts(document.forms[1]);
	}
	document.metaDataUpdateForm.command.value = command;
	document.metaDataUpdateForm.submit(); 
}


function toggleSubMenu(i,on,loc){
	imgloc = loc;
	navSubIMG=new Array(3);
	navSubIMG[0]=new subMakenav ("dmrGeneral",90,23);
	navSubIMG[1]=new subMakenav ("dmrUserField",90,23);
	navSubIMG[2]=new subMakenav ("dmrCategory",90,23);
	if (on==1) {
		document.images["navSub"+ i].src=navSubIMG[i].imgOn.src;
	} else {
		document.images["navSub"+ i].src=navSubIMG[i].imgOff.src;
	}

}


function subMakenav(str,wi,ht) {
	this.imgOff=new Image (wi,ht);
	this.imgOff.src=imgloc+str+".gif";
	this.imgOn=new Image (wi,ht);
	this.imgOn.src=imgloc+str+"-on.gif";
}

//This is used in preference to lock/unlock userfileds.
function unlockUser()
{
	document.preferenceUserForm.dmrUserName.disabled = false;
	document.preferenceUserForm.dmrUserName.disable = false;
	document.preferenceUserForm.user_name.disabled = false;
	document.preferenceUserForm.user_name.disable = false;
}

function lockUser()
{
	document.preferenceUserForm.dmrUserName.disable = true;
	document.preferenceUserForm.dmrUserName.disabled = true;
	document.preferenceUserForm.user_name.disabled = true;
	document.preferenceUserForm.user_name.disable = true;
}

//This script will be called from albumTemplate for returning to previous
//location when finished viewing the album.
function returnLink() {
	if (window.opener==null){
		javascript:history.back();
	}else{
		javascript:self.close();
	}	
}

//Script to reload the album maintenace form for buadmins
function reloadAlbumMaintenace(act) { 
	var errorText;
	for (var i=0; i< document.albumManageForm.albumnameIndicator.length; i++) {
		if (document.albumManageForm.albumnameIndicator[i].checked){
			if (document.albumManageForm.albumnameIndicator[i].value ==  "userid"){
				if (document.albumManageForm.albumOwner.value == null || document.albumManageForm.albumOwner.value  == ""){
					errorText = "invalid";
				}
			}
		}
	}
	if (errorText){
		alert("Please enter a valid Dmr user-id and reclick the radio button to submit");
	}else{
        document.albumManageForm.command.value= act;
	    document.albumManageForm.submit();
    }
}

//Added by subbarao as part of the add album new functionality.
function reloadAlbumAdd(act) { 

	var errorText;
	
	if ( document.albumAddForm.albumOwner.value==null || document.albumAddForm.albumOwner.value==''){
		alert("Please enter a valid Dmr user-id and reclick the  button to submit");
		
		return false;
	}else{
		
        document.albumAddForm.command.value= act;
        document.albumAddForm.albumnameAddIndicator.value="OwnerID_Search";
	    document.albumAddForm.submit();
    }
}


