function submitCloseDiv(form_name,div_name){
form_name.submit();
showHideDiv(div_name);
}

function explode( delimiter, string, limit ) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}


function detectBrowser(){

	if (navigator.userAgent.indexOf("Firefox")!=-1) browser = "ff"; 
	if (navigator.userAgent.indexOf("MSIE")!=-1) browser = "ie";

	return browser;

}

function browserDetect(){

	browser = detectBrowser();
	return browser;
}


function createFolder(title) {

	new Ajax.Updater('folderlist', '/t_filearea_ajax.php', {
		method: 'post',
		parameters: 'a=createfolder&title=' + title
	});

}



function goToUrl(url){
	
	window.location = url;
	
}

function sendMsnInvites(){
	
	count = document.getElementById('msn_counts').value;
	subject = document.getElementById('msn_subject').value;
	body = document.getElementById('msn_body').value;
	emails = "";
	for(i=0;i<count;i++){
		id = document.getElementById('msn_send' +i);
			if (id.checked) {
				emails = id.value + ";" + emails;
			}
		}		
				
	waitingDiv('start','Please wait while sending emails');
	
	feed=importXML("t_msn_invite_xml.php?emails=" + emails + "&function=send_invite&msn_subject=" + subject +"&body=" + body);
	
	waitingDiv('stop','');
	
	
}	
	
	
function fetchMsnFriends()
{	
	username = document.getElementById('msn_login').value;
	pwd = document.getElementById('msn_password').value;
	
	waitingDiv('start','Please wait');
	
	feed=importXML("t_msn_invite_xml.php?msn_username=" + username + "&msn_password=" + pwd+"&function=invite");
//alert('stop2');
	waitingDiv('stop','Please wait');

	if (feed)
	{
		contact = feed.getElementsByTagName("contact");
		login = feed.getElementsByTagName('loginsuccess')[0].getAttribute('value');
		div = document.getElementById("msn_friends");
		div.innerHTML = "";
		check_start = "<input type=checkbox id=msn_send";
		check_end = ">";
	
		if (login == 1)
		{
			for(i=0; i<contact.length; i++) 
			{
				full = check_start +  i + " value=" + contact[i].getAttribute('email') + ">" + contact[i].getAttribute('email') ;
				div.innerHTML = div.innerHTML + full + "<br>";
			}
			div.innerHTML = div.innerHTML + '<input type=hidden id=msn_counts value=' + i + '>';
			showHideDiv('msn_send_button');
		}
		else 
		{
			 div.innerHTML = "Username and password not correct";
		}
	}
	else
	{
		 div.innerHTML = "Username and password not correct";
	}
}

function sendCsvInvites()
{	
	count = document.getElementById('csv_counts').value;
	subject = document.getElementById('csv_subject').value;
	body = document.getElementById('csv_body').value;
	emails = "";
	for(i=0;i<count;i++)
	{
		id = document.getElementById('csv_send' +i);
		if (id.checked) 
		{
			emails = id.value + ";" + emails;
		}
	}		
	waitingDiv('start','Please wait while sending emails');
	feed=importXML("t_msn_invite_xml.php?emails=" + emails + "&function=send_invite&msn_subject=" + subject +"&body=" + body);
	waitingDiv('stop','');
}

function sendEcInvites()
{	
	subject = document.getElementById('ec_subject').value;
	body = document.getElementById('ec_body').value;
	emails = "";
	for(i=0;i<9;i++)
	{
		id = document.getElementById('ec_send' +i);
		if (id.value != "") 
		{
			emails = id.value + ";" + emails;
		}
	}		
	waitingDiv('start','Please wait while sending emails');
	feed=importXML("t_msn_invite_xml.php?emails=" + emails + "&function=send_invite&msn_subject=" + subject +"&body=" + body);
	waitingDiv('stop','');
}

function waitingDiv(status,text){

	if (status == "start") {
        	elem = document.getElementById('helpingdiv_text');
		elem.innerHTML = text;
		showHideDiv('helpingdiv');
		}
	else {
		showHideDiv('helpingdiv');
		}

}



function showHideDivLink(id,link){

        elem = document.getElementById(id);
        l = document.getElementById(link);

	status = showHideDiv(id);

	if (status == "visible") {
		l.innerHTML = "Hide";
	}

	if (status == "hidden") {
		l.innerHTML = "Show";
	}


}

function showHideImageDiv(image_id,image_url,div_id){
		document.getElementById(image_id).src=image_url;
		showDiv(div_id);
}


function showDiv(id){

        elem = document.getElementById(id);
        elem.style.display = "block";
        elem.style.visibility = "visible";

}



function hideDiv(id){

        var elem = document.getElementById(id);
        elem.style.display = "none";
        elem.style.visibility = "hidden";

}




function showHideDiv(id){

        elem = document.getElementById(id);
        status = elem.style.visibility;

        if (status == "visible"){
            elem.style.display = "none";
            elem.style.visibility = "hidden";
	    status_now = "hidden";
        }
        else {
             elem.style.display = "block";
             elem.style.visibility = "visible";
	    status_now = "visible";
             }

	return status_now;

}





function switchYoutubeMovieShow(id){
	//alert(id);
	elem = document.getElementById('youtube_movie_id_' + id);
        status = elem.style.visibility;
	//alert(status);

        if (status == "visible"){
            elem.style.display = "none";
            elem.style.visibility = "hidden";
        }
        else {
             elem.style.display = "block";
             elem.style.visibility = "visible";
             }

}


function writeYoutubeMovie(){

		Arr = addYoutubeMovie();

		link = "http://www.youtube.com/v/" + Arr[2];

		html1 = '<font style="font-size: 17px;">' +  Arr[1] +'</font> <a href="javascript:void(\'0\');" onClick="javascript:switchYoutubeMovieShow(' + Arr[0]  + ');">Switch</a> <table border=1 cellspacing=0 cellpadding=0 width="425"><tr><td>';
		html2 = '</td></tr></table><br>';


		link1 = '<object width="425" height="355"><param name="movie" value="';
		link2 = '"></param><param name="wmode" value="transparent"></param><embed src="';
		link3 = '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
		link =  html1 + link1 + link + link2 + link + link3 + html2;

		document.getElementById('youtube_added').innerHTML = link +  document.getElementById('youtube_added').innerHTML;


}

function getYoutubeMovieFromDB(y_id){
	
	feed=importXML("t_load_youtube_movie.php?youtube_id=" + y_id);
		
	if (feed){
		youtube_id = feed.getElementsByTagName('youtube_movie')[0].getAttribute('id');
		youtube_link = feed.getElementsByTagName('youtube_movie')[0].getAttribute('link');

		return youtube_link;	
		}
	else {
		return "MZHcPGWO44s";
	}	

}	


function addYoutubeMovie(){

	movie_link  = document.getElementById('add_youtubemovies').value;
	if (document.getElementById('download_youtubelink')){
		movie_download  = document.getElementById('download_youtubelink').value;
	}
	else {
		movie_download = "0";	
	}

	if (document.getElementById('youtube_admin_feature')){
	youtube_admin_feature_value = "0";
	//alert(document.youtubeform['youtube_admin_feature'].options.length);
			for(i=0;i<document.youtubeform['youtube_admin_feature'].options.length-1;i++)
			{
					if (document.youtubeform['youtube_admin_feature'].options[i].selected == true){
						//alert(document.youtubeform['youtube_admin_feature'].options[i].value);
						youtube_admin_feature_value = document.youtubeform['youtube_admin_feature'].options[i].value;
					}
					
			}
	//alert(youtube_admin_feature_value);
	
	}
	else {
		youtube_admin_feature_value = "0";	
	}


	movie_link = URLEncode(movie_link);
	headline  = document.getElementById('add_youtubemovies_headline').value;
	feed=importXML("t_user_func.php?add_youtubelink=" + movie_link + "&function=add_youtubelink&headline=" + headline +"&download_youtubelink=" + movie_download   +"&youtube_admin_feature=" + youtube_admin_feature_value  );

if (feed){
	youtube_id = feed.getElementsByTagName('youtube')[0].getAttribute('id');
	youtube_header = feed.getElementsByTagName('youtube')[0].getAttribute('header');
	youtube_link = feed.getElementsByTagName('youtube')[0].getAttribute('uri');
	}

var Arr=new Array()
Arr[0] = youtube_id;
Arr[1] = youtube_header;
Arr[2] = youtube_link;

return Arr;
}


function doLogin(){

		username = document.getElementById('loginusername').value;
		password = document.getElementById('loginpassword').value;

		result= loginOK(username,password);

		if (result == 1) window.location.reload();
		if (result == 2) document.getElementById('login_error').innerHTML = "Wrong username & password";

}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}



function loginOK(username,password){

		feed=importXML("t_login_xml.php?username=" + username + "&password=" + password );
		var i;
		loginok=3;
		if (feed){
			loginok = feed.getElementsByTagName('login')[0].getAttribute('value');	
			if (loginok == 1){
				//alert("Hurray!");
				}
			if (loginok == 2){
				//alert("Bhoou!");
				}
			

		}

		return loginok;

}

function importXML(dname) {
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject) {
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		xmlDoc=document.implementation.createDocument("","",null);
	}
	else {
		alert('Your browser cannot handle this script');
	}
	xmlDoc.async=false;
	xmlDoc.load(dname);
	return(xmlDoc);
}

function ZoomPicture(user_id,picture_id){
//alert("tittar pï¿½ " + picture_id );
if (document.all){
//alert("suck - sluta kÃ¶r IE, ladda hem och kÃ¶r Firefox istÃ¤llet. http://www.getfirefox.com , zoomningen funkar inte i IE.. ni med IE fÃ¥r vÃ¤nta en stund.. sÃ¥ fÃ¥r vi fixa det pÃ¥ n$
//location="t_picturegallery_viewpicture.php?picture_id="  + picture_id;
//alert("1");
window.location="/t_picture_view.php?picture_id="  + picture_id;
top.location="/t_picture_view.php?picture_id="  + picture_id;
//alert("2");
//top.location="/t_picturegallery_viewpicture.php?picture_id="  + picture_id;
wait(2200);
//setInterval("wait(2000)",10000);
//alert("3");
return true;
}
else {
//OLD document.getElementById("My" + picture_id).src = "t_user_gallery_pictures_thumb.php?filename=" + user_id + "_" + picture_id + 
//".jpg&showimg_max_width=800&showimg_max_height=800";
 document.getElementById("My" + picture_id).src = "t_user_gallery_pictures_thumb.php?filename=" + user_id + "_" + picture_id + ".jpg&template=5";
}
//importXML("/t_user_func.php?function=new_gallery_visit&picture_id=" + picture_id );
}



function CloseOverLib(){
//alert("stÃ¤nger overlib");
cClick();
nd();
}
function picture_gallery_look(picture_id){
	//alert("tittar pa " + picture_id );
	importXML("/t_user_func.php?function=new_gallery_visit&picture_id=" + picture_id );
	//alert("tittat pa " + picture_id );
}


function clickit(cn,clink,search_word) {
  if(document.images) {
     (new Image()).src="http://www.sihab.se/clickstats.php?num="+cn+"&url="+clink+"&val=" + search_word;
  }
  return true;
}
function ZoomShowImg(id, elem, pwidth, pheight) {
	cw = document.body.clientWidth;
	ch = document.body.clientHeight;
	adjust = (cw > ch) ? ch : cw;
	if (pheight > ch) {
		w = Math.ceil(ch / pheight * pwidth);
		h = ch;
	}
	else if (pwidth > cw) {
		w = cw;
		h = Math.ceil(cw / pwidth * pheight);
	}
	else {
		w = pwidth;
		h = pheight;
	}
	elem.style.left = (cw - w) / 2 + "px";
	elem.style.top = (ch - h) / 2 + "px";
	document.getElementById('marker_img').innerHTML = "<img src=\"t_blueboxblog_show_image.php?id=" + id + "\" style=\"z-index:20\" width=\"" + w + "\" height=\"" + h + "\"/> ";
	toggleSelects(false);
	elem.style.display = "block";
	elem.style.visibility = "visible";
	document.getElementById('marker_zoom').innerHTML  = ' <a href="javascript:void(0);" onclick="UnZoomShowImg(' + id + ',document.getElementById(\'marker_img_orig\'),' + w + ','  + h + ');" > UnZoom </a> ';

}

function UnZoomShowImg(id, elem, pwidth, pheight) {
	cw = document.body.clientWidth;
	ch = document.body.clientHeight;
	adjust = (cw > ch) ? ch : cw;
	if (pheight > ch) {
		w = Math.ceil(ch / pheight * pwidth);
		h = ch;
	}
	else if (pwidth > cw) {
		w = cw;
		h = Math.ceil(cw / pwidth * pheight);
	}
	else {
		w = pwidth;
		h = pheight;
	}
	elem.style.left = (cw - w) / 2 + "px";
	elem.style.top = (ch - h) / 2 + "px";
	document.getElementById('marker_img').innerHTML = "<img src=\"t_blueboxblog_show_image.php?id=" + id + "&adjust=200\" style=\"z-index:20\" width=\"400\" height=\"300\" /> ";
	toggleSelects(false);
	elem.style.display = "block";
	elem.style.visibility = "visible";

	document.getElementById('marker_zoom').innerHTML  = ' <a href="javascript:void(0);" onclick="UnZoomShowImg(' + id + ',document.getElementById(\'marker_img_orig\'),' + w + ','  + h + ');" > Zoom </a> ';

}



function showImg(id, elem, pwidth, pheight) {
	cw = document.body.clientWidth;
	ch = document.body.clientHeight;
	adjust = (cw > ch) ? ch : cw;
	if (pheight > ch) {
		w = Math.ceil(ch / pheight * pwidth);
		h = ch;
	}
	else if (pwidth > cw) {
		w = cw;
		h = Math.ceil(cw / pwidth * pheight);
	}
	else {
		w = pwidth;
		h = pheight;
	}
	elem.style.left = (cw - w) / 2 + "px";
	elem.style.top = (ch - h) / 2 + "px";
	document.getElementById('marker_img').innerHTML = "<img src=\"t_blueboxblog_show_image.php?id=" + id + "\" style=\"z-index:20\" width=\"" + w + "\" height=\"" + h + "\" /> ";
	//elem.innerHTML = "<img src=\"t_blueboxblog_show_image.php?id=" + id + "\" style=\"z-index:20\" width=\"" + w + "\" height=\"" + h + "\" />";
	toggleSelects(false);
	elem.style.display = "block";
	elem.style.visibility = "visible";
}
function showInfo(id) {
	feed=importXML("t_blueboxblog_get_info.php?id=" + id);
	if (feed) {
		var msg1 = feed.getElementsByTagName('msg');
	document.getElementById('marker_img').innerHTML = '<img src="t_blueboxblog_show_image.php?id=' + id + '&adjust=400" border=0 style="cursor:pointer" />';

		//document.getElementById('marker_img').innerHTML = '<img src="t_blueboxblog_show_image.php?id=' + id + '&adjust=400" border=0 style="cursor:pointer" onclick="showImg(' + id + ',document.getElementById(\'marker_img_orig\'),' + msg1[0].getAttribute('pwidth') + ',' + msg1[0].getAttribute('pheight') + ');" />' ;

		document.getElementById('marker_zoom').innerHTML  = ' <a href="javascript:void(0);" onclick="ZoomShowImg(' + id + ',document.getElementById(\'marker_img_orig\'),' + msg1[0].getAttribute('pwidth') + ','  + msg1[0].getAttribute('pheight') + ');" > Zoom </a> ';
		document.getElementById('marker_username').innerHTML = '<a href="t_user_info.php?username=' + msg1[0].getAttribute('username') + '" target="_blank">' + msg1[0].getAttribute('username')   + '</a>';
		//document.getElementById('marker_username').innerHTML  = ' <a href="javascript:void(0);" onclick="showImg(' + id + 
		//',document.getElementById(\'marker_img_orig\'),' + msg1[0].getAttribute('pwidth') + ','  + msg1[0].getAttribute('pheight') + ');" > Zoom </a> <br> <a 
		//href="t_user_info.php?username=' + msg1[0].getAttribute('username') + '" target="_blank">' + msg1[0].getAttribute('username')   + '</a>';
		document.getElementById('marker_message').innerHTML  =  msg1[0].getAttribute('message');
		document.getElementById('marker_catalog_name').innerHTML  =  msg1[0].getAttribute('catalog_id');
		document.getElementById('marker_category').innerHTML  =  msg1[0].getAttribute('category');
		document.getElementById('marker_catalog').innerHTML  =  '<a href="javascript:void(\'0\');" onClick="javascript:LoadCatalog(\'' + msg1[0].getAttribute('catalog_id')  + '\');"><nobr>' + msg1[0].getAttribute('catalog_name') + '</nobr></a>';
		document.getElementById('marker_date').innerHTML  =   msg1[0].getAttribute('date') ;
//		alert("marker's member_id: " + msg1[0].getAttribute('member_id')  + "\nyour user_id: -1");
		if (msg1[0].getAttribute('member_id') == -1) {
			document.getElementById('marker_edit').innerHTML  =  '<span class="button2" onclick="editMessage(' + id + ');">Redigera</span>';
			document.getElementById('marker_delete').innerHTML  =  '<span class="button2" onclick="deleteMarker(' + id + ');">Ta bort</span>';
		}
		else {
			document.getElementById('marker_edit').innerHTML  =  "";
			document.getElementById('marker_delete').innerHTML  =  "";
		}
	}
	else {
		alert("id: " + id);
	}
}

function openNewMsg(rcptid) {
  window.open("t_messages.phtml?action=showSend&rcpt_id=" + rcptid, "_blank", "height=177, width=210, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=yes, toolbar=no");
}

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

mouseX = 50; // Default mouse X
mouseY = 50; // Default mouse Y
offset = 5;
toolMouseX = mouseX+offset;
toolMouseY = mouseY+offset;

function getMouseXY(e) {
  if (IE) {
    mouseX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX;
    mouseY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (mouseX < 0) mouseX = 0;
  if (mouseY < 0) mouseY = 0;
  toolMouseX = mouseX+offset;
  toolMouseY = mouseY+offset;
}

function showHide(id) {
  var visibility = document.getElementById(id).style.visibility;
  if(visibility == 'visible') {
    document.getElementById(id).style.visibility = 'hidden';
  }
  else {
    document.getElementById(id).style.visibility = 'visible';
    document.getElementById(id).style.left = toolMouseX+'px';
    document.getElementById(id).style.top = toolMouseY+'px';
  }
}

function showHide2(id, h, w) {
  var visibility = document.getElementById(id).style.visibility;
  if(visibility == 'visible') {
    document.getElementById(id).style.visibility = 'hidden';
    //document.getElementById(id).style.height = '0px';
    //document.getElementById(id).style.width = '0px';
    document.getElementById(id).style.display = 'none';
  }
  else {
    document.getElementById(id).style.visibility = 'visible';
    //document.getElementById(id).style.height = h+'px';
    //document.getElementById(id).style.width = w+'px';
    document.getElementById(id).style.display = 'block';
  }
}

function getContentFromIframe(iFrameName)  
{  
    var myIFrame = document.getElementById(iFrameName);  
    var content = myIFrame.contentWindow.document.body.innerHTML;  
	return content;
} 

function fetchCsvFriends()
{	
	waitingDiv('start','Please wait');
	feed=importXML("t_site_csv_upload.php?function=get_contacts");
	waitingDiv('stop','Please wait');

	if (feed)
	{
		contact = feed.getElementsByTagName("contact");
		//login = feed.getElementsByTagName('loginsuccess')[0].getAttribute('value');
		check_start = "<input type=checkbox id=csv_send";
		check_end = ">";
		/*if (login == 1)
		{*/
		html = "";
			for(i=0; i<contact.length; i++) 
			{
				full = check_start +  i + " value=" + contact[i].getAttribute('email') + ">" + contact[i].getAttribute('email');
				html = html + full + "<br>";
			}
			div = document.getElementById("csv_friends");
			div.innerHTML = "";
			div.innerHTML = html + '<input type=hidden id=csv_counts value=' + i + '>';
			showHideDiv('csv_send_button');
		/*}
		else 
		{
			 div.innerHTML = "Upload failed";
		}*/
	}
	else
	{
		 div.innerHTML = "Upload failed";
	}
}