var OnDisplay = null;
var LayerYPos = 10;
var adsHeight = 0;

function armenica(Module,Part,Tag){
   userID = GetCookie('Armenica.org',0);
   var url;

   if ((Module == 1) || (Module == 51)){
     url = 'http://www.armenica.org/cgi-bin/armenica.cgi?' + userID + '=' + Module + '=' + Part + '==' + Tag;
   }
   else{
     var cat = Tag.substr(0,2);
     
     url = 'http://www.armenica.org/cgi-bin/armenica.cgi?' + userID + '=' + Module + '=' + cat + '=' + Part + '====' + Tag;
   }

   window.location.href = url;
}

var mainCookie = "initCookie1234567890"; 

function GetCookie(name,cookieFlag) { 
  var cookiecontent = 'initCookie1234567890'; 
 
  if(document.cookie.length > 0) {
     var cookiename = name + '='; 
     var cookiebegin = document.cookie.indexOf(cookiename); 
     var cookieend = 0; 
 
     if(cookiebegin > -1) { 
        cookiebegin += cookiename.length; 
        cookieend = document.cookie.indexOf(";", cookiebegin); 
               
  
        if(cookieend < cookiebegin){ 
           cookieend = document.cookie.length; 
        }

        cookiecontent = document.cookie.substring(cookiebegin,cookieend);
        cookiecontent = unescape(cookiecontent); 
     } 
     else{ 
        if (cookieFlag){
          cookiecontent = cookieFlag;
        }
        else{
          cookiecontent = getRandomId(1000000000000000);
        }
     } 
   } 
   else{
     if (cookieFlag){
       cookiecontent = cookieFlag;
     }
     else{
       cookiecontent = getRandomId(1000000000000000); 
     }
   } 
   
   var value = parseInt(cookiecontent); 
   
   PutCookie(name,value);

   return value; 
} 

function PutCookie(n,v) { 
   document.cookie = n + "=" + v; 
} 

function getRandomId(indata){ 
  return Math.floor(Math.random() * indata) + 1; 
} 

function Show(LayerId,Language,Name){  

  userId = GetCookie('Armenica.org');
  var module;

  if (Language == 1){
    if ((LayerId == "videoDiv") || (LayerId == "CollVideoDiv")){ 
      module = 4;
    }
    else{
      module = 3;
    }
  }
  else{
    if ((LayerId == "videoDiv") || (LayerId == "CollVideoDiv")){ 
      module = 54;
    }
    else{
      module = 53;
    }
  }

  if (LayerId == "mapDiv"){
    top.frames[0].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?" + userId + "=" + module + "=0=" + Name;  
  }  
  else if (LayerId == "personDiv"){    
    top.frames[1].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?" + userId + "=" + module + "=1=" + Name;  
  }
  else if (LayerId == "infoDiv"){    
    top.frames[2].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?" + userId + "=" + module + "=2=" + Name;  
  } 
  else if (LayerId == "crossDiv"){    
    top.frames[3].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?" + userId + "=" + module + "=3=" + Name;  
  }
  else if (LayerId == "videoDiv"){
    top.frames[0].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?" + userId + "=" + module + "=0=" + Name + "=" + 1;
  }
  else if (LayerId == "CollVideoDiv"){
    top.frames[1].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?" + userId + "=" + module + "=1=" + Name + "=" + 1;
  }  
  else if (LayerId == "collectionDiv"){
    top.frames[0].location.href = "http://www.armenica.org/cgi-bin/history/en/getCollectionObject.cgi?" + Name;
  }
  else if (LayerId == "fullTextEng"){
  }
  else if (LayerId == "fullTextSwe"){
  }
  

  //alert("LayerId = " + LayerId);	
  if (document.getElementById){
    if (OnDisplay != null)
      OnDisplay.style.visibility = 'hidden';	      
      OnDisplay = top.document.getElementById(LayerId);		
    if (navigator.userAgent.indexOf ('Gecko') == -1 || navigator.userAgent.indexOf ('Opera') == -1) // Alla utom Mozilla/Ns6 och Opera			
      OnDisplay.style.top = (LayerYPos + top.document.body.scrollTop) + "px";		
    else // Mozilla/Ns6 och Opera			
      OnDisplay.style.top = (LayerYPos + pageYOffset) + "px";
      OnDisplay.style.visibility = 'visible';	
   }	
   else if (document.all){
      if (OnDisplay != null){	    
        OnDisplay.style.visibility = 'hidden';	    
        OnDisplay = top.frames[0].document.all[LayerId];	    
        top.document.all[LayerId].style.visibility = 'visible';	  
      }	
   }	
   else if (document.layers){
      if (OnDisplay != null){	    
        OnDisplay.visibility = 'hide';	    
        OnDisplay = eval ("document." + LayerId);	    
        OnDisplay.visibility = 'show';	    
        OnDisplay.top = LayerYPos + pageYOffset;	  
      }	
   }
}

function Hide (LayerId){   
  if (document.getElementById){    
    top.document.getElementById(LayerId).style.visibility = 'hidden';  
  }  
  else if (document.all){    
    top.document.all[LayerId].style.visibility = 'hidden';  
  }  
  else if (document.layers){    
    eval("top.document." + LayerId + ".visibility = 'hide'");  
  }

  if (LayerId == "mapDiv"){
    top.frames[0].location.href = "http://www.armenica.org/history/blank.html";  
  }  
  else if (LayerId == "personDiv"){    
    top.frames[1].location.href = "http://www.armenica.org/history/blank.html";  
  }  
  else if (LayerId == "infoDiv"){    
    top.frames[2].location.href = "http://www.armenica.org/history/blank.html";  
  }  
  else if (LayerId == "crossDiv"){    
    top.frames[3].location.href = "http://www.armenica.org/history/blank.html";  
  }
  else if (LayerId == "videoDiv"){    
    top.frames[0].location.href = "http://www.armenica.org/history/blank.html";  
  }
  else if (LayerId == "CollVideoDiv"){
    top.frames[1].location.href = "http://www.armenica.org/history/blank.html";
  }  
  else if (LayerId == "collectionDiv"){    
    top.frames[0].location.href = "http://www.armenica.org/history/blank.html";  
  }
}

function preCheck(){
  var allOk = true;
  var text = "";
  data = new Array(4);
  var version = document.contact.version.value;

  if (version == 1){
    if (document.contact.fname.value.length < 2){
      data[0] = "First name";
      allOk = false;
    }

    if (document.contact.lname.value.length < 3){
      data[1] = "Last name"; 
      allOk = false;
    }

    if ((document.contact.email.value.length < 6) || (document.contact.email.value.search("@") == -1)){
      data[2] = "Email";
      allOk = false;
    }

    if ((document.contact.type.value != 4) && (document.contact.message.value.length < 10)){
      data[3] = "Message";
      allOk = false;
    }
  }
  else{
    if (document.contact.fname.value.length < 2){
      data[0] = "Namn";
      allOk = false;
    }

    if (document.contact.lname.value.length < 3){
      data[1] = "Efternamn"; 
      allOk = false;
    }

    if ((document.contact.email.value.length < 6) || (document.contact.email.value.search("@") == -1)){
      data[2] = "Email";
      allOk = false;
    }

    if ((document.contact.type.value != 4) && (document.contact.message.value.length < 10)){
      data[3] = "Meddelande";
      allOk = false;
    } 
  }


  if (allOk){
     return true;
  }
  else{  
     if (version == 1){  
       text += "Please complete the following information:\n\n";
     }
     else{
       text += "Vänligen kompleetera följande information:\n\n";  
     }

     for (i=0; i < 4; i++){
       if (data[i]){
        text += "* ";
        text += data[i];
        text += "\n";
       }
     }

    alert(text);
    return false;
  }
}

function iFrameHeight() {

  if(document.getElementById && !(document.all)) {
    
    h = document.body.scrollHeight - 185;

    if (h < top.adsHeight){
      h = top.adsHeight;
    }

    //alert (document.body.scrollHeight + " => " + h);
    
    if (document.getElementById('main')){
      document.getElementById('main').height = h;
    }

    if (document.getElementById('lMenu')){
      document.getElementById('lMenu').height = h;
    }
    
    if (document.getElementById('ads')){
      document.getElementById('ads').height = h;
    }


  }
  else if(document.all) {
    
    h = document.body.clientHeight - 185;
    
    if (h < top.adsHeight){
      h = top.adsHeight;
    }

    if (document.all.main){
      document.all.main.height = h;
    }

    //    alert(document.body.clientHeight + " => " + h);

    if (document.all.lMenu){
      document.all.lMenu.height = h;
    }
    
    if (document.all.ads){
      document.all.ads.height = h;
    }
    
  }
}


function ShowDiv(LayerId){  
  //alert("LayerId = " + LayerId);	
  if (document.getElementById){
    if (OnDisplay != null)
      OnDisplay.style.visibility = 'hidden';	      
      OnDisplay = top.document.getElementById(LayerId);		
    if (navigator.userAgent.indexOf ('Gecko') == -1 || navigator.userAgent.indexOf ('Opera') == -1) // Alla utom Mozilla/Ns6 och Opera			
      OnDisplay.style.top = (LayerYPos + top.document.body.scrollTop) + "px";		
    else // Mozilla/Ns6 och Opera			
      OnDisplay.style.top = (LayerYPos + pageYOffset) + "px";
      OnDisplay.style.visibility = 'visible';	
   }	
   else if (document.all){
      if (OnDisplay != null){	    
        OnDisplay.style.visibility = 'hidden';	    
        OnDisplay = top.frames[0].document.all[LayerId];	    
        top.document.all[LayerId].style.visibility = 'visible';	  
      }	
   }	
   else if (document.layers){
      if (OnDisplay != null){	    
        OnDisplay.visibility = 'hide';	    
        OnDisplay = eval ("document." + LayerId);	    
        OnDisplay.visibility = 'show';	    
        OnDisplay.top = LayerYPos + pageYOffset;	  
      }	
   }
}


function showMap(map,language){
   if (language == 1){
     top.frames[0].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?=3=7=" + map;
   }
   else{
     top.frames[0].location.href = "http://www.armenica.org/cgi-bin/armenica.cgi?=53=7=" + map;
  }

   LayerId = 'mapDiv';

 //alert("LayerId = " + LayerId);	
  if (document.getElementById){
    if (OnDisplay != null)
      OnDisplay.style.visibility = 'hidden';	      
      OnDisplay = top.document.getElementById(LayerId);		
    if (navigator.userAgent.indexOf ('Gecko') == -1 || navigator.userAgent.indexOf ('Opera') == -1) // Alla utom Mozilla/Ns6 och Opera			
      OnDisplay.style.top = (LayerYPos + top.document.body.scrollTop) + "px";		
    else // Mozilla/Ns6 och Opera			
      OnDisplay.style.top = (LayerYPos + pageYOffset) + "px";
      OnDisplay.style.visibility = 'visible';	
   }	
   else if (document.all){
      if (OnDisplay != null){	    
        OnDisplay.style.visibility = 'hidden';	    
        OnDisplay = top.frames[0].document.all[LayerId];	    
        top.document.all[LayerId].style.visibility = 'visible';	  
      }	
   }	
   else if (document.layers){
      if (OnDisplay != null){	    
        OnDisplay.visibility = 'hide';	    
        OnDisplay = eval ("document." + LayerId);	    
        OnDisplay.visibility = 'show';	    
        OnDisplay.top = LayerYPos + pageYOffset;	  
      }	
   }
}




function videoClip(clipNr,language){

var randNr = Math.floor((16)*Math.random());

var video = new Array();
var item;

video[0]="Tegher Monastery|Tegher klostret|HHB23VUW3rY|wGEc1SWZ-BQ";
video[1]="Hayravank Monastery|Hayravank klostret|8ianBnxRrfA|XLcSiRAiuvU";
video[2]="Arshakouni Royal Mausoleum|Arshakouniska kungliga maoseleum|YtrllQw8dTk";
video[3]="Lecture by Prof. Dadrian|Föreläsning av prof. Dadrian|pudMMIhdpLE|bQ6KCaPjkn8|VgEDdNSOzi8|DlRKgEIqVb4|aGTu50LpRtE|tMRq2_zn8jk|74qg6B9KMgk|WOXlaBjokJg|dbRIvuRobmM";
video[4]="Talin Cathedral|Talins katedral|HxRETnzSul8|FFbSoFQnYik";
video[5]="Noravank Monastery|Noravanks kloster|7muY_i38XaA|TAsQxMYYy-8|gBQBLG25d2Y|11J58ogERr0";
video[6]="St John Church|S:t Johannes döparens kyrka|u7LW2gV5mOg";
video[7]="Areni|Areni|gbcl_AqIyIA";
video[8]="Haghpat Monastery|Haghpats kloster|rCHQhryS0Qg|gb_KIrQKPdg";
video[9]="Aruchavank|Aruchavank|NZavwsJUrNQ";
video[10]="Kosh Fortress|Kosh fästning|c7v8wl_hAmw";
video[11]="Destruction of the Armenian Cemetery, Nakhichevan|Förstörelsen av armeniska kyrkogården i Nakhichevan|1YLcHq2xyAs|3Uhb6fSQXc4|iHuJ25c27gQ";
video[12]="Declaration of Independence|Självständighetsförklaringen|RWzq0HeCe3E";
video[13]="Poem Herosakan|Poem Herosakan|A4gZHoTnBZE";
video[14]="Interview with Prof. T. Akcam|Intervju med prof. T. Akcam 1/5|4mWkzL91WPg|rR3vu2b1zCw|fulbgH9rs8M|oafahwQZNIY|ZFOSXcijoRc";
video[15]="Garni Temple|Garni tempel|scaoSkmMdbE";

if (clipNr == 1234567890){
  item = video[randNr];
}
else{
  item = video[clipNr];
}

values = item.split("|");

videoTextEng = values[0];
videoTextSwe = values[1];

var videoText = "";

if (language == 1){
 videoText = videoTextEng;
}
else{
 videoText = videoTextSwe;
}

window.document.open();

itemsInList = values.length - 2;
i=0;
while (i<itemsInList)
{
//alert("rand: " + randNr + " /  Len: " + values.length + " " + values + " == " + i + " =>" + values[i+2]);

document.write("<div class=\"contentdiv\">\n");
window.document.write("<object width=\"255\" height=\"214\"><param name=\"movie\" value=\"http://www.youtube.com/v/");

window.document.write(values[i+2]);

window.document.write("&hl=sv&fs=1&color1=0xe1600f&color2=0xfebd01\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/");

window.document.write(values[i+2]);

window.document.write("&hl=sv&fs=1&color1=0xe1600f&color2=0xfebd01\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"255\" height=\"214\"></embed></object>\n");

window.document.write("<br><font style=\"font-size:10px; font-family: verdana, arial, helvetica, sans-serif\">" + videoText + "</font>");

window.document.write("</div>");

i++;
}
window.document.close();

}
