function PopUpGeneric(URL, width, height, resize)
	{
	// Popup window with links to image library. 
	var popleft=((document.body.clientWidth - 440) / 2)+window.screenLeft; 
	var poptop=(((document.body.clientHeight - 460) / 2))+window.screenTop-40;		
	window.open(URL,"_blank","resizable=" + resize + ",scrollbars=yes,width=" + width + ",height=" + height + ",left="+popleft+",top="+poptop)
	}

// ******************************************************************************************************
// Function to open help i Editor area
// ******************************************************************************************************
function OpenHelp(){
window.open("/Editor/Editor_help/help.htm","Help","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=770,height=550");
			}

// function that clears a textfield (e.g. used by forum_functions.asp)
function doClear()
{
document.forms[0].upFile.value = ""
}

// function that clears a textfield (e.g. for member upload image in presentation - edit CV)
function doClearProfilePhoto()
{
document.forms[0].upFile.value = "";
document.forms[0].upFile.disabled = false;
}


//Function to check if Searchform is filled in correctly before submitting
function CheckForm() {
 //Check for a something to search for
 if (document.forms[0].KW.value == ""){
  msg = "You must select something\n";
  alert(msg + "to search for ..\n");
  document.forms[0].KW.focus();
 return false;
 }	
return true;
}

//Function to go to URL
// usage: <input type=button value=""Avbryt"" onClick=gotoURL('" & THIS_SCRIPT & "?mode=listSchemas')>
function gotoURL(url)
{
self.location.href = url;
}

// ******************************************
// Functions for (multiple rows update)
// ******************************************
function RecUpdate(Rec_Id)
{
var ThisID = "*" + (Rec_Id) + "*"
 if (document.forms[0].hidRec_Ids.value == "")
 {	
  document.forms[0].hidRec_Ids.value = (ThisID)
  }
 if (document.forms[0].hidRec_Ids.value != "")
 {  
  var str = document.forms[0].hidRec_Ids.value;
  var pos = str.indexOf(ThisID);
  if (pos == -1) 
  {
  document.forms[0].hidRec_Ids.value = document.forms[0].hidRec_Ids.value + ", " + (ThisID)  
  } 											 
 }	
}

// Function for poping-up images : Reference it like this in the html: 
// <a href="javascript:;" onClick="PopTheImg('jpg','/assets/layout/my_image.jpg','640','480','Image 1','0','0')">Click!</a> 
function PopTheImg(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
 screenh = window.screen.height;
 screenw = window.screen.width;
 posLeft = (screenw-imageWidth)/2;
 posTop = (screenh-imageHeight)/2;
 theWindow = window.open("","theWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
 theWindow.document.open();
 theWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
 theWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="'+alt+'" onClick="javascript:window.self.close();" galleryimg="no">');
 theWindow.document.write('</body></html>');
 theWindow.document.close();
 theWindow.focus()
}

// Function that displays wait message when submitting a form
// css-style: .waitMsg { visibility:hidden; color: red; }
// sample code: <span class="waitMsg" ID="id_waitmsg">Loading Data. Please Wait...<br><img id=pbar src="loading.gif"></span>
function ShowWaitMsg()
{
if(id_waitmsg) id_waitmsg.style.visibility = 'visible';
setTimeout('document.images["pbar"].src = "loading.gif"', 200);
}

// FUNCTIONS USED BY MBEditor in: doc_default.asp, doc_gallery.asp and img_gallery.asp //
// Check form for Document Upload
function validate() 
{
 var msg
 msg = "You must:\n";

 if (document.forms[0].file.value == '')
	{
	msg += ("- Select a document to upload.\n");
	}

 if (document.forms[0].docTitle.value == '')
	{
	msg += ("- Enter a title for the document.\n");
	}

 if (document.forms[0].docDescr.value == '')
	{
	msg += ("- Write a short description of the document.\n");
	}

 //if (!validRadio(document.forms[0].ForumID)) 
  //{ msg += ("- choose a forum to publish the document in.\n"); }

 if (msg != "You must:\n") {
  alert(msg)
  return;
 }

 else 
 { document.forms[0].submit() }
}


// NEW 2006-10-05
// FUNCTIONS USED BY MBEditor in: doc_default.asp, doc_gallery.asp and img_gallery.asp //
// Check form for Document Upload
function checkDocSubmit(mInput) 
{
 var msg = "You must:\n";
 var myLinkType = mInput;

 if (myLinkType == 0) { // Category
  // if (document.forms[0].file.value == '') { msg += ("- Select a document to upload.\n");}
  if (document.forms[0].docTitle.value == '') {msg += ("- Enter a title for the category.\n");}
  if (document.forms[0].docDescr.value == '') {msg += ("- Write a short description of the category.\n");}
 }

 else if (myLinkType == 1) // Document/file
 {
  if (document.forms[0].file.value == '') { msg += ("- Select a document.\n");}
  if (document.forms[0].docTitle.value == '') {msg += ("- Enter a title for the document.\n");}
  if (document.forms[0].docDescr.value == '') {msg += ("- Write a short description of the document.\n");}
  if (!validRadio(document.forms[0].docUserType)) { msg += ("- set permissions for file or link.\n"); } 
 }

 else if (myLinkType == 2) // Link/URL
 {
  if (document.forms[0].file.value == '') { msg += ("- Enter a link.\n");}
  if (document.forms[0].docTitle.value == '') {msg += ("- Enter a title for the link.\n");}
  if (document.forms[0].docDescr.value == '') {msg += ("- Write a short description of the link.\n");}
  if (!validRadio(document.forms[0].docUserType)) { msg += ("- set permissions for file or link.\n"); } 

 }
 
 // Permissions has to be checked for all linktypes

 if (msg != "You must:\n")
  { alert(msg) 
	 return; }

 else 
 { document.forms[0].submit() }

}
// END NEW 2006-10-05


// function InsertDocLink
function insertDocLink(url)
 {
  var oSel = window.opener.content.document.selection.createRange(); 
  if (oSel!=null) 
      oSel.pasteHTML(url); 
}

// function InsertImage
function InsertImage(inpImgURL, inpImgAlt, inpImgAlign, inpImgBorder, inpImgWidth, inpImgHeight, inpHSpace, inpVSpace)
 {
  window.opener.content.document.execCommand("InsertImage", false, inpImgURL);
  var oSel = window.opener.content.document.selection.createRange()
  var sType = window.opener.content.document.selection.type 

  // FIX in order to receive values from form, i.e: align, border, VSpace and HSpace
  var inpImgAlign = document.forms[0].img_align.value;
  var inpImgBorder = document.forms[0].img_border.value;
  var inpHSpace = document.forms[0].img_hspace.value;
  var inpVSpace = document.forms[0].img_vspace.value;
  // END FIX
	
  if ((oSel.item) && (oSel.item(0).tagName=="IMG")) 
   {
    if(inpImgAlt!="")
     oSel.item(0).alt = inpImgAlt
     oSel.item(0).align = inpImgAlign
     oSel.item(0).border = inpImgBorder
    if(inpImgWidth!="")
     oSel.item(0).width = inpImgWidth 
    if(inpImgHeight!="")
     oSel.item(0).height = inpImgHeight
    if(inpHSpace!="")
     oSel.item(0).hspace = inpHSpace
    if(inpVSpace!="")
     oSel.item(0).vspace = inpVSpace
    }  
   }

// function showMsg()
function showMsg() {
 document.getElementById("popupMsg").style.visibility='visible'
}

// Function to check if radiobuttons are checked
// Helper function to validate() - validates radiobuttons
function validRadio(formField) 
{ 
 var result = true; 
 var radioSelected; 

 for (var i=0; i<formField.length; i++){ 
 if (formField[i].checked) { 
  radioSelected = formField[i].value 
 } 
}

if (!radioSelected)
 { result = false; } 

return result; 
}