// JavaScript Document
// the IFRAME is IFRAME_PREFIX + XX. The constant below defines
// the value of the prefix
var IFRAME_PREFIX = "i";

// Load the contents of the document into an element
function loadOuter(doc, target) {
   // The name of the IFrame into which the external document is loaded	
   var targetiframe = IFRAME_PREFIX + target;
   document.getElementById(targetiframe).src = doc
   // workaround for missing onLoad event in IFRAME for NN6
   if (!document.getElementById(targetiframe).onload) {
      setTimeout("transferHTML(" + targetiframe + ")", 1000)
   }
}

// Transfer the HTML within the BODY tag from an IFRAME to the specified target.
// The convention followed is that content from an IFRAME called iXX is loaded
// into an element XX.
function transferHTML(target) {
   // The name of the IFRAME into which the external document is loaded
   var srcIFrame = document.getElementById(IFRAME_PREFIX + target);
   // The content in the IFrame contained within the body tag
   var srcContent = (srcIFrame.contentDocument) ? srcIFrame.contentDocument.getElementsByTagName("BODY")[0].  innerHTML : (srcIFrame.contentWindow) ? srcIFrame.contentWindow.document.body.innerHTML : "";
   // Set the content of the target document
   document.getElementById(target).innerHTML = srcContent;
}

// Returns false if the field is empty, null, or has the string "null", and pops up
// the message passed to the function
function isNotNullOrEmptyString(fieldName, message) {
	if (isNullOrEmpty(document.getElementById(fieldName).value)) {	
		alert(message);		
		return false;
	}
	return true;
}

// Returns false if Is parent category check box is not checked
// and no Parent category selected.
// the message passed to the function
function isParentCategory(fieldName1,fieldName2,message) {
	if(document.getElementById(fieldName1).checked == false && isNullOrEmpty(document.getElementById(fieldName2).value)){	
		alert(message);		
		return false;
	}
	return true;
}

// general purpose function to see if an input value has been
// entered at all or if the input value has a value "null"
function isNullOrEmpty(inputStr) {
	if (isEmpty(inputStr) || inputStr == "null") {
		return true;
	}
	return false;
}

// general purpose function to see if an input value has been
// entered at all
function isEmpty(inputStr) {
	if (inputStr == null || inputStr == "") {
		return true;
	}
	return false;
}

// All usernames should have a minimum of 6 characters
var MIN_USERNAME_LENGTH = 6;

// Passwords entered should have a minimum of 8 characters and maximum of 16
var MIN_PASSWORD_LENGTH = 6;
var MAX_PASSWORD_LENGTH = 30;

// function to validate username, the username should have more than 6 characters
function validateUsername(){
	 var userName = document.getElementById("username").value;
	 // Verify that the username doesn't contain any space.
	  if (userName.indexOf(" ",0) > -1){
	     alert("The username should not have any spaces");	
		 return false;
	  }
	  if(userName.length < MIN_USERNAME_LENGTH){
	     alert("The username should have minimum of " + MIN_USERNAME_LENGTH + " characters");	
		 return false;
	  }
	  return true;
}

// function to validate password, the password should have between 8 to 16 characters
function validatePasswordLength(){
	 var passWord = document.getElementById("password").value;
	 // Verify that the password length is between 8 and 16 characters
	  if(passWord.length < MIN_PASSWORD_LENGTH || passWord.length > MAX_PASSWORD_LENGTH){
	     alert("The password should have between " + MIN_PASSWORD_LENGTH + " and " + MAX_PASSWORD_LENGTH + " characters");	
		 return false;
	  }
	  return true;
}

// check whether password and confirm password fields match
function checkPasswordFields(field1, field2, msg) {
	if (document.getElementById(field1).value != document.getElementById(field2).value) {
		document.getElementById(field1).value = "";
		document.getElementById(field2).value = "";
		alert(msg);
		return false;
	}		
	return true;
}


// Validates the email entered.
function validateEmail(fieldValue){
   // The invalid characters that should not be used in an email address
   var invalidChars = " /:,;"; 
   var emailAddress = fieldValue;
   
   var atPosition = emailAddress.indexOf("@",1);
   var periodPosition = emailAddress.indexOf(".",atPosition);
   
   // Checks for the invalid characters listed above.
   for (var i=0; i<invalidChars.length; i++){
      badChar = invalidChars.charAt(i);
	  if (emailAddress.indexOf(badChar,0) > -1){
	     return false;		 
	  }
   }

   if (atPosition == -1){ // Checks for the @
      return false;
   }
   if (emailAddress.indexOf("@",atPosition + 1) > -1){ // Makes sure there is one @
      return false;
   }
   if (periodPosition == -1){ // Makes sure there is a period after the @ 
      return false;
   }
   // Makes sure there is at least 2 characters after the period
   if ((periodPosition + 3) > emailAddress.length){ 
      return false;
   }
   
   return true;
}

// function used to check email and display message
function isValidEmail(fieldname, msg) {
	if (!validateEmail(document.getElementById(fieldname).value)) {
		alert(msg);
		return false;
	}
	return true;
}


// Function that checks whether the field is empty and if not validate the email
function isValidEmailWhenNotRequired(fieldname, msg) {
	// Check if the email has been entered
	if	(document.getElementById(fieldname).value == ""){
		// alert("No email defined");
		return true;
	} else {
		 // alert("The email is " + document.getElementById(fieldname).value);
	    // Validate the entered email	
		 return isValidEmail(fieldname, msg);	
	  }

}

//function to enable a textfield when a checkbox is checked , 'agerangefrom', 'agerangeto'', textfield
function enableTextFieldFromCheckbox() {
	if(document.getElementById('isabove18years').checked == true) {
		document.getElementById('agerangefrom').disabled = false;
		document.getElementById('agerangeto').disabled = false;
		document.getElementById(textfield).className = "";
		
	} else {
		document.getElementById('agerangefrom').disabled = true;
		document.getElementById('agerangeto').disabled = true;
		document.getElementById(textfield).className = "disabledfield";
		document.getElementById('agerangeto').value = "";
		document.getElementById('agerangefrom').value = "";
	}
}


// function to set the filter option to All when the user selects a state 
// or company from the combo lists. The form is then submitted
function setFilterToAll(){
	if(document.getElementById("filteroption")){
		document.getElementById("filteroption").value = "";
	}
	document.getElementById("submitform").click();
}


// general purpose function is to heck whether the value entered is an interger
function isPositiveInteger(fieldName, msg) {
	if (isPosInteger(fieldName)) {
		return true;
	} else {
		alert(msg);
		document.getElementById(fieldName).value = "";
		return false;
	}
}

// general purpose function to see if a suspected numeric input
// is a positive integer
function isPosInteger(fieldName) {
	inputVal = document.getElementById(fieldName).value;
	inputStr = inputVal.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if (oneChar < "0" || oneChar > "9") {
			return false;
		}
	}
	return true;
}

// Returns false if the field has a value that is not a number and pops up
// the message passed to the function
function isNonNegativeNumber(fieldName, message) {
	if (isNumber(document.getElementById(fieldName).value)) {
		return true;
	}
	alert(message);
	document.getElementById(fieldName).value = "";
	return false;
}

//general purpose function to see if a suspected numeric input
//is a positive or negative number
function isNumber(inputVal){
	oneDecimal =false;
	inputStr =inputVal.toString();
	for (var i =0; i <inputStr.length; i++){
		var oneChar = inputStr.charAt(i);
		if (i == 0 && oneChar == "+"){
			continue;
		}
		if (oneChar == "." && !oneDecimal){
			oneDecimal = true;
			continue;
		}
		if (oneChar < "0" || oneChar > "9"){
			return false;
		}
	}
	return true;
}

// prompts the user whether or not they would like to delete an entity
function deleteVideo(url, entity, name) {
	message = "Are you sure you want to delete " + entity + ": '" + name +"'? \n" +
				"If you have submiited this video as part of any role submissions\n" + 
					" it will not be available for the custom Directors to watch\n" + 
					"Press OK to delete the " + entity +"\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}


// prompts the user whether or not they would like to delete an entity
function deleteEntity(url, entity, name) {
	message = "Are you sure you want to delete " + entity + ": '" + name +"'? \n" + 
					"Press OK to delete the " + entity +"\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete an entity
function deleteMessage(url) {
	message = "Are you sure you want to delete this message? \n" + 
					"Press OK to delete the message\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}


// prompts the user whether or not they would like to report and Ad
function reportAdvert(url, name) {
	message = "Are you sure you want to report this Ad: " + name +" as inappropriate ? \n" + 
					"Press OK to report Ad: " + name +" \n" +  
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete an entity
function reportUserProfile(url, name) {
	message = "Are you sure you want to report " + name +"'s profile as inappropriate ? \n" + 
					"Press OK to report " + name +"'s profile\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete an entity
function reportUserPhoto(url, name) {
	message = "Are you sure you want to report " + name +"'s photo as inappropiate ? \n" + 
					"Press OK to report " + name +"'s photo\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete a video
function voteVideo(url, title) {
	message = "Are you sure you want to vote for the video \'" + title +"\'? \n\n" + 
					"Press OK to vote \n\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete an audio clip
function voteAudioClip(url, title) {
	message = "Are you sure you want to vote for the audio clip \'" + title +"\'? \n\n" + 
					"Press OK to vote \n\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete an audio clip
function reportUserAudioClip(url, name) {
	message = "Are you sure you want to report " + name +"'s audio clip as inappropiate ? \n" + 
					"Press OK to report " + name +"'s audio clip\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}


// prompts the user whether or not they would like to delete an audio clip
function reportUserVideo(url, name) {
	message = "Are you sure you want to report " + name +"'s video as inappropiate ? \n" + 
					"Press OK to report " + name +"'s video\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}
// prompts the user whether or not they would like to save an entity
function saveEntity(url) {
	message = "Are you sure you want to save your changes\n" +
					"Press OK to save your changes\n" +
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}




// prompts the user whether or not to continue the save action
function askSaveChanges(formName) {
	message = "Are you sure you want save the changes? \n" + 
					"Press OK to update the \n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		document.forms[formName].submit();
	}
}



// function to open a pop-up window to view product larger image
function openLargerArtistImage(width, height, URL) {
	//modified function to ensure that large images fit in the window
	if(width>500 || height > 500) {
		width = 500;
		height = 500;
	}
	newwidth = new Number(width);
	newwidth += 100;
	newheight = new Number(height);
	newheight += 100;
	//alert("width: " + newwidth + "height: " + newheight);
aWindow=window.open(URL,"newwindow","toolbar=no,scrollbars=no,status=no,location=no,resizable=no,menubar=no,width="+newwidth+",height="+newheight+",left=200,top=100");
}
// function to set the filter option to All when the user selects a month and year
// from the combo lists. the form is then submitted
function setFilterToAll(){
	if(document.getElementById("filteroption")){
		document.getElementById("filteroption").value = "";
	}
	document.getElementById("submitform").click();
}
// set the form action where data is to be submitted
function updateStatusThenSubmit(statusValue, formName) {
		document.getElementById("status").value = statusValue;
		document.forms[formName].submit();
}

//function to enable a field when a checkbox is checked
function enableFieldFromCheckbox(checkbox, fieldName) {
	if(document.getElementById(checkbox).checked == true) {
		document.getElementById(fieldName).disabled = false;
		document.getElementById(fieldName).className = "";
		
	} else {
		document.getElementById(fieldName).disabled = true;
		document.getElementById(fieldName).className = "disabledfield";
		document.getElementById(fieldName).value = "";
	}
}

//function to enable a field when a checkbox is checked
function disableFieldFromCheckbox(checkbox, fieldName) {
	if(document.getElementById(checkbox).checked == false) {
		document.getElementById(fieldName).disabled = false;
		document.getElementById(fieldName).className = "";
		
	} else {
		document.getElementById(fieldName).disabled = true;
		document.getElementById(fieldName).className = "disabledfield";
		document.getElementById(fieldName).value = "";
	}
}
//function to display the advert subcategories depending on the selected parent category
function showSubCategories(fieldName) {
	var parentcategoryid = document.getElementById(fieldName).options[document.getElementById(fieldName).selectedIndex].value;
	var currentvalue = '';
	frames['isubcategories'].location.href = "subcategories.php?parentcategoryid=" + parentcategoryid + "&currentvalue=" + currentvalue;
}


 //function does the following: 
// 1. set the value of the search field to the default value 'Search' when it is empty  and action is click
// 2. Make the field empty when the value is the default value and action is click

 function setSearchFieldValue(searchfield, defaultvalue, action) {
	//var defaultvalue = "Search";
	if(action=="blur") {
		if(document.getElementById(searchfield).value == "") {
			document.getElementById(searchfield).value = defaultvalue;
		}
	} else if(action=="click") {
		if(document.getElementById(searchfield).value == defaultvalue) {
			document.getElementById(searchfield).value = "";
		}
	}
}

//function to check whether a checkbox is checked
function isChecked(checkbox, message) {
	if(document.getElementById(checkbox).checked == false) {
		alert(message);		
		return false;
	}
	return true;	
}

//function to check the file extension and ensure that the file
//in a particular field is of a valid file type
function isValidFileType(field, message) {
	var filename = document.getElementById(field).value;
	if(!isNullOrEmpty(filename)) {
		var validfiletypes = new Array("jpg", "jep", "gif", "jpeg", "JPG", "GIF", "JEP", "JPEG");
		var extension  = filename.substring(filename.length-3, filename.length)
		for(var i=0; i<validfiletypes.length; i++) {
			if(extension == validfiletypes[i]) { 
				return true;
			}
		}
		alert(message);
		return false;
	}
}

//function used to confirm a delete action
// prompts the user whether or not they would like to delete an entity
function confirmDeletion() {
	message = "Are you sure you want to delete? \n" + 
					"Press OK to delete and Cancel to stay on the current page";
	if (window.confirm(message)) {
		return true;
	}
	return false;
}

//function to ensure that at least one phone number is selected
function hasPhoneNumber(firstphone, secondphone, message) {
	if(isNullOrEmpty(firstphone) && isNullOrEmpty(secondphone)) {
			alert(message);
			return false;
	}
	return true;
}

//////////////////////////////////////////////////////////////////
///image page functions                                ///////////
//////////////////////////////////////////////////////////////////
function show(thisPic, replacedPic, width, height) {
	//imageResize(width, height, 500);
	document.getElementById(replacedPic).src= myPix[thisPic];	
	document.getElementById(replacedPic).width= width;
	document.getElementById(replacedPic).height=height;
	matchPictureWithCaption(thisPic);
}

// set default picture
function setDefaultPicture(thisPic){
	defaultPicture = thisPic;
	show(defaultPicture, "myPicture");
}

// function to match picture with caption
function matchPictureWithCaption(picID){
	captionText = document.getElementById(picID).innerHTML;	
	document.getElementById("pictext").innerHTML= captionText;
}

// function to set submit button status and value of isactive field depending on the value selected
function setStatus(fieldName, value) {
	document.getElementById(fieldName).value = value;
	if(value == "Active") {
		document.getElementById('isactive').value = 'Y'; 
	} else {
		document.getElementById('isactive').value = 'N'; 
	}
}

// function to set submit button status and value of isactive field depending on the value selected
function echoID(fieldName) {
	photoid = document.getElementById(fieldName).value;
	alert(fieldName);
}

function openListWindow(fileName) {
  // To specify the window characteristics edit the "features" variable below:
  // width - width of the window
  // height - height of the window
  // scrollbar - "yes" for scrollbars, "no" for no scrollbars
  // left - number of pixels from left of screen
  // top - number of pixels from top of screen
  features = "width=500,left=50,top=100,height=500,scrollbar=yes";
  listwindow = window.open(fileName,"newWin", features);   
}

function openSmallListWindow(fileName) {
  // To specify the window characteristics edit the "features" variable below:
  // width - width of the window
  // height - height of the window
  // scrollbar - "yes" for scrollbars, "no" for no scrollbars
  // left - number of pixels from left of screen
  // top - number of pixels from top of screen
  features = "width=500,left=50,top=100,height=250,scrollbar=yes";
  listwindow = window.open(fileName,"newWin", features);   
}

function openAnotherListWindow(fileName) {
  // To specify the window characteristics edit the "features" variable below:
  // width - width of the window
  // height - height of the window
  // scrollbar - "yes" for scrollbars, "no" for no scrollbars
  // left - number of pixels from left of screen
  // top - number of pixels from top of screen
  features = "width=700,left=50,top=100,height=700,scrollbar=yes";
  listwindow = window.open(fileName,"newWin", features);   
}
// JavaScript Document
// the IFRAME is IFRAME_PREFIX + XX. The constant below defines
// the value of the prefix
var IFRAME_PREFIX = "i";

// Load the contents of the document into an element
function loadOuter(doc, target) {
   // The name of the IFrame into which the external document is loaded	
   var targetiframe = IFRAME_PREFIX + target;
   document.getElementById(targetiframe).src = doc
   // workaround for missing onLoad event in IFRAME for NN6
   if (!document.getElementById(targetiframe).onload) {
      setTimeout("transferHTML(" + targetiframe + ")", 1000)
   }
}

// Transfer the HTML within the BODY tag from an IFRAME to the specified target.
// The convention followed is that content from an IFRAME called iXX is loaded
// into an element XX.
function transferHTML(target) {
   // The name of the IFRAME into which the external document is loaded
   var srcIFrame = document.getElementById(IFRAME_PREFIX + target);
   // The content in the IFrame contained within the body tag
   var srcContent = (srcIFrame.contentDocument) ? srcIFrame.contentDocument.getElementsByTagName("BODY")[0].  innerHTML : (srcIFrame.contentWindow) ? srcIFrame.contentWindow.document.body.innerHTML : "";
   // Set the content of the target document
   document.getElementById(target).innerHTML = srcContent;
}

// Returns false if the field is empty, null, or has the string "null", and pops up
// the message passed to the function
function isNotNullOrEmptyString(fieldName, message) {
	if (isNullOrEmpty(document.getElementById(fieldName).value)) {	
		alert(message);		
		return false;
	}
	return true;
}

// Returns false if Is parent category check box is not checked
// and no Parent category selected.
// the message passed to the function
function isParentCategory(fieldName1,fieldName2,message) {
	if(document.getElementById(fieldName1).checked == false && isNullOrEmpty(document.getElementById(fieldName2).value)){	
		alert(message);		
		return false;
	}
	return true;
}

// general purpose function to see if an input value has been
// entered at all or if the input value has a value "null"
function isNullOrEmpty(inputStr) {
	if (isEmpty(inputStr) || inputStr == "null") {
		return true;
	}
	return false;
}

// general purpose function to see if an input value has been
// entered at all
function isEmpty(inputStr) {
	if (inputStr == null || inputStr == "") {
		return true;
	}
	return false;
}

// All usernames should have a minimum of 6 characters
var MIN_USERNAME_LENGTH = 6;

// Passwords entered should have a minimum of 8 characters and maximum of 16
var MIN_PASSWORD_LENGTH = 6;
var MAX_PASSWORD_LENGTH = 30;

// function to validate username, the username should have more than 6 characters
function validateUsername(){
	 var userName = document.getElementById("username").value;
	 // Verify that the username doesn't contain any space.
	  if (userName.indexOf(" ",0) > -1){
	     alert("The username should not have any spaces");	
		 return false;
	  }
	  if(userName.length < MIN_USERNAME_LENGTH){
	     alert("The username should have minimum of " + MIN_USERNAME_LENGTH + " characters");	
		 return false;
	  }
	  return true;
}

// function to validate password, the password should have between 8 to 16 characters
function validatePasswordLength(){
	 var passWord = document.getElementById("password").value;
	 // Verify that the password length is between 8 and 16 characters
	  if(passWord.length < MIN_PASSWORD_LENGTH || passWord.length > MAX_PASSWORD_LENGTH){
	     alert("The password should have between " + MIN_PASSWORD_LENGTH + " and " + MAX_PASSWORD_LENGTH + " characters");	
		 return false;
	  }
	  return true;
}

// check whether password and confirm password fields match
function checkPasswordFields(field1, field2, msg) {
	if (document.getElementById(field1).value != document.getElementById(field2).value) {
		document.getElementById(field1).value = "";
		document.getElementById(field2).value = "";
		alert(msg);
		return false;
	}		
	return true;
}


// Validates the email entered.
function validateEmail(fieldValue){
   // The invalid characters that should not be used in an email address
   var invalidChars = " /:,;"; 
   var emailAddress = fieldValue;
   
   var atPosition = emailAddress.indexOf("@",1);
   var periodPosition = emailAddress.indexOf(".",atPosition);
   
   // Checks for the invalid characters listed above.
   for (var i=0; i<invalidChars.length; i++){
      badChar = invalidChars.charAt(i);
	  if (emailAddress.indexOf(badChar,0) > -1){
	     return false;		 
	  }
   }

   if (atPosition == -1){ // Checks for the @
      return false;
   }
   if (emailAddress.indexOf("@",atPosition + 1) > -1){ // Makes sure there is one @
      return false;
   }
   if (periodPosition == -1){ // Makes sure there is a period after the @ 
      return false;
   }
   // Makes sure there is at least 2 characters after the period
   if ((periodPosition + 3) > emailAddress.length){ 
      return false;
   }
   
   return true;
}

// function used to check email and display message
function isValidEmail(fieldname, msg) {
	if (!validateEmail(document.getElementById(fieldname).value)) {
		alert(msg);
		return false;
	}
	return true;
}



//Function that checks whether an entertainer has selected none when submitting for a role
//function isEmptyPhoto(fieldname, msg) {
	// Check whether the option "No Photo" has been selected
	//if	(document.getElementById(fieldname).value == ""){ 
//}

// Prompts an entertainer whether or not they would like to use the "No Photo" option
function isEmptyPhoto() {
	if	(document.getElementById('photoid').checked == true){ 	
		message = "Are you sure want to submit for this role without a photo?";
		if (window.confirm(message)) {
			return true;
		}
	return false;	
	}
}

// Prompts an entertainer whether or not they would like to use the "No Photo" option
function isEmptyMedia(fieldname, fieldtype) {
	//Check if the photo is empty
	if	(document.getElementById(fieldname).checked == true){ 	
		message = "Are you sure want to submit for this role without a "+ fieldtype +"?";
		if (window.confirm(message)) {
			return true;
		}
	return false;	
	}
}
// Prompts an entertainer whether or not they would like to use the "No Photo" option
function isEmptyVideo() {
	if	(document.getElementById('videoid').checked == true){ 	
		message = "Are you sure want to submit for this role without a video?";
		if (window.confirm(message)) {
			return true;
		}
	return false;	
	}
}


// Function that checks whether the field is empty and if not validate the email
function isValidEmailWhenNotRequired(fieldname, msg) {
	// Check if the email has been entered
	if	(document.getElementById(fieldname).value == ""){
		// alert("No email defined");
		return true;
	} else {
		 // alert("The email is " + document.getElementById(fieldname).value);
	    // Validate the entered email	
		 return isValidEmail(fieldname, msg);	
	  }

}

//function to enable a textfield when a checkbox is checked , 'agerangefrom', 'agerangeto'', textfield
function enableTextFieldFromCheckbox() {
	if(document.getElementById('isabove18years').checked == true) {
		document.getElementById('agerangefrom').disabled = false;
		document.getElementById('agerangeto').disabled = false;
		document.getElementById(textfield).className = "";
		
	} else {
		document.getElementById('agerangefrom').disabled = true;
		document.getElementById('agerangeto').disabled = true;
		document.getElementById(textfield).className = "disabledfield";
		document.getElementById('agerangeto').value = "";
		document.getElementById('agerangefrom').value = "";
	}
}


// function to set the filter option to All when the user selects a state 
// or company from the combo lists. The form is then submitted
function setFilterToAll(){
	if(document.getElementById("filteroption")){
		document.getElementById("filteroption").value = "";
	}
	document.getElementById("submitform").click();
}


// general purpose function is to heck whether the value entered is an interger
function isPositiveInteger(fieldName, msg) {
	if (isPosInteger(fieldName)) {
		return true;
	} else {
		alert(msg);
		document.getElementById(fieldName).value = "";
		return false;
	}
}

// general purpose function to see if a suspected numeric input
// is a positive integer
function isPosInteger(fieldName) {
	inputVal = document.getElementById(fieldName).value;
	inputStr = inputVal.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if (oneChar < "0" || oneChar > "9") {
			return false;
		}
	}
	return true;
}

// Returns false if the field has a value that is not a number and pops up
// the message passed to the function
function isNonNegativeNumber(fieldName, message) {
	if (isNumber(document.getElementById(fieldName).value)) {
		return true;
	}
	alert(message);
	document.getElementById(fieldName).value = "";
	return false;
}

//general purpose function to see if a suspected numeric input
//is a positive or negative number
function isNumber(inputVal){
	oneDecimal =false;
	inputStr =inputVal.toString();
	for (var i =0; i <inputStr.length; i++){
		var oneChar = inputStr.charAt(i);
		if (i == 0 && oneChar == "+"){
			continue;
		}
		if (oneChar == "." && !oneDecimal){
			oneDecimal = true;
			continue;
		}
		if (oneChar < "0" || oneChar > "9"){
			return false;
		}
	}
	return true;
}

// prompts the user whether or not they would like to delete an entity
function removeEntity(url, entity, name) {
	message = "Are you sure you want to remove " + entity + ":  from '" + name +"'? \n" + 
					"Press OK to remove the " + entity +"\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}


// prompts the user whether or not they would like to report and Ad
function reportAdvert(url, name) {
	message = "Are you sure you want to report this Ad: " + name +" as inappropriate ? \n" + 
					"Press OK to report Ad: " + name +" \n" +  
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete an entity
function reportUserProfile(url, name) {
	message = "Are you sure you want to report " + name +"'s profile as inappropriate ? \n" + 
					"Press OK to report " + name +"'s profile\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to delete an entity
function reportUserPhoto(url, name) {
	message = "Are you sure you want to report " + name +"'s photo as inappropiate ? \n" + 
					"Press OK to report " + name +"'s photo\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user whether or not they would like to save an entity
function saveEntity(url) {
	message = "Are you sure you want to save your changes\n" +
					"Press OK to save your changes\n" +
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}

// prompts the user that the values wont be saved if his/she presses Cancel
function cancelEntity(url) {
	message = "Are you sure you want to cancel your changes\n" +
				"Any infomation that you may have entered shall be lost\n" +	
					"Press OK to cancel your changes and return to the previous page\n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		window.location.href=url;
	}
}



// prompts the user whether or not to continue the save action
function askSaveChanges(formName) {
	message = "Are you sure you want save the changes? \n" + 
					"Press OK to update the \n" + 
					"Cancel to stay on the current page";
	if (window.confirm(message)) {
		document.forms[formName].submit();
	}
}



// function to open a pop-up window to view product larger image
function openLargerArtistImage(width, height, URL) {
	//modified function to ensure that large images fit in the window
	if(width>500 || height > 500) {
		width = 500;
		height = 500;
	}
	newwidth = new Number(width);
	newwidth += 100;
	newheight = new Number(height);
	newheight += 100;
	//alert("width: " + newwidth + "height: " + newheight);
aWindow=window.open(URL,"newwindow","toolbar=no,scrollbars=no,status=no,location=no,resizable=no,menubar=no,width="+newwidth+",height="+newheight+",left=200,top=100");
}
// function to set the filter option to All when the user selects a month and year
// from the combo lists. the form is then submitted
function setFilterToAll(){
	if(document.getElementById("filteroption")){
		document.getElementById("filteroption").value = "";
	}
	document.getElementById("submitform").click();
}
// set the form action where data is to be submitted
function updateStatusThenSubmit(statusValue, formName) {
		document.getElementById("status").value = statusValue;
		document.forms[formName].submit();
}

//function to enable a field when a checkbox is checked
function enableFieldFromCheckbox(checkbox, fieldName) {
	if(document.getElementById(checkbox).checked == true) {
		document.getElementById(fieldName).disabled = false;
		document.getElementById(fieldName).className = "";
		
	} else {
		document.getElementById(fieldName).disabled = true;
		document.getElementById(fieldName).className = "disabledfield";
		document.getElementById(fieldName).value = "";
	}
}

//function to enable a field when a checkbox is checked
function disableFieldFromCheckbox(checkbox, fieldName) {
	if(document.getElementById(checkbox).checked == false) {
		document.getElementById(fieldName).disabled = false;
		document.getElementById(fieldName).className = "";
		
	} else {
		document.getElementById(fieldName).disabled = true;
		document.getElementById(fieldName).className = "disabledfield";
		document.getElementById(fieldName).value = "";
	}
}
//function to display the advert subcategories depending on the selected parent category
function showSubCategories(fieldName) {
	var parentcategoryid = document.getElementById(fieldName).options[document.getElementById(fieldName).selectedIndex].value;
	var currentvalue = '';
	frames['isubcategories'].location.href = "subcategories.php?parentcategoryid=" + parentcategoryid + "&currentvalue=" + currentvalue;
}


 //function does the following: 
// 1. set the value of the search field to the default value 'Search' when it is empty  and action is click
// 2. Make the field empty when the value is the default value and action is click

 function setSearchFieldValue(searchfield, defaultvalue, action) {
	//var defaultvalue = "Search";
	if(action=="blur") {
		if(document.getElementById(searchfield).value == "") {
			document.getElementById(searchfield).value = defaultvalue;
		}
	} else if(action=="click") {
		if(document.getElementById(searchfield).value == defaultvalue) {
			document.getElementById(searchfield).value = "";
		}
	}
}

//function to check whether a checkbox is checked
function isChecked(checkbox, message) {
	if(document.getElementById(checkbox).checked == false) {
		alert(message);		
		return false;
	}
	return true;	
}

//function to check the file extension and ensure that the file
//in a particular field is of a valid file type
function isValidFileType(field, message) {
	var filename = document.getElementById(field).value;
	if(!isNullOrEmpty(filename)) {
		var validfiletypes = new Array("jpg", "jep", "gif", "jpeg", "JPG", "GIF", "JEP", "JPEG");
		var extension  = filename.substring(filename.length-3, filename.length)
		for(var i=0; i<validfiletypes.length; i++) {
			if(extension == validfiletypes[i]) { 
				return true;
			}
		}
		alert(message);
		return false;
	}
}

//function to check the file extension and ensure that the file
//in a particular field is of a valid file type
function isValidAudioFileType(field, message) {
	var filename = document.getElementById(field).value;
	if(!isNullOrEmpty(filename)) {
		var validfiletypes = new Array("mp3", "MP3");
		var extension  = filename.substring(filename.length-3, filename.length)
		for(var i=0; i<validfiletypes.length; i++) {
			if(extension == validfiletypes[i]) { 
				return true;
			}
		}
		alert(message);
		return false;
	}
}
//function used to confirm a delete action
// prompts the user whether or not they would like to delete an entity
function confirmDeletion() {
	message = "Are you sure you want to delete? \n" + 
					"Press OK to delete and Cancel to stay on the current page";
	if (window.confirm(message)) {
		return true;
	}
	return false;
}

//function to ensure that at least one phone number is selected
function hasPhoneNumber(firstphone, secondphone, message) {
	if(isNullOrEmpty(firstphone) && isNullOrEmpty(secondphone)) {
			alert(message);
			return false;
	}
	return true;
}


// function to set submit button status and value of isactive field depending on the value selected
function setStatus(fieldName, value) {
	document.getElementById(fieldName).value = value;
	if(value == "Active") {
		document.getElementById('isactive').value = 'Y'; 
	} else {
		document.getElementById('isactive').value = 'N'; 
	}
}

// function to set submit button status and value of isactive field depending on the value selected
function echoID(fieldName) {
	photoid = document.getElementById(fieldName).value;
	alert(fieldName);
}


// function to check number of characters in notes field
function checkNumberofCharacters(notesfieldName, counterFieldName) {
	var maxcharacters = 750;
	updateMessageCounter();
	var notes = document.getElementById(notesfieldName).value;
	var notesLength = notes.length;
	if (notesLength > maxcharacters) {
		alert('You can only enter a maximum of ' + maxcharacters +' characters');
		// show only up to limit of charatcters
		var maxString = notes.substring(0,maxcharacters);
		document.getElementById(notesfieldName).value = maxString;
		// reset counter
		document.getElementById(counterFieldName).innerHTML = maxcharacters;
		return false;
	}
	return true;	
}
function updateMessageCounter() {
	var notes = document.getElementById("notes").value;
	var notesLength = notes.length;
	document.getElementById("counterdiv").innerHTML = notesLength;
}

// function to check number of characters in notes field
function checkNumberofCharactersForNotes(notesfieldName, counterFieldName) {
	updateMessageCounter();
	var maxcharacters = 2000;
	var notes = document.getElementById(notesfieldName).value;
	var notesLength = notes.length;
	if (notesLength > maxcharacters) {
		alert('You can only enter a maximum of ' + maxcharacters +' characters');
		// show only up to limit of charatcters
		var maxString = notes.substring(0,maxcharacters);
		document.getElementById(notesfieldName).value = maxString;
		// reset counter
		document.getElementById(counterFieldName).innerHTML = maxcharacters;
		return false;
	}
	return true;	
}

// Function to add the contents of a div to a form
// see Travel Details form for an example
function updateFormFromHiddenDivElements(fieldName) {
	HIDDEN_DIV_ELEMENT_PREFIX = "h_";
	HIDDEN_DIV_CHECKBOX_PREFIX = "c_";
	HIDDEN_DIV_DROPDOWN_PREFIX = "d_";
	// get all the elements in the form
	var children = document.getElementById(fieldName).getElementsByTagName('*');
	for (i=0; i < children.length; i++) {
		// get the current elemnt from the array of children
		var elem = children[i];
		// update the main form controls
		// first check that the main form control exists 

		if (document.getElementById(getEnd(elem.id, HIDDEN_DIV_ELEMENT_PREFIX)) != null) {
			document.getElementById(getEnd(elem.id, HIDDEN_DIV_ELEMENT_PREFIX)).value = elem.value;
		} else if (document.getElementById(getEnd(elem.id, HIDDEN_DIV_CHECKBOX_PREFIX)) != null) {
			// do this if the element is a checkbox
			// check if the child element has a value, if it has a value then set
			// the corresponding check box to the same value and set it to be checked
				if(!isNullOrEmpty(elem.value)) {
					// select the check box
					document.getElementById(getEnd(elem.id, HIDDEN_DIV_CHECKBOX_PREFIX)).checked = true;
				}
		} else if (document.getElementById(getEnd(elem.id, HIDDEN_DIV_DROPDOWN_PREFIX)) != null) {
			// do this if the element is a drop-down field
			// Set the value of the selected index to the value of the hidden element
				//alert(elem.id + ":" + elem.value);
				document.getElementById(getEnd(elem.id, HIDDEN_DIV_DROPDOWN_PREFIX)).options[document.getElementById(getEnd(elem.id, HIDDEN_DIV_DROPDOWN_PREFIX)).selectedIndex].value = elem.value;
		}

	}	
}

// extract back end of string after searchString
function getEnd(mainStr,searchStr) {
	foundOffset = mainStr.indexOf(searchStr)
	if (foundOffset == -1) {
		return null
	}
	return mainStr.substring(foundOffset+searchStr.length,mainStr.length)
}

//function to set the value of a date field to an empty string when its value is today.
//This is to be used for the date fields that should have the default value as an empty string and not today e.g., Leave Date
function setDateToEmptyString(dateFieldName, dateValue) { 
//declare a new date
	var today= new Date();
	//obtain the year month and date from the date provided
	var year = dateValue.substring(0, 4);
	var month = dateValue.substring(5, 6);
	var day = dateValue.substring(7, 8);
	//alert(today.getDate());
	//Compare the two dates and in case the date is the same as today make the value of the field an empty string.
	if(year==today.getFullYear() && month==(today.getMonth() + 1) && day==today.getDate()) {
		//alert("The Year:" + year + " The Month:" + month + " Day:" + day);		
		document.getElementById(dateFieldName).value = "";
	}
	
}

// count the number of roles on a breakdown
function countRolesForBreakdown() {
	if (document.getElementById('rolecount').value == "0") {
		// there are no roles
		alert("Please add at least one role for the breakdown");
		return false;
	}
	return true;
}

// function to ensure that at least one checkbox has been selected
function checkSelection(msg) {
   count = 0;
   for (var i=0; i < document.forms[0].elements.length; i++) {
      if (document.forms[0].elements[i].checked) {
	     count++;
	  }
   }
   if (count == 0) {
      alert(msg);
	  return false;
   }
   return true;
}

//function to check whether at least one checkbox is selected from a list of checkboxes with the same name
function isAnyCheckboxSelected(checkboxarray,message, limit) {
	var i = 0;
	while(i < limit) {
		if(document.all(checkboxarray, i).checked == true) {			
			return true;	
		}	
		i++;
	}
	alert(message);
	return false;
}

//function to compare the values of two fields and ensure that one of them is greater than the other
function compareFieldValues(smallValueField, largeValueField, message) {
	//compare the two field if they have values
	if(!isNullOrEmpty(document.getElementById(smallValueField).options[document.getElementById(smallValueField).selectedIndex].value) && !isNullOrEmpty(document.getElementById(largeValueField).options[document.getElementById(largeValueField).selectedIndex].value)) {
		//set the values to numbers
		smallValue = new Number(document.getElementById(smallValueField).options[document.getElementById(smallValueField).selectedIndex].value);
		largeValue = new Number(document.getElementById(largeValueField).options[document.getElementById(largeValueField).selectedIndex].value);
		//compare the two values and return an error message if the largeValue is smaller than the smallValue
		if(smallValue > largeValue) {
			alert(message);
			return false
		}
		return true;
	}
	return true;
}

//function to validate two date fields and ensures that the date in the firstfield is before the date in the second field
function validateDateFields(firstField, secondField, message){
	var firstdatearray = new Array();
	var seconddatearray = new Array();
	
	//var firstdatestring = document.getElementById(firstField).value;
	
	if(firstField != 'birthdate'){
		// this date already has a / separator for the month, day and year
		firstdatestring = document.getElementById(firstField).value;
	} else {
		// birth date is got from 3 fields, birthdate_m, birthdate_d, birthdate_y so we 
		// concatenate them and separate them with a / which we shall strip off later
		firstdatestring  = document.getElementById("birthdate_m").value + "/" + document.getElementById("birthdate_d").value + "/" + document.getElementById("birthdate_y").value;
	}
	
	var seconddatestring = document.getElementById(secondField).value;
	
	if(firstdatestring != "" && seconddatestring != ""){
		// if the date strings are the same then return true
		//alert('the first date string is '+firstField+' with value '+firstdatestring+' and the second date string is '+secondField +' with value '+seconddatestring);
		//extract the values from the date strings and place them in arrays
		firstdatearray = firstdatestring.split("/");
		seconddatearray = seconddatestring.split("/");
		
		//declare new dates using the values in the arrays
		// For some reason, subtract 1 from the month, I think it has to do with
		// months being calculated from 0 (for Jan) instead of 1 or something like that
		var firstdate = new Date(firstdatearray[2], firstdatearray[0] - 1, firstdatearray[1]);
		var seconddate = new Date(seconddatearray[2], seconddatearray[0] - 1, seconddatearray[1]);
	
		//subtract the time between the two dates
		var difference = seconddate.getTime() - firstdate.getTime();
		//if the time difference is negative, empty the fields, alert a message and return false
		if(difference < 0 ){
			alert(message);
			//document.getElementById(secondField).value = "";
			return false;
			
		}
	}
	return true;
}

//function to validate two date fields and ensures that the date in the firstfield is before the date in the second field
function validateDateFutureDate(dateField, message){
	var datearray = new Array();
	
	// this date already has a / separator for the month, day and year
	datestring = document.getElementById(dateField).value;
	
	//extract the values from the date strings and place them in arrays
	datearray = datestring.split("/");
	
	//declare new dates using the values in the arrays
	// For some reason, subtract 1 from the month, I think it has to do with
	// months being calculated from 0 (for Jan) instead of 1 or something like that
	fielddate = new Date(datearray[2], datearray[0] - 1, datearray[1]);
	now = new Date;
	if(!(datearray[2] == now.getFullYear() && datearray[0] - 1 == now.getMonth() && datearray[1] == now.getDate())) {
		//subtract the time between the field date and the current date
		var difference = fielddate.getTime() - now.getTime();
		//if the time difference is negative, empty the fields, alert a message and return false
		if(difference < 0 ){
			alert(message);
			return false;
			
		}
	}
	return true;
}

//function to display a value depending on the value of a checkbox 
function displayValue(checkboxvalue, displaydiv, truevalue, falsevalue) {
	if(checkboxvalue != "") {
		// display the true value
		document.getElementById(displaydiv).innerHTML = truevalue;
	} else {
		//display the false value
		document.getElementById(displaydiv).innerHTML = falsevalue;	
	}
}

//A function to ensure that the value of a textfield is positive number if
// a checkbox is checked
function isNotEmptyOrCheckboxIsChecked(checkbox, textfield, message) {
	if(!(document.getElementById(checkbox).checked == true || !(isNullOrEmpty(document.getElementById(textfield).value)))) {
		alert(message);
		return false;
	} else {
		return true;
	}	
}

// Refreshes the page and insertsthe id passed into the page
function showVideo(fieldName) {
	frames['ivideo'].location.href = XOOPS_URL + "/modules/video/video/video.php?id=" + fieldName;
	//frames['ivideo'].location.href = "video.php?revverid=" + fieldName;

}

// JavaScript Document
// This function is used to display tabs
function showTabIfVisible(mname, shown) {
	if (document.getElementById(mname+'_layer').style.visibility == (shown ? 'inherit' : 'hidden')) return;
		document.getElementById(mname+'lt').className = shown ? 'bgontabbottom' : 'bgofftabbottom';
		document.getElementById(mname+'lnk').className = shown ? 'bgontabbottommid' : 'bgofftabbottommid';
		document.getElementById(mname+'txt').className = shown ? 'smalltextnolink' : 'smallgraytextnolink';
		document.getElementById(mname+'rt').className = shown ? 'bgontabbottom' : 'bgofftabbottom';
		document.getElementById(mname+'_layer').style.zIndex = shown ? 0 : -1;
		document.getElementById(mname+'_layer').style.visibility = shown ? 'inherit' : 'hidden';
		document.getElementById(mname+'lti').src=document.getElementById(mname+'lti').src.replace(shown ? /_plain/ : /_stroked/,shown ? '_stroked' : '_plain');
		document.getElementById(mname+'rti').src=document.getElementById(mname+'rti').src.replace(shown ? /_plain/ : /_stroked/,shown ? '_stroked' : '_plain');
}

function showTab(lname) {
	
   showTabIfVisible('tab1', lname == 'tab1');
   showTabIfVisible('tab2', lname == 'tab2');
   showTabIfVisible('tab3', lname == 'tab3');
   showTabIfVisible('tab4', lname == 'tab4');

}

//function to displays the owner, viewer and photo id of the photo that has been clicked on 
function showPhotoViews(ownerName, photoid) {
	var browser = document.getElementById('browser').value;
	frames['logphotoviews'].location.href = "logphotoviews.php?owner=" + ownerName + "&photoid=" + photoid + "&browser=" + browser;
}

// function to validate the data entered on a specific tab
function validateTab(newTab) {
	/* var currentLayer = document.getElementById("currentlayer").value;
	if (currentLayer == "tab1_layer") {
		// change the name of the current layer only if validation was sucessful
		if (validateGeneralInformation()) {
			document.getElementById("currentlayer").value = newTab + "_layer";
			return true;
		}
	} else if (currentLayer == "tab2_layer") {
		if (validateFatherInformation()) {
			document.getElementById("currentlayer").value = newTab + "_layer";
			return true;
		}
	} else if (currentLayer == "tab3_layer") {
		if (validateMotherInformation()) {
			document.getElementById("currentlayer").value = newTab + "_layer";
			return true;
		}		
	}*/
	return true;
	
}
// Thid function retuurns the total amount
function getMakingTheMovieContestTotals(contest){
	var amount = 0;
	
	if(contest==''){
		if(document.submitaudioclip.audioclipid){//check if this radio group exits
			for( i = 0; i < document.submitaudioclip.audioclipid.length; i++ ){		
				if(document.submitaudioclip.audioclipid[i].checked ==true && document.submitaudioclip.audioclipid[i].value!= ""){
					amount = document.getElementById('audioprice').value;				
				}
			}
			
		}
	}
	
	if(document.submitaudioclip.videoid){//check if this radio group exits
		for( i = 0; i < document.submitaudioclip.videoid.length; i++ ){		
			if(document.submitaudioclip.videoid[i].checked ==true && document.submitaudioclip.videoid[i].value!= ""){
				amount = eval(parseInt(amount) + parseInt(document.getElementById('videoprice').value));
				
			}
		}
	}
	
	if(parseInt(amount)==0){
		document.getElementById('totalprice').value = "";
	}else{		
		document.getElementById('totalprice').value = amount;
	}
	document.getElementById('amountdiv').innerHTML = amount;
	
	return true;
}