// ******************************************************************************************************
// Function to popup url or image in new window
// ******************************************************************************************************
function PopUpGeneric(URL, width, height)
	{
	// 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=1,scrollbars=auto,width=" + width + ",height=" + height + ",left="+popleft+",top="+poptop)
	}

// ******************************************************************************************************
// Function for poping-up images : Reference it like this in the html: 
// <a href="javascript:;" onClick="PopUpImg('jpg','/assets/layout/my_image.jpg','640','480','Image 1','0','0')">Click!</a> 
// ******************************************************************************************************
function PopUpImg(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()
}

// OPEN IMAGE-LIB
function popURL(url)
	{
	// 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","scrollbars=NO,width=480,height=400,left="+popleft+",top="+poptop)
	}

// ******************************************************************************************************
// 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="/assets/layout/loading.gif"></span>
// ******************************************************************************************************
function ShowWaitMsg()
{
if(id_waitmsg) id_waitmsg.style.visibility = 'visible';
setTimeout('document.images["pbar"].src = "/assets/layout/loading.gif"', 200);
}

// ******************************************************************************************************
// 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 to uncheck all radiobuttons on a form
// **************************************************
   function UncheckRadios(formid)
    {
     frm_len=formid.length  // get the number of form elements
     for(i=0;i<frm_len;i++)
         {
          if(formid.elements[i].type=="radio")
            {formid.elements[i].checked=false}
         }
   }

// ************************************************
//  Function to clear textfield by ID
// ************************************************
function clearTextField(textfield,newvalue)
{
 elem = document.getElementById(textfield);
 elem.value = newvalue;
}

// ************************************* //
// 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 to go to URL
// Usage: <input type=button value=""Avbryt"" onClick=gotoURL('" & THIS_SCRIPT & "?mode=listSchemas')>
// *********************************** //
function gotoURL(url)
{ self.location.href = url; }


// ****************************************** //
// Check newsletter subscriber - edit email
// ****************************************** //
function checkEditNewsLetterEmail()
{
 var msg
 msg = "Du måste fylla i" + ":\n";

 checkEmail = document.subscribe.pren_email.value
 checkNewEmail = document.subscribe.pren_email_new.value

 if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
 { msg += ("- En korrekt nuvarande epostadress" + "\n"); }

 if ((checkNewEmail.indexOf('@') < 0) || ((checkNewEmail.charAt(checkNewEmail.length-4) != '.') && (checkNewEmail.charAt(checkNewEmail.length-3) != '.'))) 
  { msg += ("- En korrekt ny epostadress" + "\n"); }

	if (msg != "Du måste fylla i" + ":\n") {
	alert(msg)
	return;
	}

	else 
	{ document.subscribe.submit() }
}

// *************************************************
// Functions related to form Adressändring
// *************************************************
function textCounter( field, countfield, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    alert( 'Meddelandetexten får ej överstiga 250 tecken.' );
    return false;
  }
  else
  {
    countfield.value = maxlimit - field.value.length;
  }
}


// function UnKnownID()
function UnKnownID()
{ 
document.forms[0].Medlemsnummer.value = "99999"; 
}


// function Snabbis()
function Snabbis()
{
document.forms[0].NyAdress.value = document.forms[0].Adress.value;
document.forms[0].NyAdress2.value = document.forms[0].Adress2.value;
document.forms[0].NyPostnummer.value = document.forms[0].Postnummer.value;
document.forms[0].NyOrt.value = document.forms[0].Ort.value;
document.forms[0].NyLand.value = document.forms[0].Land.value;
document.forms[0].NyTelefon.value = document.forms[0].Telefon.value;
}