function collapseSelect(em) {
	document.getElementById(em).size=1;
}

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 ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);	
	else // otherwise, update 'characters left' counter
		cntfield.value = maxlimit - field.value.length;
}

function CheckAllIn(form) {			
  for (var i = 0; i < document.forms[form].elements.length; i++) {
	if(document.forms[form].elements[i].type == 'checkbox') {
	  document.forms[form].elements[i].checked = !(document.forms[form].elements[i].checked);
	}
  }
}
var ie4 = document.all;

var ns4 = document.layers;

var ns6 = document.getElementById && !document.all; 

// Example:

// var b = new BrowserInfo();

// alert(b.version); 

function BrowserInfo()

{

  this.name = navigator.appName;

  this.codename = navigator.appCodeName;

  this.version = navigator.appVersion.substring(0,4);

  this.platform = navigator.platform;

  this.javaEnabled = navigator.javaEnabled();

  this.screenWidth = screen.width;

  this.screenHeight = screen.height;

}



var isW3C = (document.getElementById) ? true : false
var isAll = (document.all) ? true : false

/* 1.1.2: Fixed a bug where trailing . in e-mail address was passing
            (the bug is actually in the weak regexp engine of the browser; I
            simplified the regexps to make it work).
   1.1.1: Removed restriction that countries must be preceded by a domain,
            so abc@host.uk is now legal.  However, there's still the 
            restriction that an address must end in a two or three letter
            word.
     1.1: Rewrote most of the function to conform more closely to RFC 822.
     1.0: Original  */

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/;
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]";
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.");
    return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!");
		return false;
	    }
    }
    return true;
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.");
    return false;
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.");
   return false;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!";
   alert(errStr);
   return false;
}

// If we've gotten this far, everything's valid!
return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; 
  document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) 
  	eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

function MM_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function sure() {
	msg = 'Are you sure you want to delete?';
	return confirm(msg);
}

function sureDelete(url) {
	if (confirm("Are you sure you want to delete"))
	    document.location = url;
}

function popUp2(URL,width,height,x,y) {
		day = new Date();
		id = day.getTime();
//		alert(URL + " " + width + " " + height);
//		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width='" + width + "',height='"+height+"',left=300,top=200');");
		window.open(URL,id,'width=' + width + ',height=' + height + ',innerwidth=' + width + ',innerheight=' + height + ',left=' + x + ',top=' + y + ',screenX=' + x + ',screenY=' + y + ',toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=1,resizable=1');
}
/*function popUp(strURL,strType,strHeight,strWidth) {
	var strOptions="";
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth+"left=300,top=100";
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	window.open(strURL, 'newWin', strOptions);
}
*/
var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUp(url, type, strWidth, strHeight){
	
//	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") 
		tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") 
		tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=300,top=100";
	if (type == "console2") 
		tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=300,top=80";	
	newWindow = window.open(url, "Vindu", tools);
	newWindow.focus();
}
		
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {
//  if(popUpWin) {
//    if(!popUpWin.closed) popUpWin.close();
//  }
//  alert(URLstr);
  popUpWin = open(URLStr, 'popUpWin', 'width='+width+',height='+height+',innerwidth='+width+',innerheight='+height+',left='+left+',top='+top+',toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1');
  popUpWin.focus();
//  return false;
}
//var popUpWin2=0;
function popUpWindow2(URLStr, left, top, width, height) {
//  if(popUpWin2) {
//    if(!popUpWin2.closed) popUpWin2.close();
//  }
//  alert(URLstr);
  popUpWin2 = window.open(URLStr,'popUpWin2','width='+width+',height='+height+',left='+left+',top='+top+',toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbar=1,resizable=1,copyhistory=1');
  popUpWin2.focus();
//  return false;
}
function refreshParent() {
  window.opener.location.href = window.opener.location.href;
  if (window.opener.progressWindow) {
    window.opener.progressWindow.close()
  }
  window.close();
}
function validateTime(t) {
	if (document.getElementById(t).value.search(/\d{2}\:\d{2}/)==-1) {
      alert("The time format for " + t + " is not valid.\r\nPlease enter a time with the format 00:00 (24 hr time format please!)");
  	  document.getElementById(t).focus();
   }
}
function DateGood(y,m,d) {
  var D;
  with (D = new Date(y, --m, d))
    return getMonth() == m && getDate() == d ? D : NaN;
}
function DateFieldOK(y,m,d) {
//  var X = D.value.split(/\D+/);
//  return DateGood(+ X[0], + X[1], + X[2]);
	return DateGood(y,m,d);
}
function ISODateValue(Q) {
  var B, D = 0;
  B = /^(\d{4})-(\d\d)-(\d\d)$/.test(Q);
  if (B)
    with (RegExp)
      {
        D = new Date($1, $2 - 1, $3);
        B = D.getMonth() == $2 - 1 && D.getFullYear() == $1;
      }
  return [B, D];
}
function isDate(mm,dd,yyyy) {
	var d = new Date(mm + "/" + dd + "/" + yyyy);
	return d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy;
}
function doTheClock() {
   window.setTimeout( "doTheClock()", 1000 );
   t = new Date();
   if(document.all || document.getElementById){
      window.status = t.toString();
   }else{   
      self.status = t.toString();
   }
}
doTheClock()

// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

var isSelected = false;

function copySelection(workArea){

	workText = document.selection.createRange();
	isSelected = true;
}
function remember() {
//	pos = document.selection.createRange();
	workText = document.selection.createRange();
	isSelected = true;
}

function AddURL2(workArea){
	alert(2);
	var AddURL="";
	var txt="";
	
	txt=prompt("Enter URL for the link.","http://");
	AddURL="<a href=\""+txt+"\" target=\"_blank\">";
	AddURL2="</a>";
	
	
	if (isSelected) {
		workArea.workText.text = AddURL+workArea.workText.text+AddURL2;
		if (workArea.workText.text=='') {
			isSelected=false;workArea.focus()
		}
	}
}
function insert_link(f,a,klasse) {
  
  var str = document.selection.createRange().text;
//  document.form.a.value.focus();
  var my_link = prompt("Enter URL for the link:","http://");
  if (my_link != null) {
    var sel = document.selection.createRange();
	sel.text = "<a href=\"" + my_link + "\" target=\"_blank\" class=\""+klasse+"\">" + str + "</a>";
  }
  return;
}
function insert_mail_link(f,a,klasse) {
  
  var str = document.selection.createRange().text;
//  document.form.a.value.focus();
  var my_link = prompt("Enter email address for the link:","");
  if (my_link != null) {
    var sel = document.selection.createRange();
	sel.text = "<a href=\"mailto:" + my_link + "\" class=\""+klasse+"\">" + str + "</a>";
  }
  return;
}

function insert_movie(f,a,klasse) {  
  var str = document.selection.createRange().text;
//  document.form.a.value.focus();
  var my_movie = prompt("Enter youtube movie address here:","");
  if (my_movie != null) {
    var sel = document.selection.createRange();
    start = my_movie.indexOf("http");
    end = my_movie.indexOf('"', start);
    my_movie = my_movie.substring(start,end);
    sel.text = "<object type=\"application/x-shockwave-flash\" style=\"width:425px; height:350px;\" data=\"" + my_movie + "\"><param name=\"movie\" value=\"" + my_movie + "\" /></object>";
  }
  return;
}

function AddURL(workArea,klasse){
	field = document.getElementById(workArea);	
	field.focus();
//	alert(field.value);
/*	if (isSelected) {
		AddURL2(workArea);
	} 
	else */ 
	if (field.selectionStart || field.selectionStart == '0') {    	   	
		var AddURL = "";
		var txt = "";
		
	//	alert(workArea);
		txt = prompt("Enter URL for the link:","http://");
		AddURL = "<a href=\""+txt+"\" target=\"_blank\" class=\""+klasse+"\">";
		AddURL2 = "</a>";	
      var sel = ""; 
      var startPos = field.selectionStart; 
      var endPos = field.selectionEnd; 
       
      if (endPos!=startPos) 
      sel = field.value.substring(startPos,endPos); 
       
      if (sel.length>0) 
      	field.value = field.value.substring(0,startPos)+AddURL+sel+AddURL2+field.value.substring(endPos,field.value.length); 
      else { 
         field.value = field.value.substring(0,startPos)+AddURL+sel+AddURL2+field.value.substring(endPos,field.value.length); 
//         field.selectionStart = startPos+sel.length+2; 
 //        field.selectionEnd = startPos+sel.length+2; 
      } 
   } else 
   		insert_link(field,workArea,klasse);
}

function AddMail(workArea,klasse){
	field = document.getElementById(workArea);	
	field.focus();
	if (klasse == undefined)
		klasse = "m_link";
//	alert(field.value);
/*	if (isSelected) {
		AddURL2(workArea);
	} 
	else */ 
	if (field.selectionStart || field.selectionStart == '0') {    	   	
		var AddMail = "";
		var mtxt = "";
		
	//	alert(workArea);
		mtxt = prompt("Enter emailaddress for the link:","");
		AddMail = "<a href=\"mailto:"+mtxt+"\" class=\""+klasse+"\">";
		AddMail2 = "</a>";	
      var sel = "";
      var startPos = field.selectionStart; 
      var endPos = field.selectionEnd; 
       
      if (endPos!=startPos) 
      sel = field.value.substring(startPos,endPos); 
       
      if (sel.length>0) 
      	field.value = field.value.substring(0,startPos)+AddMail+sel+AddMail2+field.value.substring(endPos,field.value.length); 
      else { 
         field.value = field.value.substring(0,startPos)+AddMail+sel+AddMail2+field.value.substring(endPos,field.value.length); 
//         field.selectionStart = startPos+sel.length+2; 
 //        field.selectionEnd = startPos+sel.length+2; 
      } 
   } else 
   		insert_mail_link(field,workArea,klasse);
}
                                                                                                                                                                                               
function AddMovie(workArea,klasse){
    field = document.getElementById(workArea);    
    field.focus();
    if (klasse == undefined)
        klasse = "m_link";
//    alert(field.value);
/*    if (isSelected) {
        AddURL2(workArea);
    } 
    else */ 
    if (field.selectionStart || field.selectionStart == '0') {               
        var AddMovie = "";
        var movie = "";
        
    //    alert(workArea);
        movie = prompt("Enter YouTube movie address: (the EMBED code you usually find to the right of the movie at www.youtube.com). Beware! In the ingress, the movie will and must be placed before the text!","");
        start = movie.indexOf("http");
        end = movie.indexOf('"', start);
        movie = movie.substring(start,end);
        AddMovie = "<object type=\"application/x-shockwave-flash\" style=\"width:425px; height:350px;\" data=\"" + movie + "\"><param name=\"movie\" value=\"" + movie + "\" /></object>";
        var sel = ""; 
        if (workArea == "ingress") {
            var startPos = 0; 
            var endPos = 0; 
        } else {
            var startPos = field.selectionStart; 
            var endPos = field.selectionEnd; 
        }    
        field.value = field.value.substring(0,startPos)+AddMovie+field.value.substring(endPos,field.value.length); 
   } else 
        insert_movie(field,workArea,klasse);
}

function wrapInTags(workArea,isTag){

	if (isSelected) {
		workArea.workText.text = "<"+isTag+">"+workArea.workText.text+"</"+isTag+">";
		if (workArea.workText.text=='') {
			isSelected=false;workArea.focus()
		}
	}
}

function tag(f,tag) { 
    var field = document.getElementById(f); 
    tag = tag.toLowerCase(); 
    endtag = tag;
    if (tag == "justify") {
		tag = "p class='justify'";
		endtag = "p";
	} else if (tag == "right") {
		tag = "p class='right'";
		endtag = "p";
	} 
	if (isSelected) {
		  var str = document.selection.createRange().text;
//		  document.form.field.focus();
		  var sel = document.selection.createRange();
		  sel.text = "<" + tag + ">" + str + "</" + endtag + ">";
		  return;

	}

   else if (field.selectionStart || field.selectionStart == '0') {    	   	
       field.focus(); 
  		var text = ""; 
      var startPos = field.selectionStart; 
      var endPos = field.selectionEnd; 
       
      if(endPos!=startPos) 
      text = field.value.substring(startPos,endPos); 
       
      if(text.length>0) 
      field.value = field.value.substring(0,startPos)+"<"+tag+">"+text+"</"+endtag+">"+field.value.substring(endPos,field.value.length); 
      else {  
	  	 field.value = field.value.substring(0,startPos)+"<"+tag+"></"+endtag+">"+field.value.substring(endPos,field.value.length); 
         field.selectionStart = startPos+tag.length+2; 
         field.selectionEnd = startPos+tag.length+2; 
      } 
   } 
   else 
   field.value = "<"+tag+"></"+tag+">"; 
}
function mouseover(el) {
  el.className = "raised";
}

function mouseout(el) {
  el.className = "fbutton";
}

function mousedown(el) {
  el.className = "pressed";
}

function mouseup(el) {
  el.className = "raised";
}

var $j = jQuery;
$j(document).ready(function() {
	$j("#audioplayer div").each(function() {
		$j(this).click(function() {
			var id = $(this).attr('id');	
			$.ajax({
			   type: "GET",
			   url: "http://zobbmusic.com/regtrack.php",
			   data: "id="+id,
			   success: function(msg) {
				 //alert( "Data Saved: " + id );
			   }
			   });
			//sendValue('regtrack',id);
		});					
	});
});
