var xmlHttp = null;
var xmlHttp2 = null;
var writedone = false;

// Mozilla, Opera, Safari sowie Internet Explorer 7
if (typeof XMLHttpRequest != 'undefined') {
	xmlHttp = new XMLHttpRequest();
	xmlHttp2 = new XMLHttpRequest();
}
if (!xmlHttp) {
	// Internet Explorer 6 und aelter
	try {
		xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			xmlHttp  = null;
		}
	}
}
if (!xmlHttp2) {
	// Internet Explorer 6 und aelter
	try {
		xmlHttp2  = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			xmlHttp2  = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			xmlHttp2  = null;
		}
	}
}

function writeSB(sb_current_id,sb_user_id,sb_channel,sb_email,sb_mode) {
	var string;
	
	if (xmlHttp) {
		xmlHttp.open('GET', '/sb/sb_render_spreadbox.php?donotwrite=1&sb_id=' + sb_current_id + '&sb_channel='+ sb_channel + '&sb_mode='+ sb_mode + '&sb_user_id='+ sb_user_id + '&sb_email='+ sb_email + '&sb_page_url=' + document.URL, true);
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
			
				var vars = xmlHttp.responseText.split('%%');
	
				if((document.getElementById(widget_div)!=null)&&(document.getElementById(widget_div).style!=null)) {
					document.getElementById(widget_div).innerHTML = vars[0]; }

				if((document.getElementById(blogcode_div)!=null)&&(document.getElementById(blogcode_div).style!=null)) {
					document.getElementById(blogcode_div).innerHTML = vars[1]; }

				if (with_email_form) { 
					document.spreadit.sb_id.value = sb_current_id;
				}
				if (with_blog_form) { 
					string = vars[1];
					string = string.replace(/&lt;/g,'<');
  					string = string.replace(/&gt;/g,'>');
					document.code.sb_code.value = string;
				}
				
				myspaceSb = vars[2];
				activateLink();
				switchBack();
			}
    		};
		xmlHttp.send(null);
	}
}	

function sb_browse2next(mode,dir,sb_user_id,sb_channel,sb_email,sb_mode) {
	clear_messages();
	
	if (xmlHttp2) {
		xmlHttp2.open('GET', '/sb/sb_browse.php?dir=' + dir + '&sb_shop_id=' + sb_current_shop_id + '&mode=' + mode + '&sb_id=' + sb_current_id, true);
		xmlHttp2.onreadystatechange = function () {
			if (xmlHttp2.readyState == 4) {
				var vars = xmlHttp2.responseText.split('%%');
				sb_current_shop_id = vars[0]; 
				sb_current_id = vars[1]; 
				writeSB(sb_current_id,sb_user_id,sb_channel,sb_email,sb_mode);
			}
		};
		xmlHttp2.send(null);
	}
	return false;
}

function sb_browse2shop(sb_shop_id,sb_id,sb_user_id,sb_channel,sb_email,sb_mode) {
	clear_messages();
	sb_current_shop_id = sb_shop_id; 
	sb_current_id = sb_id; 
	writeSB(sb_current_id,sb_user_id,sb_channel,sb_email,sb_mode);
	return false;
}

function sb_browse2shop_noClear(sb_shop_id,sb_id,sb_user_id,sb_channel,sb_email,sb_mode) {
	sb_current_shop_id = sb_shop_id; 
	sb_current_id = sb_id; 
	writeSB(sb_current_id,sb_user_id,sb_channel,sb_email,sb_mode);
	return false;
}