﻿
var ctrlPrefix = 'ctl00_ContentPlaceHolder1_';
//var Max_SubTasks = 3;

function trim(astring)
{
    //var trimmed = str.replace(/^\s+|\s+$/g, '') ;
    return astring.replace(/^\s+|\s+$/g, '');
}


///// maintain scroll position ///
function SetDivPosition(){
var intY = document.getElementById(ctrlPrefix+"divGridView").scrollTop;
var date = new Date();
date.setTime(date.getTime()+(1*60*60*1000));
var expires = "; expires="+date.toGMTString();
document.cookie = "cookie1"+"="+intY+expires+"; path=/";
document.title = intY;
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

/*
 Set Cookie Javascript Function
You need to put the name and values in quotes when you call the function, like this:
Set_Cookie( 'mycookie', 'visited 9 times', 30, '/', '', '' );. 
Don't forget to put in empty quotes for the unused parameters or you'll get an error when you run the code. 
This makes the cookie named 'mycookie', with the value of 'visited 9 times', and with a life of 30 days, and the cookie is set to your root folder.
The Set_Cookie values for 'domain' and 'secure' are not utilized. Use 'domain' on the Javascript cookie if you are using it on a subdomain, like widgets.yoursite.com, where the cookie is set on the widgets subdomain, but you need it to be accessible over the whole yoursite.com domain.
It's good practice to not assume the path to the site root will be set the way you want it by default, so do this manually as a rule, '/'. If no value is set for expires, it will only last as long as the current session of the visitor, and will be automatically deleted when they close their browser. 
*/
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


//Get Cookie Javascript Function
// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			//alert(cookie_value);
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
				
				
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function checkCreateUserForm(cbTermsID,ctrlIDName, ctrlIDpw, ctrlIDpwconfirm, ctrlIDemail)
{
 var d = document;
 var cb = d.getElementById(cbTermsID );
 var name = d.getElementById(ctrlIDName).value;
 var pw = d.getElementById(ctrlIDpw).value;
 var pwconfirm = d.getElementById(ctrlIDpwconfirm).value;
 var email = d.getElementById(ctrlIDemail).value;
// var vals = "";
// vals = cb.checked;
// vals += "\nName: " + name;
// vals += "\nPW: " + pw;
// vals += "\nPWconfirm: " + pwconfirm;
// vals += "\ne-mail: " + email;
// alert(vals );
 var errs = "";
 var errCount = 0;
 // check T&Cs checkbox
 if(!cb.checked)
    {
     errCount += 1;
     errs  += "\t" + errCount + ". You must agree to the Terms & Conditions\n";
    }
 // check name length
 if (name.length == 0)
    {
     errCount += 1;
     errs += "\t" + errCount + ". You didn't enter a User Name\n";
    }
 // only allow letters & numbers
 var result = checkName(name);
 if(!result == "")
    {
     errCount++;
     errs += "\t" + errCount + " " + result + " allowed in User Name\n";
    }
 
 // check password is between 6-12 chars, uppercase, lowercase, and numeral
 var pwerr = checkPassword(pw,6,12);
 if(!pwerr == "")
    {
     errCount += 1;
     errs += "\t" + errCount + ". " + pwerr;
    }
 // check passwords match - if we don't have a password error!
// if(!pwerr == "")
//    {
     if (pw != pwconfirm)
        {
         errCount += 1;
         errs += "\t" + errCount + ". Confirmation Password is different.\n";
        }
//    }
 //check e-mail
 var mailerr = checkEmail(email);
 if(!mailerr == "")
    {
     errCount += 1;
     errs += "\t" + errCount + ". " + mailerr;
    }
   
 if(!errs == "")
    {
     var msg = "Please correct the following " + errCount + " Errors:\n\n" + errs;
     alert(msg);
     return false;
    }
 
 return true;
}
///////////////////////////

// check 2 strings match
function isDifferent(strng1,strng2)
{
  var error = ""; 
  if (strng1 != strng2)  //"Can\'t touch this!") 
      {
         error = "The strings are different.\n";
      }
return error;
}

function checkName(strng)
{
  var illegalChars = /[\W_]/; // allow only letters and numbers
 if (illegalChars.test(strng))
    {
     return "Only letters and numbers";
    } 
}

// check password - between iMinChars-iMaxChars, uppercase, lowercase, and numeral
// for checkCreateUserForm()
function checkPassword(strng,iMinChars,iMaxChars)
{
 var error = "";
 var errCount=0;
 var teststring = strng;
 // check for string of empty characters
 if(!teststring.length == 0)
    {
    var newstr = trim(teststring);
    if(newstr.length  == 0)
        {
            return "The Password consists of " + teststring.length + " empty characters\n";
        }
    }
 // check for empty string
 if (strng == "") 
    {
        return "You didn't enter a password.\n";
    }

 // check for length    
 if ((strng.length < parseInt(iMinChars)) || (strng.length > parseInt(iMaxChars))) 
    {
       errCount++;
       error += "\t" + errCount + " The password is the wrong length. (" + iMinChars + "-" + iMaxChars + ")\n";
    }
 // check for illegal characters
// var illegalChars = /[\W_]/; // allow only letters and numbers
// if (illegalChars.test(strng))  
//    {
//        errCount++;
//        error += "\t" + errCount + "The password contains illegal characters.(only letters and numbers)\n";
//    } 
 var er=""       
 var illegalChars = "  ','  '<'  '>'  'space' "; 
 if ( strng.match(/[,<> ]/) )  
    {
        errCount++;
        er += "\t\t" + errCount + " The password contains illegal characters.(" + illegalChars + ") are not allowed)\n";
    } 

 // check for an uppercase character
 if (!strng.match(/[A-Z]/)) 
    {
      errCount++;
      er += "\t\t" + errCount + " The password must contain at least one uppercase letter.\n";
    } 
 // check for an lowercase character
 if (!strng.match(/[a-z]/)) 
    {
      errCount++;
      er += "\t\t" + errCount + " The password must contain at least one lowercase letter.\n";
    }
 // check for a number 0-9
 if (!strng.match(/[0-9]/)) 
    {
      errCount++;
      er += "\t\t" + errCount + " The password must contain at least one number[0-9].\n";
    } 
 
 if (!er == "")
    {
     error += "There are " + errCount + " First Password Errors:\n" + er;
    }
 return error;    
}    

// check password - between iMinChars-iMaxChars, uppercase, lowercase, and numeral
// for manageusers.aspx change password buttton click
//function checkPasswordOnly(ctrlTextboxID,ctrlErrorID,iMinChars,iMaxChars)
function checkPasswordOnly(ctrlTextboxID,iMinChars,iMaxChars)
{
 var d = document;
 var pwCtrlText = d.getElementById (ctrlTextboxID )
 //var errCtrl = d.getElementById(ctrlErrorID )
 var strng = pwCtrlText.value
 var error = "";
 var errCount=0;
 var teststring = strng;
 // clear any previous errors
 //errCtrl .innerHTML="";
 // check for string of empty characters
 if(!teststring.length == 0)
    {
    var newstr = trim(teststring);
    if(newstr.length  == 0)
        {
            //errCtrl.innerHTML = "The Password consists of " + teststring.length + " empty characters<br />";
            alert('The Password consists of ' + teststring.length + ' empty characters');
            return false;
            //return "The Password consists of " + teststring.length + " empty characters<br />";
        }
    }
 // check for empty string
 if (strng == "") 
    {
        //errCtrl.innerHTML = "You didn't enter a password.<br />";
        alert('You didn\'t enter a password');
        return false;
        //return "You didn't enter a password.<br />";
    }

 // check for length    
 if ((strng.length < parseInt(iMinChars)) || (strng.length > parseInt(iMaxChars))) 
    {
       errCount++;
       error += errCount + " The password is the wrong length. (" + iMinChars + "-" + iMaxChars + ")\n";
//alert ('wrong length ' + strng.length+'\nerrCount:'+errCount+'\nerror:'+error);       
    }
 // check for illegal characters
// var illegalChars = /[\W_]/; // allow only letters and numbers
// if (illegalChars.test(strng))  
//    {
//        errCount++;
//        error += "\t" + errCount + "The password contains illegal characters.(only letters and numbers)<br />";
//    } 
 var er=""       
 var illegalChars = "  ','  '<'  '>'  'space' "; 
 if ( strng.match(/[,<> ]/) )  
    {
        errCount++;
        er += errCount + " The password contains illegal characters.(" + illegalChars + ") are not allowed)\n";
    } 

 // check for an uppercase character
 if (!strng.match(/[A-Z]/)) 
    {
      errCount++;
      er += errCount + " The password must contain at least one uppercase letter.\n";
    } 
 // check for an lowercase character
 if (!strng.match(/[a-z]/)) 
    {
      errCount++;
      er += errCount + " The password must contain at least one lowercase letter.\n";
    }
 // check for a number 0-9
 if (!strng.match(/[0-9]/)) 
    {
      errCount++;
      er += errCount + " The password must contain at least one number[0-9].\n";
    } 
 
 if (!er == "")
    {
     //error += "There are " + errCount + " First Password Errors:\n" + er;
     error +=  er;
    }
 
 var retval;
 if(!error == "")
    {
     //errCtrl.innerHTML = error;
     alert(error);
     retval = false;
    }
 else 
    {
     //errCtrl.innerHTML ="password OK " + iMinChars + "-" + iMaxChars;
     retval = true;
    }
 
 return retval; //true;    //error
    
}    




// e-mail check
function checkEmail(strng)
{
 var error = "";
 if (strng == "")
     {
       error = "You didn't enter an email address.\n";
     }
  var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng)))
     { 
       error = "Please enter a valid email address.\n";
     }
  else
     {
        //test email for illegal characters
      var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
      if (strng.match(illegalChars))
          {
             error = "The email address contains illegal characters.\n";
          }
     }
 return error;    
}


function checkEmailOnly(strng)
{
 var error = "";
 if (strng == "")
     {
       error = "You didn't enter an email address.\n";
       //return "You didn't enter an email address.\n";
     }
if (trim(strng) == "")
     {
       error = "Only blank characters in the email address.\n";
       //return "You didn't enter an email address.\n";
     }
     
  var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng)))
     { 
       error = "Please enter a valid email address.\n";
     }
  else
     {
        //test email for illegal characters
      var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
      if (strng.match(illegalChars))
          {
             error = "The email address contains illegal characters.\n";
          }
     }
 if(!error == "")
    {
     //errCtrl.innerHTML = error;
     alert(error);
     retval = false;
    }
 else 
    {
     //errCtrl.innerHTML ="password OK " + iMinChars + "-" + iMaxChars;
     retval = true;
    }    
     
 return retval;    
}



// ====================================================================
// 
// ====================================================================
//function checkUpload(rb_UploadTo, filename)
function checkUpload()
{
 var d = document;
 var uploadFileName = d.getElementById(ctrlPrefix + 'tb_FileName').value;
 var artist = d.getElementById(ctrlPrefix + 'tb_Artist').value;
 var song = d.getElementById(ctrlPrefix + 'tb_SongTitle').value;

 //tb_DocDescription
 var description = d.getElementById(ctrlPrefix + 'tb_DocDescription').value;
 
 var taskDDL = d.getElementById (ctrlPrefix + 'DDL_Task');
 var taskID = taskDDL.options[taskDDL.selectedIndex].value;
 var taskName = taskDDL.options[taskDDL.selectedIndex].text;
 var subTaskDDL = d.getElementById (ctrlPrefix + 'DDL_SubTask');
 var subTaskID = subTaskDDL.options[subTaskDDL.selectedIndex].value;
 var subTaskName = subTaskDDL.options[subTaskDDL.selectedIndex].text;
 var levelDDL = d.getElementById (ctrlPrefix + 'DDL_Level');
 var levelID = levelDDL.options[levelDDL.selectedIndex].value;
 var levelName = levelDDL.options[levelDDL.selectedIndex].text;
 var themeDDL = d.getElementById (ctrlPrefix + 'DDL_Theme');
 var themeID = themeDDL.options[themeDDL.selectedIndex].value;
 var themeName = themeDDL.options[themeDDL.selectedIndex].text;

 var SubThemeDDL = d.getElementById(ctrlPrefix + 'DDL_SubTheme');
 var subThemeID = themeDDL.options[SubThemeDDL.selectedIndex].value;
 var subThemeName = themeDDL.options[SubThemeDDL.selectedIndex].text;
 
 /* required values */
 arrErrors = [];
 if (trim(uploadFileName).length < 1)
    {
    arrErrors.push('No Upload File Name');
    }
 if (trim(artist).length < 1)
    {
    arrErrors.push('Artist is Required');
    }
 if (trim(song).length < 1)
    {
    arrErrors.push('Song Title is Required');
    }

 if (trim(description).length < 1) 
    {
    arrErrors.push('Description is Required');
    }
 
 if (parseInt(taskID) < 1)
    {
    arrErrors.push('Task is Required');
    }
 if (parseInt(subTaskID) < 1)
    {
    arrErrors.push('SubTask is Required');
    }
 if (parseInt(levelID) < 1)
    {
    arrErrors.push('Level is Required');
    }
 if (parseInt(themeID) < 1)
    {
    arrErrors.push('Theme is Required');
    }
    if (parseInt(subThemeID) < 1) 
    {
    arrErrors.push('Sub Theme is Required');
    }

  //=== If We Have Errors, show error message  ===
 if (arrErrors.length > 0)
    {
    var ErrMsg = '';
    for (var i=0, len=arrErrors.length; i<len; ++i )
        {
        ErrMsg += (i+1) + ':\t' + arrErrors[i] + '\n';
        }
        alert('Please correct these ' + arrErrors.length + ' Error(s):\n\n' + ErrMsg);
    //d.getElementById(ctrlPrefix +'btn_OK').disabled = true;
    return false;
    }
    
 var msg = "OK to update database with the following Values?";
 msg += "\nDoc Name:\t" + uploadFileName;
 msg += "\nArtist:\t\t" + artist;
 msg += "\nSong:\t\t" + song;
 msg += "\nTask:\tID: " + taskID + "\t\tName:\t" + taskName;
 msg += "\nSub Task\tID: " + subTaskID + "\t\tName:\t" + subTaskName;
 msg += "\nLevel\tID: " + levelID + "\t\tName:\t" + levelName;
 if(themeID == -1)
    {
    themeID = "None";
    themeName = "None";
    }
 msg += "\nTheme\tID: " + themeID + "\t\tName:\t" + themeName;
 
 return confirm(msg);
}

/*
function checkUploadPage()
{
 
 var d = document;
 
 var uploadFileName = d.getElementById(ctrlPrefix + 'tb_FileName').value;
 
    // get ref to Artist/Song Textboxes
 var ArtistName = d.getElementById(ctrlPrefix + 'tb_Artist').value;
 var SongTitle = d.getElementById(ctrlPrefix + 'tb_SongTitle').value;
    // get ref to asp.net DDLs
 var ctrlTaskDDL = d.getElementById(ctrlPrefix + 'DDL_Task');
 var ctrlSubTaskDDL = d.getElementById(ctrlPrefix + 'DDL_SubTask');
 var ctrlLevelDDL = d.getElementById(ctrlPrefix + 'DDL_Level');
 var ctrlThemeDDL = d.getElementById(ctrlPrefix + 'DDL_Theme');
    // get IDs from DDLs
    // ????????????? are these needed ????????????????????????
 var taskID = ctrlTaskDDL.options[ctrlTaskDDL.selectedIndex].value;
 var subtaskID = ctrlSubTaskDDL.options[ctrlSubTaskDDL.selectedIndex].value;
 var levelID = ctrlLevelDDL.options[ctrlLevelDDL.selectedIndex].value;
 var themeID = ctrlThemeDDL.options[ctrlThemeDDL.selectedIndex].value;

 // get values for all possible selections
 var AssignedTask_1 = document.getElementById(ctrlPrefix + 'lbl_TasksAssigned_1').innerHTML;    // .value;
 var AssignedTask_2 = document.getElementById(ctrlPrefix + 'lbl_TasksAssigned_2').innerHTML;
 var AssignedTask_3 = document.getElementById(ctrlPrefix + 'lbl_TasksAssigned_3').innerHTML;
  
 var SubTasksAssignedToTask_1 = document.getElementById(ctrlPrefix + 'lbl_SubTasksAssigned_1').innerHTML;
 var SubTasksAssignedToTask_2 = document.getElementById(ctrlPrefix + 'lbl_SubTasksAssigned_2').innerHTML;
 var SubTasksAssignedToTask_3 = document.getElementById(ctrlPrefix + 'lbl_SubTasksAssigned_3').innerHTML;
  
 var AssignedLevel_1 = document.getElementById(ctrlPrefix + 'lbl_LevelsAssigned_1').innerHTML;
 var AssignedLevel_2 = document.getElementById(ctrlPrefix + 'lbl_LevelsAssigned_2').innerHTML;
 var AssignedLevel_3 = document.getElementById(ctrlPrefix + 'lbl_LevelsAssigned_3').innerHTML;
 
 var ThemesAssignedToTask_1 = document.getElementById(ctrlPrefix + 'lbl_ThemesAssigned_1').innerHTML;    //lbl_ThemesAssigned_1
 var ThemesAssignedToTask_2 = document.getElementById(ctrlPrefix + 'lbl_ThemesAssigned_2').innerHTML;
 var ThemesAssignedToTask_3 = document.getElementById(ctrlPrefix + 'lbl_ThemesAssigned_3').innerHTML;

 //=== REQUIRED VALUES ===//
 //-- for tbl_Artists --//
 // # Artist Name
 // ???? Song Title - delete this field ????????
 //-- for tbl_SongTitles
 // # SongName
 //-- for tbl_DocInfo --//
 // Theme - ID_Theme_1..3
 // Task - ID_Task_1..3
 // Level - ID_Level_1..3
 // ID_Artist
 // ID_SongTite
 //=== OPTIONAL VALUES ==//
 // Sub Task -
 
 // parse assigned Tasks for tbl_DocInfo - formatted as ID;fieldname (e.g. 5,ID_Task_1)
 // place in array
 arrTasks = [];
 arrTasks[0] = AssignedTask_1;
 arrTasks[1] = AssignedTask_2;
 arrTasks[2] = AssignedTask_3;
 
 arrSubTasks = [];      // needs further parsing to get up to MaxSubTasks from each array index
 arrSubTasks[0] = SubTasksAssignedToTask_1;
 arrSubTasks[1] = SubTasksAssignedToTask_2;
 arrSubTasks[2] = SubTasksAssignedToTask_3;
 
 arrLevels = [];
 arrLevels[0] = AssignedLevel_1;
 arrLevels[1] = AssignedLevel_2;
 arrLevels[2] = AssignedLevel_3;
 
 arrThemes = [];
 arrThemes[0] = ThemesAssignedToTask_1;
 arrThemes[1] = ThemesAssignedToTask_2;
 arrThemes[2] = ThemesAssignedToTask_3;
 
 //=== Check Required Values ===
 //var OK = true;
 arrErrors = [];
 
 if (trim(ArtistName).length < 1)
    {
    arrErrors.push('Artist is required');
    //OK = false;
    }
 if (trim(SongTitle).length < 1)
    {
    arrErrors.push('Song Title is required');
    //OK = false;
    }
 
 if (arrTasks[0].length < 1)
    {
    arrErrors.push('No Task Assigned To Task 1');
    //OK = false;    
    }

 
 if (arrLevels[0].length < 1)
    {
    arrErrors.push('No Level Assigned');
    //OK = false;    
    }

 
 //=== If We Have Errors, show error message  ===
 if (arrErrors.length > 0)
    {
    var ErrMsg = '';
    for (var i=0, len=arrErrors.length; i<len; ++i )
        {
        ErrMsg += arrErrors[i] + '\n';
        }
    alert('ERRORS:\n' + ErrMsg);
    d.getElementById(ctrlPrefix +'btn_OK').disabled = true;
    return;
    }

    //=== get arrays of subtasks for each task
    var arrTmpSubtask_1 = arrSubTasks[0].split('*');
    var arrTmpSubtask_2 = arrSubTasks[1].split('*');
    var arrTmpSubtask_3 = arrSubTasks[2].split('*');

   // var msg = 'Uploaded File: ' + uploadFileName;
    var msg = 'Uploaded file:\n' + uploadFileName + '\n\tADD THE SELECTIONS BELOW TO THE DATABASE?\n';
    msg += '\nartist: ' + ArtistName + '\nsong: ' + SongTitle;

    msg += '\n\ntask 1:\t' + arrTasks[0];
    //alert('Lengths:\n' + 'arrTmpSubtask_3[0].length:'+ arrTmpSubtask_3[0].length + '\n' + arrTmpSubtask_2.length + '\n' + arrTmpSubtask_3.length);
    if (arrTmpSubtask_1[0].length > 0)
    {
    msg += '\n\t\tsubtasks:';
    msg += '\n\t\t\t\t' + arrTmpSubtask_1[0]; 
    msg += '\t\t\t\t' + arrTmpSubtask_1[1];
    msg += '\t\t\t\t' + arrTmpSubtask_1[2];
    }

    msg += '\ntask 2:\t' + arrTasks[1];
    if (arrTmpSubtask_2[0].length > 0)
    {
    msg += '\n\t\tsubtasks:';
    msg += '\n\t\t\t\t' + arrTmpSubtask_2[0]; 
    msg += '\t\t\t\t' + arrTmpSubtask_2[1];
    msg += '\t\t\t\t' + arrTmpSubtask_2[2];
    }

    msg += '\ntask 3:\t' + arrTasks[2];
    if (arrTmpSubtask_3[0].length > 0)
    {
    msg += '\n\t\tsubtasks:';
    msg += '\n\t\t\t\t' + arrTmpSubtask_3[0]; 
    msg += '\t\t\t\t' + arrTmpSubtask_3[1];
    msg += '\t\t\t\t' + arrTmpSubtask_3[2];
    }
       
    // levels
    msg += '\n\nlevel 1:\t' + arrLevels[0];
    msg += '\nlevel 2:\t' + arrLevels[1];
    msg += '\nlevel 3:\t' + arrLevels[2];
    // themes
    msg += '\n\ntheme 1:\t' + arrThemes[0];
    msg += '\ntheme 2:\t' + arrThemes[1];
    msg += '\ntheme 3:\t' + arrThemes[2];
    
    msg += '\n\n';



 //d.getElementById(ctrlPrefix +'btn_OK').disabled = !confirm(msg);
 
 return confirm(msg);   //returns true for OK - false for cancel
 
}
*/

//////////////////////////////////
/*

========================================================
========= simulates a static variable (counter) =========
========================================================
function optionChanged()
{
if ( typeof optionChanged.counter == 'undefined' ) {
        // It has not... perform the initilization
        optionChanged.counter = 0;
    }

    // Do something stupid to indicate the value
    alert(++optionChanged.counter);
}
========================================================
*/

/*
function showHTMLdiv(adivID, state)
{
    document.getElementById(adivID).style.display = ((state == true) ? "block":"none");
}
*/

/*
function checkDDLhasSelection(DDLclientID)
{
 if (document.getElementById(DDLclientID).selectedIndex < 1)
    {
    var DDLname = DDLclientID.substring(DDLclientID.lastIndexOf('_')+1);
    alert('Please select a "' + DDLname + '" to assign First');
    return false;
    }
 else
    {
    return true;
    }
}
*/

/*
function clearASPText(ctrlID)
{
    document.getElementById(ctrlID).innerHTML ='';
}
function resetASPDDL(ctrlID)
{
    document.getElementById(ctrlID).selectedIndex=0;
}
function clearText(htmlTextBoxName)
{
    document.getElementById(htmlTextBoxName).value='';
}
*/

/*
// ====================================================================
// gets database values from relevant controls & places them in asp:labels
// ====================================================================
function setDBvalues()
{
    var d = document;
    // get references to target labels
    var ThemesTarget = d.getElementById(ctrlPrefix + 'lbl_Themes');
    var TasksTarget = d.getElementById(ctrlPrefix + 'lbl_Tasks');
    var SubTasksTarget = d.getElementById(ctrlPrefix + 'lbl_SubTasks');
    var LevelsTarget = d.getElementById(ctrlPrefix + 'lbl_Levels');
    
    // get references to selection controls
    var DDLselectedTask = d.getElementById(ctrlPrefix + 'DDL_Theme');
    var DDLselectedTask = d.getElementById(ctrlPrefix + 'DDL_Task');
    var DDLselectedTask = d.getElementById(ctrlPrefix + 'DDL_SubTask');
    var DDLselectedTask = d.getElementById(ctrlPrefix + 'DDL_Level');
    
    // get the Theme/Task/SubTask/Level assigned 1..n from the HTML text boxes
    // formatted ID ; description
    // Themes
    var arr = d.getElementById('txt_Theme_1').value.split(';');
    var idAssignedTheme_1 = arr[0];
    arr = d.getElementById('txt_Theme_2').value.split(';');
    var idAssignedTheme_2 = arr[0];
    arr = d.getElementById('txt_Theme_3').value.split(';');
    var idAssignedTheme_3 = arr[0];
    // put the ids into the asp:label in a ; separated list
    d.getElementById(ctrlPrefix + 'lbl_InfoThemes').value = idAssignedTheme_1 + ';' + idAssignedTheme_2 + ';' + idAssignedTheme_3;
    // Tasks
    var arr = d.getElementById('txt_Task_1').value.split(';');
    var idAssignedTask_1 = arr[0];
    arr = d.getElementById('txt_Task_2').value.split(';');
    var idAssignedTask_2 = arr[0];
    arr = d.getElementById('txt_Task_3').value.split(';');
    var idAssignedTask_3 = arr[0];
    // put the ids into the asp:label in a ; separated list
    d.getElementById(ctrlPrefix + 'lbl_InfoTasks').value = idAssignedTask_1 + ';' + idAssignedTask_2 + ';' + idAssignedTask_3;
    // SubTasks
    var arr = d.getElementById('txt_SubTask_1').value.split(';');
    var idAssignedSubTask_1 = arr[0];
    arr = d.getElementById('txt_SubTask_2').value.split(';');
    var idAssignedSubTask_2 = arr[0];
    arr = d.getElementById('txt_SubTask_3').value.split(';');
    var idAssignedSubTask_3 = arr[0];
    // put the ids into the asp:label in a ; separated list
    d.getElementById(ctrlPrefix + 'lbl_InfoSubTasks').value = idAssignedSubTask_1 + ';' + idAssignedSubTask_2 + ';' + idAssignedSubTask_3;

    // Levels
    var arr = d.getElementById('txt_Level_1').value.split(';');
    var idAssignedLevel_1 = arr[0];
    arr = d.getElementById('txt_Level_2').value.split(';');
    var idAssignedLevel_2 = arr[0];
    arr = d.getElementById('txt_Level_3').value.split(';');
    var idAssignedLevel_3 = arr[0];
    // put the ids into the asp:label in a ; separated list
    d.getElementById(ctrlPrefix + 'lbl_InfoLevels').value = idAssignedLevel_1 + ';' + idAssignedLevel_2 + ';' + idAssignedLevel_3;
    
    
    //alert('idAssignedTheme_1: ' + idAssignedTheme_1 + '\nidAssignedTheme_2: ' + idAssignedTheme_2 + '\nidAssignedTheme_3: ' + idAssignedTheme_3);
    
    // 
    alert('DBvalues Set!');
}



// ====================================================================
// sets target textbox values when (Select A Number) options change 
// ====================================================================
function optionChanged(selectObj, targetTextPrefix, associatedDropDowList)
{

 var d=document;
 // get the index of the selected option 
 var idx = selectObj.selectedIndex; 
 // get the value of the selected option (e.g. ID_Theme_1)
 var val = selectObj.options[idx].text; //value; // both same!!
 // if idx=0 or val=-1 then 1st option is selected (to ??#)
 // build target text name
 var txtTarget = d.getElementById(targetTextPrefix + idx);
 // get the theme/task/subtask/level ID from the associatedDDL (value?) 
 var ctrlID = d.getElementById(ctrlPrefix + associatedDropDowList);
 var ID = ctrlID.options[ctrlID.selectedIndex].value;
 var theName = ctrlID.options[ctrlID.selectedIndex].text;
 // if the ID = -1 (index(0)description is selected), show message and return
 if(ID == -1)
   {
   //DDL_
   // get type from associated DDL name passed as parameter
   var typeName = associatedDropDowList.substring(4)
   alert('please select a ' + typeName + ' first');
   selectObj.selectedIndex = 0;
   return;
   }
// 
 // if the target text is not null, set it to the selected values string - ID;ID_Theme_1
 if (null != txtTarget)
   {
   txtTarget.value = ID + ';' + theName; //val;
   }
 else
   {
   // ???
   }
 //alert('idx: ' + idx + '\nval: ' + val + '\nname: ' + theName + '\ntxtTarget: ' + txtTarget.id);
}
*/

