//-------------------------------------------------------------------------------------------
// save.js - checks whether the user's saved their contribution
// Part of the Community Sites software package
// Developed by Ian Grant and Jack Latimer
// Copyright Community Sites 2004, 2005
// For further information, see www.communitysites.co.uk or email info@communitysites.co.uk
//-------------------------------------------------------------------------------------------

// flag for saved data
var isSaved = true;

// determines whether we're in a situation where data might be lost
var checkRequired = false;

// the timeout used to display the PageMaker auto-save facility
var pmAutoSaveWarning_timeout = null;
var pmAutoSaveWarning_duration = 0;
var pmAutoSave_timeout = null;
var pmAutoSave_duration = 0;
var pmAutoSave_blocked = false;

// flag whether Javascript is enabled within the browser by setting a value in a hidden input field
function checkJavascript() {
    if (document.getElementById("txtIsJavascript")) {
        document.getElementById("txtIsJavascript").value = "1";
    }    
}

// set alert messages for all links on the page...
function setSaveAlert(all) {
	if (typeof all == "undefined") {
    	all = false;
  	}
  	
	checkRequired = true;

	var i, a;
  	for (i=0; (a = document.getElementsByTagName('a')[i]); i++) {
		// note: checks for gallery preview links, as these are already disabled by their onclick event
		//if ((a.href != "") && ((all) || ((a.href.indexOf("contribute.aspx")==-1) || (a.href.substr(a.href.length-1, 1) != "#")) && (a.href.indexOf(".aspx#") == -1) && (a.href.indexOf("page.aspx?id=&") == -1) && (a.href.indexOf("page_id=_") == -1) && (a.href.indexOf("page_id__") == -1))) {
		if ((a.href != "") && (a.onclick==null)) {
			if ((a.href.indexOf("contribute.aspx")==-1) && (a.href.indexOf("albumedit.aspx")==-1) && (a.href.indexOf("categoryedit.aspx")==-1)) {
				a.onclick = checkQuit;
			}
		}
  	}

	// sort out any image maps
	var area;
  	for (i=0; (area = document.getElementsByTagName('area')[i]); i++) {
		if ((area.href != "") && (area.onclick==null)) {
			area.onclick = checkQuit;
		}
  	}
}

// cancels a return key press on a text box
function cancelReturn(event) {
	if ((! event) && (window.event)) {
		event = window.event;
	}

  	if ((event.which == 13) || (event.keyCode == 13)){
	   	event.returnValue=false;
	   	event.cancel = true;
		return false;
	} else {
		return true;
	}
}

// cancels a return key press on a text box and moves onto the next form element
function cancelReturnAndMoveNext(event) {
	if ((! event) && (window.event)) {
		event = window.event;
	}
	
	if ((event.which == 13) || (event.keyCode == 13)){
	   	event.returnValue=false;
	   	event.cancel = true;
		
		try {
			var bNext = false;
			for (var i=0; i<document.forms[0].length; i++) {
				// if this is the next object on the form, then set the focus to it
				if ((bNext) && (document.forms[0].elements[i].type != "hidden")) {
					document.forms[0].elements[i].focus();
					bNext = false;
					break;
				}

			   	// if this object is the one that sent the event, then record the fact that we want to focus on the next object...
				if (event.target) {
					if (document.forms[0].elements[i].name==event.target.name) {
				   		bNext = true;
					}
				} else if (event.srcElement) {
					if (document.forms[0].elements[i].name==event.srcElement.name) {
				   		bNext = true;
					}
				}
			}
			return false;

		} catch (error) {
			return false;
		}
	} else {
		return true;
	}
}

// disables the return key on text inputs, to prevent it from submitting wrongly
function disableTextSubmit() {
	var i;
	for (i=0; (input = document.getElementsByTagName('input')[i]); i++) {
		// if this is a text box and it's not the search box...
		if ((input.type == "text") && (input.name.indexOf("txtSearchInstant")==-1)) {
			input.onkeypress = cancelReturnAndMoveNext;
		}
	}
}

// requests an auto-save after a specified length of time
function setAutoSave() {
	if (! pmAutoSave_blocked) {
    	// only do this if there's content that hasn't been saved and the duration is longer than a minute
	    if ((pmAutoSaveWarning_duration >= 60000) && ((! isSaved) || (document.getElementById("txtIsSaved").value != "1"))) {
		    // set the timeout
		    pmAutoSaveWarning_timeout = setTimeout("doAutoSaveWarning();", pmAutoSaveWarning_duration);
	    }
	}
}

// ask the user if they want to save their work
function doAutoSaveWarning() {
	if (! pmAutoSave_blocked) {
    	if ((! isSaved) || (document.getElementById("txtIsSaved").value != "1")) {
	    	// show the auto-save prompt, which includes options to confirm and cancel the save operation
		    if (document.getElementById("htmlAutoSave")) {
			    // show the prompt
    			document.getElementById("htmlAutoSave").style.display = "block";
	    		// if we want to do an autosave if the user doesn't respond, set that up now
		    	if (pmAutoSave_duration >= 1000)  {
			    	// set the timeout
				    pmAutoSave_timeout = setTimeout("doAutoSave();", pmAutoSave_duration);
    			}
	    	}
	    }

	    // clear the timeout
	    if (pmAutoSaveWarning_timeout != null) {
	        clearTimeout(pmAutoSaveWarning_timeout);
    	}
    }
}

// save the user's work
function doAutoSave() {
	if (! pmAutoSave_blocked) {
        if ((! isSaved) || (document.getElementById("txtIsSaved").value != "1")) {
	    	// show the auto-save prompt, which includes options to confirm and cancel the save operation
		    if (document.getElementById("btnAutoSaveYesForce")) {
    			//location.href=document.getElementById("btnAutoSaveYes").href;
	    		document.getElementById("btnAutoSaveYesForce").click();
		    } else if (document.getElementById("btnautosaveyesforce")) {
    			document.getElementById("btnautosaveyesforce").click();
	    	}
	    }

	    // clear the timeout
	    if (pmAutoSave_timeout != null) {
	        clearTimeout(pmAutoSave_timeout);
    	}
    }
}

function cancelAutoSave() {
	// clear the timeout
	if (pmAutoSaveWarning_timeout != null) {
	    clearTimeout(pmAutoSaveWarning_timeout);
	}
	// clear the timeout
	if (pmAutoSave_timeout != null) {
	    clearTimeout(pmAutoSave_timeout);
	}
}

// ask the user whether they want to carry on...
function checkQuit() {
	var quit = true;
	// if we're about to lose work...
	if (checkRequired) {
		// and there's unsaved work that might be lost...
		if ((! isSaved) || (document.getElementById("txtIsSaved").value != "1")) {
		    quit = confirm(lang_confirmsave);
		}
	}

	return quit;
}

// find out whether the work's been saved
// - not being used currently, as we're using the confirm method above instead
function checkSaved() {
	/*
	// if we're about to lose work...
	if (checkRequired) {
		// and there's unsaved work that might be lost...
		if ((! isSaved) || (document.getElementById("txtIsSaved").value != "1")) {
			var url = "contributesave.aspx";

			// if there's any new content in the browser, add it to the url
			if (! isSaved) {
				url += "?";
				if (document.getElementById("txtUserName")) {
					url += "name=" + escape(document.getElementById("txtUserName").value) + "&";
				}
				if (document.getElementById("txtUserEmail")) {
					url += "email=" + escape(document.getElementById("txtUserEmail").value) + "&";
				}
				if (document.getElementById("chkUserPermission")) {
					if (document.getElementById("chkUserPermission").checked) {
						url += "useemail=Y&";
					} else {
						url += "useemail=N&";
					}
				}
				if (document.getElementById("txtPageTitle")) {
					url += "title=" + escape(document.getElementById("txtPageTitle").value) + "&";
				}
				if (document.getElementById("txtPageContent")) {
					url += "content=" + escape(document.getElementById("txtPageContent").value) + "&";
				}
			}

			// open the save window
			openURLInNewWindow("Save?", "save", url, 300, 300, "");
		}
	}
	*/
}

// lowercase version of the function below
function setchanged(noautosave) {
	setChanged(noautosave);
}

// something's changed, so highlight the button
function setChanged(noautosave) {
	if ((document.getElementById('txtPageName')) && ((document.getElementById('txtPageName').value=="contribute.aspx") || (document.getElementById('txtPageName').value=="albumedit.aspx") || (document.getElementById('txtPageName').value=="categoryedit.aspx"))) {
		if (document.getElementById("btnFiles")) {
        	pmAutoSave_blocked = noautosave;
			isSaved = false;
			
			// set the flag in the text field as well
			if (document.getElementById("txtIsSaved")) {
		        document.getElementById("txtIsSaved").value = "false";
			}

			// highlight the button
			document.getElementById("btnFiles").className = "panelbuttonreminder";
			
			// reset the timeout
			if (pmAutoSaveWarning_timeout != null) {
				clearTimeout(pmAutoSaveWarning_timeout);
			}
			if (pmAutoSave_timeout != null) {
				clearTimeout(pmAutoSave_timeout);
			}
			// allow for an autosave not to be requested (if we're doing a file upload)
			if ((noautosave==null) || (noautosave==false)) {
				setAutoSave();
			}
		}
	}
}

// tells the system that no save check is required
function setNoCheck() {
	checkRequired = false;
}
function setnocheck() {
	checkRequired = false;
}

// opens a document in a new window
function openURLInNewWindow(title,name,url,width, height, additionalParams) {
	var newWindow = null;

	params = '';

	if (width > 0) {
		if (width < screen.availWidth) {
			// if we're specifying the width and height, then centre it on the screen
			dialogLeft = Math.ceil((screen.width / 2) - (width / 2));
		} else {
			dialogLeft = 0;
			width = screen.availWidth;
		}
	} else {
		// if no width and height are specified, then fill the screen
		dialogLeft = 0;
		width = screen.availWidth;
	}

	if (height > 0) {
		if (height < screen.availHeight) {
			// if we're specifying the width and height, then centre it on the screen
			dialogTop = Math.ceil((screen.height / 2) - (height / 2));
		} else {
			dialogTop = 0;
			height = screen.availHeight;
		}
	} else {
		// if no width and height are specified, then fill the screen (allowing space for taskbar)
		dialogTop = 0;
		height = screen.availHeight;
	}

	if ((additionalParams.indexOf('menubar') != -1) && (is.ie4up)) {
		// ie mucks up the height if we include a menu bar, so do some adjustment
		params = 'width=' + (width - 5) + ',height=' + (height - 23) + ',dependent,left=' + dialogLeft + ',top=' + dialogTop;
	} else {
		params = 'width=' + width + ',height=' + height + ',dependent,left=' + dialogLeft + ',top=' + dialogTop;
	}

	if (additionalParams != '') {
		params = params + ',' + additionalParams
	}

	newWindow = window.open (url, '', params);
	if (newWindow) {
		newWindow.document.close();
		newWindow.focus();
		return newWindow;
	} else {
		return null;
	}
}

// delete the file (or not)
function checkDelete(item) {
    if (confirm(lang_confirmdeletestart + lang_checkdelete[item] + lang_confirmdeleteend)) {
		return true;
	} else {
		return false;
	}
}

// displays a confirmation message
function checkMessage(msg) {
	if (confirm(msg)) {
		return true;
	} else {
		return false;
	}
}

// delete the page (or not)
function checkSaveOption(deletemessage, publishmessage) {
	if (document.getElementById("lbSaveOption")) {
		if (document.getElementById("lbSaveOption").options[document.getElementById("lbSaveOption").selectedIndex].value == "d") {
			if (deletemessage == "") {
			    deletemessage = lang_confirmdeletepage;
			}
			if (confirm(deletemessage)) {
				return true;
			} else {
				return false;
			}
		} else if (document.getElementById("lbSaveOption").options[document.getElementById("lbSaveOption").selectedIndex].value.indexOf("p") != -1) {
			return true;
		} else {
			return true;
		}	
	} else {
		return true;
	}
}

// delete the image (or not)
function checkRemoveImage() {
	if (confirm(lang_confirmdeletephoto)) {
		return true;
	} else {
		return false;
	}
}

// delete the document (or not)
function checkRemoveDocument() {
	if (confirm(lang_confirmdeletedocument)) {
		return true;
	} else {
		return false;
	}
}

// delete the clip (or not)
function checkRemoveMultimedia() {
    if (confirm(lang_confirmdeletemultimedia)) {
		return true;
	} else {
		return false;
	}
}

// delete the cache (or not)
function checkClearCache() {
	if (confirm(lang_confirmclearcache)) {
		return true;
	} else {
		return false;
	}
}

// create the cache (or not)
function checkCreateCache() {
	if (confirm(lang_confirmspider)) {
		return true;
	} else {
		return false;
	}
}

// log out (or not)
function checkLogout() {
	if (confirm(lang_confirmlogout)) {
		return true;
	} else {
		return false;
	}
}

// allows a default button to be set up, activated when enter is pressed
function HandleDefaultButton(btn, event) {
  	if ((event.which == 13) || (event.keyCode == 13)){
	   	event.returnValue=false;
	   	event.cancel = true;

		obj = document.getElementById(btn);
		if (obj) {
			// this is a complete fudge, but we need to make the search button check that we don't have
			// saved work in PageMaker, and this is the easiest place to do it
			if (obj.id.indexOf("btnSearchInstant") >= 0) {
				if (! checkQuit()) {
					return false;
				}
			}

			obj.click();
		}
	}

	return true;
}

// when enter is pressed, move onto the next textbox
function HandleNextTextBox(id, event) {
  	if ((event.which == 13) || (event.keyCode == 13)){
	   	event.returnValue=false;
	   	event.cancel = true;

		obj = document.getElementById(id);
		if (obj) {
			setTimeout("document.getElementById('" + id + "').focus();", 100);
		}
		return false;
	} else {
		return true;
	}
}

//Match spaces at beginning and end of text and replace with null strings
function strtrim(input) {
    output = new String();
    output = input;

    return output.replace(/^\s+/,'').replace(/\s+$/,'');
}

// trims the strings contained within these text boxes, to avoid any validation issues
function trimIdValues(username, password) {
    if (document.getElementById(username)) {
        document.getElementById(username).value = strtrim(document.getElementById(username).value);
    }
    if (document.getElementById(password)) {
        document.getElementById(password).value = strtrim(document.getElementById(password).value);
    }
}

// returns the width of a specified image element
function getImageWidth(image) {
    if (document.getElementById(image)) {
        if (document.getElementById(image).offsetWidth) {
            return document.getElementById(image).offsetWidth;
        } else {
            return document.getElementById(image).style.pixelWidth;
        }
    }
}

// returns the height of a specified image element
function getImageHeight(image) {
    if (document.getElementById(image)) {
        if (document.getElementById(image).offsetHeight) {
            return document.getElementById(image).offsetHeight;
        } else {
            return document.getElementById(image).style.pixelHeight;
        }
    }
}

// get and store the size of a linked image
function getImageSize(dosubmit) {
    // get and store the image dimensions
    if (document.getElementById("txtImageLinkWidth")) {
        document.getElementById("txtImageLinkWidth").value = getImageWidth("imgImageLink");
    }
    if (document.getElementById("txtImageLinkHeight")) {
        document.getElementById("txtImageLinkHeight").value = getImageHeight("imgImageLink");
    }

    // if requested, resubmit....
    if ((dosubmit) && (document.getElementById("btnImageLinkAdd"))) {
        document.getElementById("btnImageLinkAdd").click();
	}
}

// enables the button for adding an image link if there's a valid-ish value in the text box
function checkImageLink() {
    if ((document.getElementById('txtImageAddress')) && (document.getElementById('btnImageLink'))) {
        if (document.getElementById('txtImageAddress').value.indexOf('://') != -1) {
            document.getElementById('btnImageLink').disabled=false;
        } else {
            document.getElementById('btnImageLink').disabled=true;
        }
    }
}


// enables the button for adding a document link if there's a valid-ish value in the text box
function checkDocumentsLink() {
    if ((document.getElementById('txtDocumentsAddress')) && (document.getElementById('btnDocumentsLink'))) {
        if (document.getElementById('txtDocumentsAddress').value.indexOf('://') != -1) {
            document.getElementById('btnDocumentsLink').disabled=false;
        } else {
            document.getElementById('btnDocumentsLink').disabled=true;
        }
    }
}

// enables the button for adding a multimedia link if there's a valid-ish value in the text box
function checkMultimediaLink() {
    if ((document.getElementById('txtMultimediaAddress')) && (document.getElementById('btnMultimediaLink'))) {
        if (document.getElementById('txtMultimediaAddress').value.indexOf('://') != -1) {
            document.getElementById('btnMultimediaLink').disabled=false;
        } else {
            document.getElementById('btnMultimediaLink').disabled=true;
        }
    }
}

// enables the button for adding code if there's something in the text box
function checkCodeLink() {
    if ((document.getElementById('txtMultimediaCode')) && (document.getElementById('btnMultimediaCode'))) {
        if (document.getElementById('txtMultimediaCode').value != "") {
            document.getElementById('btnMultimediaCode').disabled=false;
        } else {
            document.getElementById('btnMultimediaCode').disabled=true;
        }
    }
}

// hide the sitemap lists by default, so that they can then be expanded by the user...
function hideSitemapListsBefore() {
	document.writeln('<style type="text/css">');
	document.writeln('#htmlSitemap ul {');
	document.writeln('display:none;');
	document.writeln('}');
	document.writeln('</style>');
}

// just in case the css method didn't work, run through and hide the sitemap lists after they've been displayed...
function hideSitemapListsAfter() {
	var map = document.getElementById("htmlSitemap");
	if (map != null) {
		var objects = map.getElementsByTagName("ul");
		for (var i=0;i<objects.length;i++){
			// don't hide the main list!
			if (objects[i].id != "htmlSitemap") {
				objects[i].style.display = 'none';
			}
		}
	}
}

// show a section of the sitemap
function showSitemap(id) {
	if (document.getElementById("sc" + id)) {
		document.getElementById("sc" + id).style.display = 'block';
	}
	if (document.getElementById("sp" + id)) {
		document.getElementById("sp" + id).style.display = 'block';
	}
	if (document.getElementById("p" + id)) {
		document.getElementById("p" + id).style.display = 'none';
	}
	if (document.getElementById("m" + id)) {
		document.getElementById("m" + id).style.display = 'inline';
	}
}

// hide a section of the sitemap
function hideSitemap(id) {
	if (document.getElementById("sc" + id)) {
		document.getElementById("sc" + id).style.display = 'none';
	}
	if (document.getElementById("sp" + id)) {
		document.getElementById("sp" + id).style.display = 'none';
	}
	if (document.getElementById("p" + id)) {
		document.getElementById("p" + id).style.display = 'inline';
	}
	if (document.getElementById("m" + id)) {
		document.getElementById("m" + id).style.display = 'none';
	}
}

// show if hidden or hide if shown 
function toggleElement(id, redirect) {
	if (document.getElementById(id)) {
		if (document.getElementById(id).style.display == "block") {
			document.getElementById(id).style.display = "none";
		} else {
			document.getElementById(id).style.display = "block";
		}
		if (redirect != "") {
			document.location = "#" + redirect;
		}
	}
}

// keeps a record of the comment form state, in order to restore it later...
function storeCommentState() {
    if (document.getElementById('txtCommentsOpen')) {
        document.getElementById('txtCommentsOpen').value=document.getElementById('htmlCommentsInputFormInner').style.display
    }
}

// restores the comment form to its previous state
function restoreCommentState() {
    if (document.getElementById('txtCommentsOpen')) {
        if (document.getElementById('txtCommentsOpen').value != "") {
            document.getElementById('htmlCommentsInputFormInner').style.display = document.getElementById('txtCommentsOpen').value;
        }
    }
}

// indicates which panel to show within the dynamic pagemaker system
function setCurrentPanel(id) {
	if (document.getElementById("txtCurrentPanel")) {
		document.getElementById("txtCurrentPanel").value = id;
	}
}

// indicates which version of PageMaker to load
function setPageMaker(id) {
	if (document.getElementById("txtPageMakerVersion")) {
		document.getElementById("txtPageMakerVersion").value = id;
	}
}

// forces a search for the current page...
function SearchForPageLinks (id) {
	// look for the search box and button
	if (document.getElementById("header_txtSearchInstant")) {
		document.getElementById("header_txtSearchInstant").value = "page_id__" + id;
	}
	
	if (document.getElementById("header_btnSearchInstant")) {
		document.getElementById("header_btnSearchInstant").click();
	} else if (document.getElementById("header_btnSearchImageInstant")) {
		document.getElementById("header_btnSearchImageInstant").click();
	}
}

// forces a search for the current category...
function SearchForCategoryLinks (id) {
	// look for the search box and button
	if (document.getElementById("header_txtSearchInstant")) {
		if (isNaN(id)) {
			document.getElementById("header_txtSearchInstant").value = "category_idtxt__" + id;
		} else {
			document.getElementById("header_txtSearchInstant").value = "category_id__" + id;
		}
	}

	if (document.getElementById("header_btnSearchInstant")) {
		document.getElementById("header_btnSearchInstant").click();
	} else if (document.getElementById("header_btnSearchImageInstant")) {
		document.getElementById("header_btnSearchImageInstant").click();
	}
}

function checkCategoryUpdate(id) {
	if (document.getElementById(id)) {
		// only allow letters to refresh the list...
		if ((document.getElementById(id).options[document.getElementById(id).selectedIndex].value != "") && (document.getElementById(id).options[document.getElementById(id).selectedIndex].value.indexOf("ALPHA") != -1)) {
			return true;
		} else {
			return false;
		}
		
	}
}

// clear this upload
function clearRadUploads(upload) {
	if (upload) {
		var fileInputs = upload.getFileInputs();
		for (var i=0; i<fileInputs.length; i++)
		{
			upload.clearFileInputAt(i);
		}
	}
}

//doNotRadUpload - a global variable, indicating that the file inputs should be cleared.
// It is set to false in the OnClientClick property of the upload button
var doNotRadUpload = true;
function OnClientSubmitting(progressManager, args) {
	if (doNotRadUpload)	{
	    //var prm = Sys.WebForms.PageRequestManager.getInstance();
        
		//Clear the file inputs
		var upload = getRadUpload('RadUploadImage');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			    $telerik.$("#RadProgressManagerImage").css("display", "none");
			//}
        }
		upload = getRadUpload('RadUploadDocument');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			    $telerik.$("#RadProgressManagerDocument").css("display", "none");
			//}
        }
		upload = getRadUpload('RadUploadMultimedia');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			    $telerik.$("#RadProgressManagerMultimedia").css("display", "none");
			//}
        }
		upload = getRadUpload('RadUploadMultimediaImage');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			    $telerik.$("#RadProgressManagerMultimediaImage").css("display", "none");
			//}
        }
		upload = getRadUpload('RadUploadMySpaceImage');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			    $telerik.$("#RadProgressManagerMySpaceImage").css("display", "none");
			//}
        }
		upload = getRadUpload('RadUploadCategoryImage');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			    $telerik.$("#RadProgressManagerCategoryImage").css("display", "none");
			//}
        }
		upload = getRadUpload('RadUploadCategoryIcon');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			   $telerik.$("#RadProgressManagerCategoryIcon").css("display", "none");
			//}
        }
		upload = getRadUpload('RadUploadAdvertImage');
		if (upload) {
			clearRadUploads(upload);
			//if (prm.get_isInAsyncPostBack) {
			    $telerik.$("#RadProgressManagerAdvertImage").css("display", "none");
			//}
        }

        upload = getRadUpload('RadUploadFlagsImage');
        if (upload) {
            clearRadUploads(upload);
            //if (prm.get_isInAsyncPostBack) {
                $telerik.$("#RadProgressManagerFlagsImage").css("display", "none");
            //}
        }

        upload = getRadUpload('RadUploadHomePageWelcomeBanner');
        if (upload) {
            clearRadUploads(upload);
            //if (prm.get_isInAsyncPostBack) {
                $telerik.$("#RadProgressManagerHomePageWelcomeBanner").css("display", "none");
            //}
		}
	} else {
		// cancel the timeout
		clearTimeout(pmAutoSaveWarning_timeout);
		clearTimeout(pmAutoSave_timeout);
	}
}

// sets up the rad
function enableRadCancel(id) {
    /*
    // ikg - removed for upgraded Telerik controls
	RadUploadNameSpace.RadProgressArea.prototype._CancelRequest =
 		RadUploadNameSpace.RadProgressArea.prototype.CancelRequest;
		RadUploadNameSpace.RadProgressArea.prototype.CancelRequest = function()	{
			// clear the upload
			var upload = GetRadUpload(id);
			clearRadUploads(upload);

		  	// and cancel
			this._CancelRequest();
		}
    */
}

// wrapper function for the Google Map unload, which needs to be called from the 
// body tag but isn't necessarily valid
function GMapUnload() {
	try {
		GUnload();
		return true;
	} catch (err) {
		return false;
	}
}

// make sure that we're not going to get problems due to lowercase nonsense
if (typeof(Page_ClientValidate) == 'function') {
	page_clientvalidate = Page_ClientValidate;
}

function flashBanner(filename, width, height) {
    filename = filename.replace(".swf", "");
    
	// Major version of Flash required
	var requiredMajorVersion = 6;
	// Minor version of Flash required
	var requiredMinorVersion = 0;
	// Minor version of Flash required
	var requiredRevision = 0;

    // Version check based upon the values entered above in "Globals"
    var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

    // Check to see if the version meets the requirements for playback
    if (hasRequestedVersion) {
	    // if we've detected an acceptable version
		// embed the Flash Content SWF when all tests are passed
		AC_FL_RunContent(
		    "src", filename,
		    "width", width,
		    "height", height,
		    "align", "middle",
    		"id", "splashflash",
	    	"quality", "high",
		    "bgcolor", "#FFFFFF",
			"name", "splashflash",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		    );
	} else {  // flash is too old or we can't detect the plugin
	    var alternateContent = '<div style="width:' + width + 'px;height:' + height + 'px;">&nbsp;</div>';
		document.write(alternateContent);  // insert non-flash content
	}

    // and apply the ie fix
    theObjects = document.getElementsByTagName("object");
    for (var i = 0; i < theObjects.length; i++) {
        theObjects[i].outerHTML = theObjects[i].outerHTML;
    }
}

// depending on whether a checkbox is ticked, shows an accompanying form block
function showCheckboxFormArea(chkbox, formarea) {
    if (document.getElementById(chkbox)) {
        if (document.getElementById(chkbox).checked) {
            document.getElementById(formarea).style.display='block';
        }else{
            document.getElementById(formarea).style.display='none';
        }
    }
}

// when a different selection is made from a list, hide and show the corresponding html tags
function ChangeListSelection(list, prefix) {
    // first of all, hide the blocks relating to all items in the list
    for (var i=0;i<list.options.length;i++) {
        if (document.getElementById(prefix + list.options[i].value)) {
            document.getElementById(prefix + list.options[i].value).style.display = "none";
        }
    }

    // and then show the block relating to the selected item
    if (document.getElementById(prefix + list.options[list.selectedIndex].value)) {
        document.getElementById(prefix + list.options[list.selectedIndex].value).style.display = "block";
    }
}

// when an upload is selected, enable the relevant button
function radUploadSelected(radUpload, eventArgs) {
    if (radUpload._fileInput.id == "RadUploadAdvertImagefile0") {
        document.getElementById('btnAdvertsImageUpload').disabled = false;
    } else if (radUpload._fileInput.id == "RadUploadHomePageWelcomeBannerfile0") {
        document.getElementById('btnHomePageWelcomeBanner').disabled = false;
    } else if (radUpload._fileInput.id == "RadUploadMySpaceImagefile0") {
        document.getElementById('btnMySpaceIconUpload').disabled = false;
    } else if (radUpload._fileInput.id == "RadUploadIconfile0") {
        document.getElementById('btnIconUpload').disabled = false;
    } else if (radUpload._fileInput.id == "RadUploadImagefile0") {
        document.getElementById('btnImageUpload').disabled = false;
    } else if (radUpload._fileInput.id == "RadUploadDocumentfile0") {
        document.getElementById('btnDocumentsUpload').disabled = false;
    } else if (radUpload._fileInput.id == "RadUploadMultimediafile0") {
        document.getElementById('btnMultimediaUpload').disabled = false;
    } else if (radUpload._fileInput.id == "RadUploadFlagsImagefile0") {
        document.getElementById('btnFlagsImageUpload').disabled = false;
    }
}
