/* Author: nikola dot rasic at gulagsoft dot com
 * License: Do what ever You want with it.
 * Disclaimer: Absolutly no warrenty what so ever!
 * Does: Set for debugging purpos.
 */
/* function errorHandling() {return true;}
  window.onerror = errorHandling; */
/* Author: nikola dot rasic at gulagsoft dot com
 * License: Do what ever You want with it.
 * Disclaimer: Absolutly no warrenty what so ever!
 * Does: Preloads images.
 */
function mediaPreloader(obj) {
  var doc = document;
  var str = "";

  if(doc.images && getObj('left') && getObj('right')) {
    for(i = 0; i < obj.length; i++) {
      str += ":" + i;
    }
    alert(str);
  }
}

function swapMedia() {

}

function preloadImages() { //v3.0
  var d=document; 
  if(d.images) { 
    if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
      for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0) { 
          d.MM_p[j]=new Image; 
          d.MM_p[j++].src=a[i];
        }
  }
}


function popUpImage(image, alt_text){
  var height = 500;
  var width = 500;
  var mywin;
  if(window.child == null){
  	mywin = window.open(''+self.location,'','height='+height+',width='+width+',menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,directories=0,left='+((screen.width/2)-(width/3))+',top='+((screen.height/2)-(height/2))+'');
    mywin.document.write('<HTML><HEAD><TITLE>www.spermabanken.se</TITLE></HEAD><BODY bgcolor="#FFFFFF" topmargin=6 leftmargin=0 marginwidth=0 marginheight=6>');
    mywin.document.write('<CENTER><IMG name="img_prp" src="images/'+image+'" border="0" alt="'+alt_text+'"></CENTER>');
    mywin.document.write('<CENTER><A href="Javascript:this.close();" style="font-size:14px; color:#CC0033;text-decoration:none;">STÄNG</A></CENTER>');
    mywin.document.write('</BODY></HTML>');
  	mywin.document.close();
    resizeOuterTo(mywin,(mywin.document.images[0].width + 20),(mywin.document.images[0].height + 100));
    mywin.focus();
  } else {
    alert('huh?');
  }
}

function popUpWindow(_url, _width, _height) {
  var mywin;
  if(window.child == null){
  	mywin = window.open(_url,'',"height="+_height+",width="+_width+",menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,left="+((screen.width/2)-(_width/3))+",top="+((screen.height/2)-(_height/2))+" ");
    resizeOuterTo(mywin,_width,_height);
    mywin.focus();
  }
}

function resizeOuterTo(obj,w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    obj.outerWidth=w;
    obj.outerHeight=h;
   }
   else obj.resizeTo(w,h);
 }
}


/* Author: nikola dot rasic at gulagsoft dot com
 * License: Do what ever You want with it.
 * Disclaimer: Absolutly no warrenty what so ever!
 * Does: Gets parent/element nodes/names.
 */

function getParentNode(obj) {
  
  return obj.parentNode;
}

function getParentName(obj) {
  
  return getParentNode(obj).name;
}

function getElementNode(obj) {
  
}

function getElementName(obj) {
  
}


/* Author: nikola dot rasic at gulagsoft dot com
 * License: Do what ever You want with it.
 * Disclaimer: Absolutly no warrenty what so ever!
 * Does: Retrives a DOM object regardless of browser.
 */
function getObj(name) {

  var obj = new Object();
  
  if (document.getElementById) {
    obj = document.getElementById(name);
  }
  else if (document.all) {
    obj = document.all[name];
  }
  else if (document.layers) {
    obj = document.layers[name];
  }
  return obj;
}

/* Author: nikola dot rasic at gulagsoft dot com
 * License: Do what ever You want with it.
 * Disclaimer: Absolutly no warrenty what so ever!
 * Does: Creates a object that can slide across the 
 *       browser in any direction. Object must be a 
 *       <DIV> with an Id, ex. <DIV id="foo" 
 *       style="position:relative | absolute;"></DIV>.
 */
function Slider(obId, name) {
  
  var timerID     = null;
  var t_delay     = 20;
  var obj         = getObj(obId);
  
  /* Slides the object to the left to destination, dest. */
  this.slideLeft = function(dest) {
    clearTimeout(timerID);
    d = parseInt(obj.style.left) - dest;
    if(parseInt(obj.style.left) > dest) {
      obj.style.left = parseInt(obj.style.left) - (d/10 + 1) + "px";
      timerID = setTimeout(name+".slideLeft("+dest+")", t_delay);
    } else {
      clearTimeout(timerID);
    }
  }
  /* Slides the object to the right to destination, dest. */
  this.slideRight = function(dest) {
    clearTimeout(timerID);
    d = dest - parseInt(obj.style.left);
    if(parseInt(obj.style.left) < dest) {
      obj.style.left = parseInt(obj.style.left) + (d/10 + 1) + "px";
      timerID = setTimeout(name+".slideRight("+dest+")", t_delay);
    } else {
      clearTimeout(timerID);
    }
  }
  /* Slides the object upwards to destination, dest. */
  this.slideUp = function(dest) {
    clearTimeout(timerID);
    d = parseInt(obj.style.top) - dest;
    if(parseInt(obj.style.top) > dest) {
      obj.style.top = parseInt(obj.style.top) - (d/10 + 1) + "px";
      timerID = setTimeout(name+".slideUp("+dest+")", t_delay);
    } else {
      clearTimeout(timerID);
    }
  }
  /* Slides the object downwards to destination, dest. */
  this.slideDown = function(dest) {
    clearTimeout(timerID);
    d = dest - parseInt(obj.style.top);
    if(parseInt(obj.style.top) < dest) {
      obj.style.top = parseInt(obj.style.top) + (d/10 + 1) + "px";
      timerID = setTimeout(name+".slideDown("+dest+")", t_delay);
    } else {
      clearTimeout(timerID);
    }
  }
}

/* Author: nikola dot rasic at gulagsoft dot com
 * License: Do what ever You want with it.
 * Disclaimer: Absolutly no warrenty what so ever!
 * Does: Manipulates layer visibility.
 */
function Hider(obId) {

  var obj = getObj(obId);

  this.hideLayer = function() {
    obj.style.visibility = "hidden";
  }

  this.showLayer = function() {
    obj.style.visibility = "visible";
  }
  
  this.flipVisibility = function() {
    if(obj.style.visibility == "hidden") { 
      this.showLayer();
    } else {
      this.hideLayer();
    }
  }
}

/* Author: nikola dot rasic at gulagsoft dot com
 * License: Do what ever You want with it.
 * Disclaimer: Absolutly no warrenty what so ever!
 * Does: Populates a select-tag like: 
 * <SELECT><SCRIPT...>getCountryOptions('Kazakhstan', this);</SCRIPT></SELECT>.
 * The argument is the selected country for convinience.
 * Add this just before </BODY> to select Kazakhstan
 * <SCRIPT type="text/javascript">document.forms['foo'].reset();</SCRIPT>
 * 
 */
function getCountryOptions(sel) {

  var country = ['Afghanistan'
  , 'Akrotiri'
  , 'Albania'
  , 'Algeria'
  , 'American Samoa'
  , 'Andorra'
  , 'Angola'
  , 'Anguilla'
  , 'Antarctica'
  , 'Antigua and Barbuda'
  , 'Arctic Ocean'
  , 'Argentina'
  , 'Armenia'
  , 'Aruba'
  , 'Ashmore and Cartier Islands'
  , 'Atlantic Ocean'
  , 'Australia'
  , 'Austria'
  , 'Azerbaijan'
  , 'Bahamas, The'
  , 'Bahrain'
  , 'Baker Island'
  , 'Bangladesh'
  , 'Barbados'
  , 'Bassas da India'
  , 'Belarus'
  , 'Belgium'
  , 'Belize'
  , 'Benin'
  , 'Bermuda'
  , 'Bhutan'
  , 'Bolivia'
  , 'Bosnia and Herzegovina'
  , 'Botswana'
  , 'Bouvet Island'
  , 'Brazil'
  , 'British Indian Ocean Territory'
  , 'British Virgin Islands'
  , 'Brunei'
  , 'Bulgaria'
  , 'Burkina Faso'
  , 'Burma'
  , 'Burundi'
  , 'Cambodia'
  , 'Cameroon'
  , 'Canada'
  , 'Cape Verde'
  , 'Cayman Islands'
  , 'Central African Republic'
  , 'Chad'
  , 'Chile'
  , 'China'
  , 'Christmas Island'
  , 'Clipperton Island'
  , 'Cocos (Keeling) Islands'
  , 'Colombia'
  , 'Comoros'
  , 'Congo, Democratic Republic of the'
  , 'Congo, Republic of the'
  , 'Cook Islands'
  , 'Coral Sea Islands'
  , 'Costa Rica'
  , 'Cote d Ivoire'
  , 'Croatia'
  , 'Cuba'
  , 'Cyprus'
  , 'Czech Republic'
  , 'Danmark'
  , 'Dhekelia'
  , 'Djibouti'
  , 'Dominica'
  , 'Dominican Republic'
  , 'East Timor'
  , 'Ecuador'
  , 'Egypt'
  , 'El Salvador'
  , 'Equatorial Guinea'
  , 'Eritrea'
  , 'Estonia'
  , 'Ethiopia'
  , 'Europa Island'
  , 'Falkland Islands (Islas Malvinas)'
  , 'Faroe Islands'
  , 'Fiji'
  , 'Finland'
  , 'France'
  , 'French Guiana'
  , 'French Polynesia'
  , 'French Southern and Antarctic Lands'
  , 'Gabon'
  , 'Gambia, The'
  , 'Gaza Strip'
  , 'Georgia'
  , 'Germany'
  , 'Ghana'
  , 'Gibraltar'
  , 'Glorioso Islands'
  , 'Greece'
  , 'Greenland'
  , 'Grenada'
  , 'Guadeloupe'
  , 'Guam'
  , 'Guatemala'
  , 'Guernsey'
  , 'Guinea'
  , 'Guinea-Bissau'
  , 'Guyana'
  , 'Haiti'
  , 'Heard Island and McDonald Islands'
  , 'Holy See (Vatican City)'
  , 'Honduras'
  , 'Hong Kong'
  , 'Howland Island'
  , 'Hungary'
  , 'Iceland'
  , 'India'
  , 'Indian Ocean'
  , 'Indonesia'
  , 'Iran'
  , 'Iraq'
  , 'Ireland'
  , 'Israel'
  , 'Italy'
  , 'Jamaica'
  , 'Jan Mayen'
  , 'Japan'
  , 'Jarvis Island'
  , 'Jersey'
  , 'Johnston Atoll'
  , 'Jordan'
  , 'Juan de Nova Island'
  , 'Kazakhstan'
  , 'Kenya'
  , 'Kingman Reef'
  , 'Kiribati'
  , 'Korea, North'
  , 'Korea, South'
  , 'Kuwait'
  , 'Kyrgyzstan'
  , 'Laos'
  , 'Latvia'
  , 'Lebanon'
  , 'Lesotho'
  , 'Liberia'
  , 'Libya'
  , 'Liechtenstein'
  , 'Lithuania'
  , 'Luxembourg'
  , 'Macau'
  , 'Macedonia'
  , 'Madagascar'
  , 'Malawi'
  , 'Malaysia'
  , 'Maldives'
  , 'Mali'
  , 'Malta'
  , 'Man, Isle of'
  , 'Marshall Islands'
  , 'Martinique'
  , 'Mauritania'
  , 'Mauritius'
  , 'Mayotte'
  , 'Mexico'
  , 'Micronesia, Federated States of'
  , 'Midway Islands'
  , 'Moldova'
  , 'Monaco'
  , 'Mongolia'
  , 'Montenegro'
  , 'Montserrat'
  , 'Morocco'
  , 'Mozambique'
  , 'Namibia'
  , 'Nauru'
  , 'Navassa Island'
  , 'Nepal'
  , 'Netherlands'
  , 'Netherlands Antilles'
  , 'New Caledonia'
  , 'New Zealand'
  , 'Nicaragua'
  , 'Niger'
  , 'Nigeria'
  , 'Niue'
  , 'Norfolk Island'
  , 'Northern Mariana Islands'
  , 'Norge'
  , 'Oman'
  , 'Pacific Ocean'
  , 'Pakistan'
  , 'Palau'
  , 'Palmyra Atoll'
  , 'Panama'
  , 'Papua New Guinea'
  , 'Paracel Islands'
  , 'Paraguay'
  , 'Peru'
  , 'Philippines'
  , 'Pitcairn Islands'
  , 'Poland'
  , 'Portugal'
  , 'Puerto Rico'
  , 'Qatar'
  , 'Reunion'
  , 'Romania'
  , 'Russia'
  , 'Rwanda'
  , 'Saint Helena'
  , 'Saint Kitts and Nevis'
  , 'Saint Lucia'
  , 'Saint Pierre and Miquelon'
  , 'Saint Vincent and the Grenadines'
  , 'Samoa'
  , 'San Marino'
  , 'Sao Tome and Principe'
  , 'Saudi Arabia'
  , 'Senegal'
  , 'Serbia'
  , 'Seychelles'
  , 'Sierra Leone'
  , 'Singapore'
  , 'Slovakia'
  , 'Slovenia'
  , 'Solomon Islands'
  , 'Somalia'
  , 'South Africa'
  , 'South Georgia and the South Sandwich Islands'
  , 'Southern Ocean'
  , 'Spain'
  , 'Spratly Islands'
  , 'Sri Lanka'
  , 'Sudan'
  , 'Suriname'
  , 'Svalbard'
  , 'Swaziland'
  , 'Sverige'
  , 'Switzerland'
  , 'Syria'
  , 'Tajikistan'
  , 'Tanzania'
  , 'Thailand'
  , 'Togo'
  , 'Tokelau'
  , 'Tonga'
  , 'Trinidad and Tobago'
  , 'Tromelin Island'
  , 'Tunisia'
  , 'Turkey'
  , 'Turkmenistan'
  , 'Turks and Caicos Islands'
  , 'Tuvalu'
  , 'Uganda'
  , 'Ukraine'
  , 'United Arab Emirates'
  , 'United Kingdom'
  , 'United States of America'
  , 'United States Pacific Island Wildlife Refuges'				
  , 'Uruguay'
  , 'Uzbekistan'
  , 'Vanuatu'
  , 'Venezuela'
  , 'Vietnam'
  , 'Virgin Islands'
  , 'Wake Island'
  , 'Wallis and Futuna'
  , 'West Bank'
  , 'Western Sahara'
  , 'Yemen'
  , 'Zambia'
  , 'Zimbabwe'
  , 'Taiwan'];
  
  for(i = 0; i < country.length; i++) {
    if(country[i] === sel) {
      document.write('<OPTION SELECTED>' + country[i] + '</OPTION>\n');
    } else {
      document.write('<OPTION>' + country[i] + '</OPTION>\n');
    }
  }
}
