Array.prototype.find = function(searchStr) {
  var returnArray = false;
  for (i=0; i<this.length; i++) {
    if (typeof(searchStr) == 'function') {
      if (searchStr.test(this[i])) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    } else {
      if (this[i]===searchStr) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    }
  }
  return returnArray;
}

// SE
var mdmCatPriIdArray	= [];
var mdmCatLftIdArray	= [];
var mdmCatRgtIdArray	= [];

function mdmCat_switch_visibility(what,jfp_pri_id,jfp_lft,jfp_rgt) {
	if (Element.visible($(what))==false){
		//mdm_AddToOpenList(jfp_pri_id,jfp_lft,jfp_rgt);
		$(what).style.display='block';
	}else{
		//mdm_RemoveFromOpenList(jfp_pri_id,jfp_lft,jfp_rgt);
		//mdm_ShowOpenList();
		$(what).style.display='none';
	}
}


function mdm_AddToOpenList(jfp_pri_id,jfp_lft,jfp_rgt) {
	mdmCatPriIdArray.push(jfp_pri_id);
	mdmCatLftIdArray.push(jfp_lft);
	mdmCatRgtIdArray.push(jfp_rgt);
	alert("ADDED: PRI: "+jfp_pri_id+" LFT: "+jfp_lft+" RGT: "+jfp_rgt);
}

function mdm_RemoveFromOpenList(jfp_pri_id,jfp_lft,jfp_rgt) {
	var idx	= mdmCatPriIdArray.indexOf(jfp_pri_id);
	if (idx!=-1){
		mdmCatPriIdArray.splice(idx,1);
		mdmCatLftIdArray.splice(idx,1);
		mdmCatRgtIdArray.splice(idx,1);
		alert("REMOVED: PRI: "+jfp_pri_id+" LFT: "+jfp_lft+" RGT: "+jfp_rgt);
	}
	
}

function mdm_ShowOpenList() {
	var x='';
	for(var i=0; i<mdmCatPriIdArray.length; i++) { 
		x=x+"PRI: "+mdmCatPriIdArray[i]+" LFT: "+mdmCatLftIdArray[i]+" RGT: "+mdmCatRgtIdArray[i]+"\n";
	}
	alert(x);
}
// SE







function TrimString(sInString) {
	sInString	= sInString.replace( /^\s+/g, "" );
	return sInString.replace( /\s+$/g, "" );
}

function mdm_addSelection(selectedItem) {
	if (TrimString((selectedItem.getElementsByClassName("lsr")[0].innerHTML)).length>1){
		$("csc").value=(selectedItem.getElementsByClassName("lsr")[0].innerHTML).replace(/&amp;/g,"&");
		$("lsc").value=selectedItem.getElementsByClassName("lsr")[0].innerHTML;
	}else{
		Element.hide(document.getElementById('ac_ul'));
		selectedItem.submit();
		return true;
	}
}

function mdm_updateFields(inputField, selectedItem) {

//	var debug="";
//	for (i=0;i<selectedItem.childNodes.length;i++)
//	{
//		debug=debug+i+": "+selectedItem.childNodes.item(i).innerHTML+"\n";
//	}

//	var debug2="";
//	debug2=selectedItem.getElementsByClassName("curr_search_results");

}


function mdm_change_image(which,new_img) {
	$(which).src=new_img;
}


function mdm_hide_show(hide_what,show_what) {
	//	$("welcome_box").style.display='none';
	//	var queue = Effect.Queues.get('global');
//	new Effect.ToogleBlind('welcome_box', {queue: 'front'});
//	new Effect.BlindDown('welcome_box', {queue: 'front'});
	//	new Effect.BlindUp('search_results', {queue: 'front'});
	$(hide_what).style.display='none';
	$(show_what).style.display='block';
	//	new Effect.BlindDown('search_results', {queue: 'end'});
	//	new Effect.ToogleBlind('search_results', {queue: 'end'});
}

//function mdm_hide_welc_show_res() {
	//	$("welcome_box").style.display='none';
	//	var queue = Effect.Queues.get('global');
//	new Effect.ToogleBlind('welcome_box', {queue: 'front'});
//	new Effect.BlindDown('welcome_box', {queue: 'front'});
	//	new Effect.BlindUp('search_results', {queue: 'front'});
//	$("welcome_box").style.display='none';
//	$("search_results").style.display='block';
	//	new Effect.BlindDown('search_results', {queue: 'end'});
	//	new Effect.ToogleBlind('search_results', {queue: 'end'});
//}

function mdm_show_hide_details(which_arrow,which) {
	if (Element.visible($(which))==false){
		new Effect.BlindDown(which);
		$(which_arrow).src='/images/global/arrow_green_up.gif';
	}else{
		new Effect.BlindUp(which);
		$(which_arrow).src='/images/global/arrow_green_down.gif';
	}
}

function mdm_show_hide_offerdetails(which_arrow,which) {
	if (Element.visible($(which))==false){
		new Effect.BlindDown(which);
		$(which_arrow).src='/images/arrow_green_up.gif';
	}else{
		new Effect.BlindUp(which);
		$(which_arrow).src='/images/arrow_green_down.gif';
	}
}

function mdm_show_hide_offers(which_arrow,which) {
	if (Element.visible($(which))==false){
		new Effect.BlindDown(which);
		$(which_arrow).src='/images/arrow_green_up.gif';
	}else{
		new Effect.BlindUp(which);
		$(which_arrow).src='/images/arrow_green_down.gif';
	}
}

function mdm_show_hide_switch_image(what_to_hideshow,image_to_switch,image_hide,image_show) {
	if (Element.visible($(what_to_hideshow))==false){
		new Effect.BlindDown(what_to_hideshow);
		$(image_to_switch).src=image_show;
	}else{
		new Effect.BlindUp(what_to_hideshow);
		$(image_to_switch).src=image_hide;
	}
}

function mdm_show_hide_switch_image_cat(what_to_hideshow,image_to_switch,image_hide,image_show) {
	if (Element.visible($(what_to_hideshow))==true){
		//new Effect.BlindDown(what_to_hideshow);
		$(image_to_switch).src=image_show;
	}else{
		//new Effect.BlindUp(what_to_hideshow);
		$(image_to_switch).src=image_hide;
	}
}

function change_image_src(what_image,new_image) {
	
		$(what_image).src=new_image;
	
	
}

function mdm_switch_visibility(what) {
	if (Element.visible($(what))==false){
		$(what).style.display='block';
	}else{
		$(what).style.display='none';
	}
}

function mdm_switch_visibility_inline(what) {
	if (Element.visible($(what))==false){
		$(what).style.display='inline';
	}else{
		$(what).style.display='none';
	}
}

function mdm_switch_cons_sup(which) {
	if (Element.visible($(which))==false){
		new Effect.BlindDown(which);
	}else{
		new Effect.BlindUp(which);
		$(which).style.display='none';
	}

}



function hideOViewer(which_div){
	//document.getElementById(which_div).innerHTML='';
	$("OViewer").innerHTML='';
}

function setFieldValue(what)
{
	$("url").value = what
	$("explorer").style.display='none';
}

function disabled_field(what)
{
	$(what).disabled = "disabled";
}
function enabled_field(what)
{
	$(what).disabled = "";
}

function change_url(what,newlink)
{
	$(what).href 		= newlink;
	$(what).innerHTML 	= newlink;
	$(what).target		="_blank";
	
}








// ISAK TESTING

			var sendReq = getXmlHttpRequestObject();
			var receiveReq = getXmlHttpRequestObject();
			var lastMessage = 0;
			var mTimer;
			//Gets the browser specific XmlHttpRequest Object
			function getXmlHttpRequestObject() {
				if (window.XMLHttpRequest) {
					return new XMLHttpRequest();
				} else if(window.ActiveXObject) {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} else {
					document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Consider upgrading your browser.';
				}
			}
			
			//Gets the current messages from the server
			function getChatText() {
				if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
					receiveReq.open("GET", '/ajaxserver.php?sokord=' + document.getElementById('txt_message').value, true);
					receiveReq.onreadystatechange = handleReceiveChat; 
					receiveReq.send(null);
				}			
			}

			function handleReceiveChat() {
				if (receiveReq.readyState == 4) {
					//Get a reference to our chat container div for easy access
					var chat_div = document.getElementById('div_sokresultat');
					//Get the AJAX response and run the JavaScript evaluation function
					//on it to turn it into a useable object.  Notice since we are passing
					//in the JSON value as a string we need to wrap it in parentheses
					var response = eval("(" + receiveReq.responseText + ")");
					for(i=0;i < response.messages.message.length; i++) {
						chat_div.innerHTML += "id: "+response.messages.message[i].id + "<br />";
						chat_div.innerHTML += "value: "+response.messages.message[i].user + "<br />";
						chat_div.innerHTML += "internal_value: "+response.messages.message[i].text + '<br />';
						chat_div.scrollTop = chat_div.scrollHeight;
						lastMessage = response.messages.message[i].id;
					}
					//mTimer = setTimeout('getChatText();',2000); //Refresh our chat in 2 seconds
				}
			}
			//This functions handles when the user presses enter.  Instead of submitting the form, we
			//send a new message to the server and return false.
			function blockSubmit() {
				getChatText();
				return false;
			}
			//This cleans out the database so we can start a new chat session.
			function clearBox() {
				document.getElementById('div_sokresultat').innerHTML = '';
			}

			
			
var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}			


var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function checkIfAnyFieldFilledIn(confirmtext)
{
  
  // ** START **
  if ($("name").value !="" || $("subject").value !="") {
    return confirm(confirmtext)
  }
  // ** END **
  return true ;
}

function confirmCreateClassGroup(confirmtext)
{
  
  // ** START **
  if ($("newclassname").value !="") {
    return confirm(confirmtext+" "+$("newclassname").value)
    
  }
	return true ; 
  }
  

  // ** END **


function AlertFunction(text)
{
	alert(text);
}

function ClearSearchAndFocus()
{
	$("csc").value="";
	$("csc").focus();
}

function FieldValue(field)
{
	return $(field).value;
}

function insertfieldonkey(field,to_field) 
{
					var text = document.getElementById(field).value;
					var text2 = document.getElementById(to_field).value;
					if(text.length > 0 && text2.length <3) 
					{
	
						document.getElementById(to_field).value=text;
					}
					
					
					
}

function HideDivNotLoggedInFields()
{
	$("typeinterest").style.display='none';
	$("search_boxholder").style.display='none';
	$("browser").style.display='none';
	$("popular").style.display='none';
	$("line").style.display='none';
	
	
}


