var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;
var isNS6    = (navigator.appName.indexOf("Netscape") >=0 && parseFloat(navigator.appVersion) >= 5) ? 1 : 0;

//cookies
var max_cookies = 20; // no more than 20 cookies per server allowed
var cookie_name = new Array(max_cookies);

function get_cookie( Name ) {
        var search = Name + "=";
        if( document.cookie.length > 0 ) { // if there are any cookies
                offset = document.cookie.indexOf( search );
                if( offset != -1 ) { // if cookie exists 
                        offset += search.length;
                        // set index of beginning of value
                        end = document.cookie.indexOf(";", offset);
                        // set index of end of cookie value
                        if( end == -1 ) {
                                end = document.cookie.length;
                        }
                        return unescape( document.cookie.substring( offset, end ));
                }
        } else {
                return false;
        }
}

function set_cookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function get_all_cookies() {
        var cookie_jar = document.cookie;
        var my_cookies = cookie_jar.split(';');
        var crumbs;

        for( var x = 0; x < my_cookies.length; x++ ) {
                crumbs = my_cookies[x].split('=');
                if( crumbs[0] != "" ) {
                        cookie_name[x] = crumbs[0];
                }
        }
        return cookie_name.join(',');
}

function expiration(days) {
        var expires = new Date();
        var today = new Date();
        expires.setTime( today.getTime() + (1000*60*60*24*parseInt(days)) );
        return expires;
}

//cookies

var www;

function open_win_scrl(url, width, height) {
  if(www) www.close();
  if(document.all)
    www = window.open(url,'','width='+width+',height='+height+',toolbar=0,scrollbars=1,resizable=0,menubar=0,status=0,directories=0,location=0,left='+(screen.width-width)/2+',top=0')
  else   
    www = window.open(url,'','width='+width+',height='+height+',toolbar=0,scrollbars=1,resizable=0,menubar=0,status=0,directories=0,location=0,screenX='+(screen.width-width)/2+',screenY=0');
  www.focus();
}

function open_win(url, width, height) {
  var ifscroll = 0;
  if(www) www.close();
  if(document.all)
    www = window.open(url,'','width='+width+',height='+height+',toolbar=0,scrollbars='+ifscroll+',resizable=0,menubar=0,status=0,directories=0,location=0,left='+Math.ceil((screen.width-width)/2)+',top='+Math.ceil((screen.height-height)/2))
  else   
    www = window.open(url,'','width='+width+',height='+height+',toolbar=0,scrollbars='+ifscroll+',resizable=0,menubar=0,status=0,directories=0,location=0,screenX='+Math.ceil((screen.width-width)/2)+',screenY='+Math.ceil((screen.height-height)/2));
  www.focus();
}

function open_img(img, width, height) {
     args = ',toolbar=0,scrollbars=0,resizable=0,menubar=0,status=0,directories=0,location=0,left='+(screen.width-width-10)/2+',top='+(screen.height-height-10)/2;
     if(!www || www.closed) {
       www = window.open('','','width='+width+',height='+height+','+args);
     } else {
       www.resizeTo(width,height);
     }
     www.document.write('<html><head><title></title></head><body bgcolor="#4143AC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n');
     www.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr><td align="center" valign="middle"><img src="'+img+'" border=0 alt="IMAGE:'+height+'x'+width+'"></td></tr></table></body></html>');
     www.document.close();
     www.focus();  
}


function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function getObj(name)
{
  if (document.getElementById)
  {
  	return document.getElementById(name);
  }
  else if (document.all)
  {
	return document.all[name];
  }
  else if (document.layers)
  {
   	return  document.layers[name];
  }
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function setLyr(obj,lyr)
{
	var newX = findPosX(obj);
//	var newY = findPosY(obj)+14;
        var newY = 125;
	var x = new getObj(lyr);
        if (x.style) {
  	  x.style.top = newY + 'px';
	  x.style.left = newX + 'px';
        }else{
  	  x.top = newY + 'px';
	  x.left = newX + 'px';
        }
}

var canopen,loaded;
loaded=false;

function show(what,action) {
 if (loaded) {
   obj=what;
   layer = (document.getElementById)? document.getElementById(what) : document.all[what];
   if (action=="hide") {
    layer.style.visibility = "hidden";
   }
   if (action=="none") {
    layer.style.display = "none";
   }
   if (action=="show") {
      layer.style.visibility = "visible";
   }
   if (action=="block") {
    layer.style.display = "block";
   }
 }
}



// Array functions

//Function to work with arrays
function in_array(str,arr) {
 res = -1;
 for (var i=0;i<arr.length;i++) {
   if (arr[i]==str) {
     res = i;
     i=arr.length;
   }
 }
 return res;
}

function del_from_array(str,arr) {
 res = -1;
 newarr = Array();
 for (var i=0;i<arr.length;i++) {
   if (arr[i]!=str) newarr.push(arr[i]);
 }
 return newarr;
}

function add_to_array(str,arr) {
  lastid=arr.length;
  arr[lastid]=str;
  return lastid;
}

function add_unique_to_array(str,arr) {
  if (in_array(str,arr)==-1) {
     lastid=arr.length;
     arr[lastid]=str;
     return lastid;
  }else{
     return -1;
  }
}

function add_to_top_array(str,arr) {
  lastid=arr.length;
  for (i=lastid; i>0;i--) {
    arr[i]=arr[i-1];
  }
  arr[0]=str;
  return lastid;
}


function add_unique_to_top_array(str,arr) {
  var m;
  if (in_array(str,arr)==-1) {
     m = add_to_top_array(str,arr);
     return m;
  }else{
     return -1;
  }
} 
// Array functions

function change_inner_url(obj,newurl) {
  var sobj;
  if (document.frames) {
     sobj = document.frames[obj];
  } else if (window.frames) {
     sobj = window.frames[obj];
  } else if (document.getElementByID) {
     sobj = document.getElementByID(obj);
  }
  if (sobj) sobj.location.href=newurl;
  return false;
}

var sel_id;

function set_album(id,url) {
   if (sel_id) document.images[sel_id].src='i/albm.gif';
   document.images[id].src='i/albm_s.gif';
   sel_id = id;
   change_inner_url('a_r_a',url);
}

function check_max_length(element,$max_l) {
  if (element && element.value) {
    if (element.value.length>=$max_l) {
       element.value = element.value.substring(0,$max_l);
       return false;
    }else{
       return true;
    }
  }
}

//rollover

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_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 MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function show_progress_bar() {
   var layer = (document.getElementById)? document.getElementById('progressbar') : document.all['progressbar'];
   if (layer) show('progressbar','show');
}

function update_div(div,html) {
   var layer = (document.getElementById)? document.getElementById(div) : document.all[div];
   if(layer && layer.innerHTML) {
     layer.innerHTML = html;
   }
}

function get_div_html(div) {
   var layer = (document.getElementById)? document.getElementById(div) : document.all[div];
   if(layer && layer.innerHTML) {
     return layer.innerHTML;
   }
}

function xaction(commands) {
   try {
     eval(commands);
   } catch (e) {
     alert('error');
     alert(commands);
   }
}
