/*********************************************************************
Name: common_functions_en.js
Description: This file holds common javascript functions, in English
**********************************************************************/


/************************************************************************************
Name: PopUpGeneric(URL, width, height, resize)
Description: Pops up a window

Usage sample: a href="javascript:PopUpGeneric('/chat/default.asp', 601, 500, 'yes')"

Parameter resize - valid values are 'yes' (resizable) or 'no' (not resizable)
*************************************************************************************/
function PopUpGeneric(URL, width, height, resize)
	{

	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: OpenHCW()
Description: Function to open help for the Advanced Content Editor
*************************************************************************************/
function OpenHCW()
	{
	 window.open("/includes/hcw_form_en.htm","_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=770,height=550");
	}

/************************************************************************************
Function: OpenVDL()
Description: Function to open help for the Advanced Content Editor
*************************************************************************************/
function OpenVDL()
	{
	 window.open("/includes/vdl_form_en.htm","_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=770,height=550");
	}

/************************************************************************************
Function: OpenTeam()
Description: Function to open help for the Advanced Content Editor
*************************************************************************************/
function OpenTeam()
	{
	 window.open("/includes/tmc_form_en.htm","_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=770,height=550");
	}


/************************************************************************************
Function: OpenHelp()
Description: Function to open help for the Advanced Content Editor
*************************************************************************************/
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: doClear()
Description: function that clears a named fileupload field (upFile)

Used in: forum_functions.asp
*************************************************************************************/
function doClear()
{
document.forms[0].upFile.value = ""
}

/********************************************************************************************
Function: doClearProfilePhoto() 
Description: function that clears and disables a named fileupload field (upFile)

Used for member upload image in presentation - edit CV (in members_edit.asp)
*********************************************************************************************/
function doClearProfilePhoto()
{
document.forms[0].upFile.value = "";
document.forms[0].upFile.disabled = false;
}

/**************************************************************************************
Function: CheckForm()
Description: Function to check if Searchform keywords (fieldname: KW) are entered before submitting

Used in: faq_search.asp, forum_search.asp, help_search.asp and lib_search.asp
***************************************************************************************/
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: gotoURL(url)
Description: Function to go to URL

Usage sample: input type=button value="Exit" onClick=gotoURL('/the_url.asp?mode=list')
*************************************************************************************************/
function gotoURL(url)
 {self.location.href = url;}

/*******************************************************************************************************
Function: RecUpdate(Rec_Id)
Description: Function for multiple rows update

Parameter: a valid recordID

Usage sample: Please see implementation in faq_mgr.asp, help_mgr.asp, menu_mgr.asp, admin_forums.asp,
        admin_subscribers.asp, admin_systables.asp, poll_admin.asp
*******************************************************************************************************/
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: PopTheImg(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop)
Description: Function for poping-up images.

Sample Usage: Reference it like this in the html - 
&lt;a href="javascript:;" onClick="PopTheImg('jpg','/assets/layout/my_image.jpg','640','480','Image 1','0','0')"&gt;Click!&lt;/a&gt; 

Used in: photos_functions.asp
*************************************************************************************************************************/
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: ShowWaitMsg()
 Description: Function that displays wait message when submitting a form

 css-style required: .waitMsg { visibility:hidden; color: red; }
 
 Sample code: &lt;span class="waitMsg" ID="id_waitmsg"&gt;Loading Data. Please Wait...&lt;br&gt;&lt;img id=pbar src="/forum_img/loading.gif"&gt;&lt;/span&gt;
 
 Used in: admin_functions.asp, calendar_functions.asp, forum_functions.asp, inc_subscriptions.asp, members_edit.asp, members_search.asp,
           members_view.asp
**************************************************************************************************************************************/
function ShowWaitMsg()
{
if(id_waitmsg) id_waitmsg.style.visibility = 'visible';
setTimeout('document.images["pbar"].src = "/forum_img/loading.gif"', 200);
}

/******************************************************************************************************
Function: validate()
Description: Check form for Document Upload

Used in: doc_functions.asp, doc_gallery_functions.asp
******************************************************************************************************/
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() }
}

/*********************************************************
Function: function checkDocSubmit(mInput)
Description: Functions used by - lib_functions.asp
Check form for Document Upload

Parameter mInput: 0 = Category, 1 = Document file, 2 = Link/URL
*********************************************************/
function checkDocSubmit(mInput) 
{
 var msg = "You must:\n";
 var myLinkType = mInput;

 if (myLinkType == 0) { // Category
  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"); } 

 }
 
 if (msg != "You must:\n")
  { alert(msg) 
	 return; }

 else 
 { document.forms[0].submit() }

}

/******************************************************************
Function: InsertDocLink(url)
Description: used in, doc_gallery_functions.asp by the MBEditor
******************************************************************/
function insertDocLink(url)
 {
  var oSel = window.opener.content.document.selection.createRange(); 
  if (oSel!=null) 
      oSel.pasteHTML(url); 
}

/********************************************************************************************************************
Function: InsertImage(inpImgURL, inpImgAlt, inpImgAlign, inpImgBorder, inpImgWidth, inpImgHeight, inpHSpace, inpVSpace)
Description: Used in, img_gallery_functions.asp - by the MBEditor
********************************************************************************************************************/
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: validRadio(formField)
Description: Is a Helper function to validate(), checks if radiobuttons are checked.
*******************************************************************/
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; 
}