var win = null;

function NewWindow(mypage,myname,w,h,scroll,resize){
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  if ( resize == "no" ){
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',noresizable'
  }else{
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
  }
  win = window.open(mypage,myname,settings)
}


function textLimit(field, maxlen){
  if (field.value.length > maxlen + 1)
    alert('Du har överskridit antalet tillåtna tecken, ' + maxlen + ' st!');
  if (field.value.length > maxlen)
    field.value = field.value.substring(0, maxlen);
}


//function textLimit(field, maxlen){
//  if (field.value.length > maxlen){
//    field.value = field.value.substring(0, maxlen);
//    alert('Du har överskridit antalet tillåtna tecken, ' + maxlen + ' st!');
//  }
//}


function toggleCells(el, col1, col2){
  for (i = 0; i < el.parentNode.childNodes.length; i++)
    if (el.parentNode.childNodes[i].tagName)
      el.parentNode.childNodes[i].style.backgroundColor=col2
      el.style.backgroundColor=col1
}


function PassFlash(s_movieid, s_movievar, s_movietext){
  window.document.all(s_movieid).SetVariable(s_movievar, s_movietext);
}


function submitenter(myfield,e) {
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  if (keycode == 13) {
    myfield.form.submit();
    return false;
  }
  else
  return true;
}


function visitdf(){
  leftPos = 0
  topPos = 0
  if (screen) {
    leftPos = (screen.width / 2) - 172
    topPos = (screen.height / 2) - 100
  }
  ElementWindow = window.open('http://df.frostconsulting.se/popup_index.asp','infopopupdf','width=345,height=200,left='+leftPos+',top='+topPos)
}


function HideRow(id){
  if( document.getElementsByName ){
    var rows = document.getElementsByName( id );
    if( rows && rows.length > 0 ){
      for( i=0;i<rows.length;i++ ){
        if ( rows[i].style.display == "none" ){
          rows[i].style.display = "";
        }else{
          rows[i].style.display = "none"
        }
      }
    }
  }
}


function ToggleExpandCollapse(id,name){
  HideRow(id);
  var divs = document.getElementsByName(name);
  if( divs && divs.length > 0 ){
    for( i=0;i<divs.length;i++ ){

      if ( divs[i].style.display == "none" ){
        divs[i].style.display = "";
      }else{
        divs[i].style.display = "none"
      }
    }
  }
}


function Navi_Mainmenu_View(){
  var NavLink = document.form_main_change.m_id.options[document.form_main_change.m_id.selectedIndex].value;
  window.location='admin_submenu.asp?m_id=' + NavLink;
}


function Navi_EduDates_View(){
  var NavLink = document.form_edu_change.i_id.options[document.form_edu_change.i_id.selectedIndex].value;
  window.location='admin_classes_occ.asp?i_id=' + NavLink;
}


function Navi_SemDates_View(){
  var NavLink = document.form_edu_change.i_id.options[document.form_edu_change.i_id.selectedIndex].value;
  window.location='admin_seminars_occ.asp?i_id=' + NavLink;
}


function Navi_Infomenu_View1(){
  var NavLink = document.form_info_change.ism_id.options[document.form_info_change.ism_id.selectedIndex].value;
  window.location='admin_info_archive.asp?ism_id=' + NavLink;
}


function Navi_InfoPhoto_View(){
  var NavLink = document.form_photo_change.iip_id.options[document.form_photo_change.iip_id.selectedIndex].value;
  window.location='admin_infophoto.asp?iip_id=' + NavLink;
}


function Navi_GalleryPhoto_View(){
  var NavLink = document.form_photo_change.iip_id.options[document.form_photo_change.iip_id.selectedIndex].value;
  window.location='admin_images_view.asp?iip_id=' + NavLink;
}


function Navi_InfoFile_View(){
  var NavLink = document.form_file_change.iip_id.options[document.form_file_change.iip_id.selectedIndex].value;
  window.location='admin_infofile.asp?iip_id=' + NavLink;
}


function Navi_Gallery_View(){
  var NavLink = document.form_gallery_change.Photo_Cathegory.options[document.form_gallery_change.Photo_Cathegory.selectedIndex].value;
  window.location='http://www.thebinaryabode.com/?Photo_Cathegory=' + NavLink;
}


function Sel_New_Internlink(sFormTxt,sWebbrot){
  var NavLink = document.form_link_change.iit_id.options[document.form_link_change.iit_id.selectedIndex].value;
  window.opener.document.forms[sFormTxt].Info_Link.value=sWebbrot + NavLink;
  window.close();
}


function Sel_New_InternlinkNews(sFormTxt,sWebbrot){
  var NavLink = document.form_link_change.iit_id.options[document.form_link_change.iit_id.selectedIndex].value;
  window.opener.document.forms[sFormTxt].News_Link.value=sWebbrot + NavLink;
  window.close();
}


function Delete_Member(Nav_ID){
  if (confirm("Vill du radera medlemmen? Samtlig information kopplad till medlemmen kommer att raderas permanent.")){
    window.location ="admin_member_mod.asp?action=D&Member_id=" + Nav_ID;
  }
}


function Delete_Cathegory(Nav_ID){
  if (confirm("Vill du radera kategorin? Kategorin kommer att raderas permanent från systemet.")){
    window.location ="admin_cathegory_mod.asp?action=D&id=" + Nav_ID;
  }
}


function Delete_Mainmenu(Nav_ID){
  if (confirm("Vill du radera huvudmenyn? Samtliga submenyer och informationstexter kopplade till huvudmenyn kommer att raderas.")){
    window.location ="admin_mainmenu_mod.asp?action=D&id=" + Nav_ID;
  }
}


function Delete_Submenu(Nav_ID,I_ID){
  if (confirm("Vill du radera submenyn? Samtliga informationstexter kopplade till submenyn kommer att raderas.")){
    window.location ="admin_submenu_mod.asp?action=D&id=" + Nav_ID + "&m_id=" + I_ID;
  }
}


function Delete_Folders(Nav_ID){
  if (confirm("Vill du radera mappen? Samtliga submenyer/huvudmenyer kopplade till mappen kommer att raderas.")){
    window.location ="admin_folder_mod.asp?action=D&id=" + Nav_ID;
    //alert('Funktionen finns ej installerad just nu. Endast administratören har rättigheter att radera befintliga mappar.');
  }
}


function Delete_News(Nav_ID){
  if (confirm("Vill du radera nyheten? Samtliga flier och foton kopplade till nyheten kommer också att raderas.")){
    window.location ="admin_news_mod.asp?action=D&id=" + Nav_ID;
  }
}


function Delete_Edu(Nav_ID){
  if (confirm("Vill du radera utbildningen? Samtliga utbildningsdatum, filer och foton kopplade till utbildningen kommer att raderas.")){
    window.location ="admin_classes_mod.asp?action=D&id=" + Nav_ID;
  }
}


function Delete_EduOcc(Nav_ID,I_ID){
  if (confirm("Vill du radera utbildningsdatumet? Samtliga filer och foton kopplade till utbildningsdatumet kommer att raderas.")){
    window.location ="admin_classes_occ_mod.asp?action=D&id=" + Nav_ID + "&i_id=" + I_ID;
  }
}


function Delete_EduPhoto(Nav_ID,I_ID,U_ID){
  if (confirm("Vill du radera fotot? Fotot kommer att raderas permanent från systemet.")){
    window.location ="admin_classes_occ_photo_mod.asp?action=D&id=" + Nav_ID + "&link_id=" + I_ID + "&UTB_ID=" + U_ID;
  }
}


function Delete_Sem(Nav_ID){
  if (confirm("Vill du radera föreläsningen? Samtliga föreläsningsdatum, filer och foton kopplade till föreläsningen kommer att raderas.")){
    window.location ="admin_seminars_mod.asp?action=D&id=" + Nav_ID;
  }
}


function Delete_SemOcc(Nav_ID,I_ID){
  if (confirm("Vill du radera föreläsningsdatumet? Samtliga filer och foton kopplade till föreläsningsdatumet kommer att raderas.")){
    window.location ="admin_seminars_occ_mod.asp?action=D&id=" + Nav_ID + "&i_id=" + I_ID;
  }
}


function Delete_SemPhoto(Nav_ID,I_ID,U_ID){
  if (confirm("Vill du radera fotot? Fotot kommer att raderas permanent från systemet.")){
    window.location ="admin_seminars_occ_photo_mod.asp?action=D&id=" + Nav_ID + "&link_id=" + I_ID + "&UTB_ID=" + U_ID;
  }
}


function Delete_Conditions(Nav_ID){
  if (confirm("Vill du radera villkoret? Villkoret kommer att raderas permanent från systemet.")){
    window.location ="admin_conditions_mod.asp?action=D&id=" + Nav_ID;
  }
}


function Delete_EmailConf(Nav_ID){
  if (confirm("Vill du radera bekräftelsen? Bekräftelsen kommer att raderas permanent från systemet.")){
    window.location ="admin_emailconf_mod.asp?action=D&id=" + Nav_ID;
  }
}


function Delete_InfoText1(Nav_ID,I_ID,II_ID,III_ID){
  if (confirm("Vill du radera informationstexten? Informationstexten kommer att raderas permanent från systemet.")){
    window.location ="admin_info_archive_mod.asp?action=D&id=" + Nav_ID + "&ism_id=" + I_ID + "&i_listid=" + II_ID + "&i_id=" + III_ID;
  }
}


function Delete_InfoText2(Nav_ID,FlexID){
  if (confirm("Vill du radera informationstexten? Samtliga flier och foton kopplade till informationstexten kommer också att raderas.")){
    window.location ="admin_indexpage_mod.asp?action=D&id=" + Nav_ID + "&Info_MainmenuID=" + FlexID;
  }
}


function Delete_InfoPhoto(Nav_ID,I_ID,Info_ID){
  if (confirm("Vill du radera fotot? Fotot kommer att raderas permanent från systemet.")){
    window.location ="admin_infophoto_mod.asp?action=D&id=" + Nav_ID + "&iip_id=" + I_ID + "&InfoPhotos_InfoID=" + Info_ID;
  }
}


function Delete_GalleryPhoto(Nav_ID,I_ID,Info_ID){
  if (confirm("Vill du radera fotot? Fotot kommer att raderas permanent från systemet.")){
    window.location ="admin_images_mod.asp?action=D&id=" + Nav_ID + "&iip_id=" + I_ID + "&InfoPhotos_InfoID=" + Info_ID;
  }
}


function Delete_InfoFile(Nav_ID,I_ID,Info_ID){
  if (confirm("Vill du radera filen? Filen kommer att raderas permanent från systemet.")){
    window.location ="admin_infofile_mod.asp?action=D&id=" + Nav_ID + "&iip_id=" + I_ID + "&InfoFiles_InfoID=" + Info_ID;
  }
}


function Delete_Newsletter(Nav_ID){
  if (confirm("Vill du radera nyhetsbrevet? Informationen kommer att raderas permanent från systemet.")){
    window.location ="admin_newsletter_write_mod.asp?action=D&id=" + Nav_ID;
  }
}


function view_InfoPhoto(Photo_ID,sPhotoWidth,sPhotoHeight){
  //var sPhotoWidth_red = sPhotoWidth + 10;
  //var sPhotoHeight_red = sPhotoHeight + 10;
  var sPhotoWidth_red = 500;
  var sPhotoHeight_red = 500;
  NewWindow("info_photo.asp?id=" + Photo_ID,"infophoto",sPhotoWidth_red,sPhotoHeight_red,"yes","yes");
}


function get_latestFlash_confirm(){
  if (confirm("Vill du hämta den senaste versionen av Flash Player? En del innehåll på webbplatsen kräver att du uppdaterar din plugin.")){
    window.location ="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
  }
}


function ChkComment() {
  var error = "";

  if (document.formcomment.sMeddelande.value=="" && error=="") {
    error="Du måste skriva en kommentar!";
    document.formcomment.sMeddelande.focus();
  }else {
    if (document.formcomment.sMeddelande.value=="Din kommentar här" && error=="") {
      error="Du måste skriva en kommentar!";
      document.formcomment.sMeddelande.focus();
    }
  }

  if (error==""){
    document.formcomment.submit();
  }else{
    alert(error);
  }
}


function ChkNews() {
  var error = "";

  if (document.formnews.sEmailNyhet.value=="" && error=="") {
    error="Du måste ange din emailadress!";
    document.formnews.sEmailNyhet.focus();
  }

  if (document.formnews.sEmailNyhet.value!="" && error=="") {
    var myEMailIsValid = true;
    var checkThisEmail = document.formnews.sEmailNyhet.value;
    var myAtSymbolAt = checkThisEmail.indexOf('@');
    var myLastDotAt = checkThisEmail.lastIndexOf('.');
    var mySpaceAt = checkThisEmail.indexOf(' ');
    var myLength = checkThisEmail.length;
    
    if (myAtSymbolAt < 1 ) {
      myEMailIsValid = false
    }

    if (myLastDotAt < myAtSymbolAt) {
      myEMailIsValid = false
    }

    if (myLength - myLastDotAt <= 2) {
      myEMailIsValid = false
    }

    if (mySpaceAt != -1) {
      myEMailIsValid = false
    }

    if (myEMailIsValid != true) {
      error="Du har angivit en ogiltig emailadress!";
      document.formnews.sEmailNyhet.focus();
    }
  }
  
  if (error==""){
    document.formnews.submit();
  }else{
    alert(error);
  }
}


function chkLoginRequst(){
  var error = "";

  if (document.formlogin_req.emailrequest.value=="" && error=="") {
    error = "Du måste uppge din epostadress";
    document.formlogin_req.emailrequest.focus();
  }

  if (document.formlogin_req.emailrequest.value!="" && error=="") {
    var myEMailIsValid = true;
    var checkThisEmail = document.formlogin_req.emailrequest.value;
    var myAtSymbolAt = checkThisEmail.indexOf('@');
    var myLastDotAt = checkThisEmail.lastIndexOf('.');
    var mySpaceAt = checkThisEmail.indexOf(' ');
    var myLength = checkThisEmail.length;
    
    if (myAtSymbolAt < 1 ) {
      myEMailIsValid = false
    }

    if (myLastDotAt < myAtSymbolAt) {
      myEMailIsValid = false
    }

    if (myLength - myLastDotAt <= 2) {
      myEMailIsValid = false
    }

    if (mySpaceAt != -1) {
      myEMailIsValid = false
    }

    if (myEMailIsValid != true) {
      error="Du har uppgett en ogiltig epostadress";
      document.formlogin_req.emailrequest.focus();
    }
  }

  if (error==""){
    document.formlogin_req.submit();
  }else{
    alert(error);
  }
}


function protect_epost(name, address, ending, display){
  var link = name + "@" + address
  if(!display) { display = link; }
    document.write("<a class='menuright' href='mailto:" + link + "." + ending + "'>" + display + "</a>");
}
