var offX = 0;         // X offset from mouse position
var offY = 21;         // Y offset from mouse position
var mouse_posx=0;
var mouse_posy=0;
var sizecontainer = new Array;
var current_replybox='';

var current_popup=new Object();
current_popup.id;
current_popup.screen_x1=0;
current_popup.screen_x2=0;
current_popup.screen_y1=0;
current_popup.screen_y2=0;
current_popup.enabled=0;
current_popup.fatherid="";





document.onmousemove = follow;

document.onclick=function(e){
if(current_popup.enabled==1){
if (!e) var e = window.event;
if (e.target) targ = e.target.id;
else if (e.srcElement) targ = e.srcElement.id;
if(!e.pageX){ var mousex=e.x+document.body.scrollLeft; } else { var mousex=e.pageX; }//IE fix
if(!e.pageY){ var mousey=e.y+document.body.scrollTop; } else { var mousey=e.pageY; }//IE fix
if(mousex<=current_popup.screen_x1 || mousex>=current_popup.screen_x2 || mousey<=current_popup.screen_y1 || mousey>=current_popup.screen_y2){
if(targ!=current_popup.fatherid){//only close if it's not the father element(button that creates the popup) that is clicked on.
destroypopup();
}}}
}



function clear_object(id){
obj=document.getElementById(id);
obj.innerHTML='';
}




function stretchtofit(object){
//theheight=(getclientHeight()-271);
//obj=document.getElementById(object);  
//obj.style.minHeight =theheight + 'px'; 
}

window.onload=function(){
//stretchtofit('stretch_block');
}
window.onresize=function(){
//stretchtofit('stretch_block');
}



function mouseX(evt) {
if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;} 

function mouseY(evt) {
if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;} 



function get_linkcode(){
var url=prompt('please enter the address of your link');
if(url != null && url!=''){
var text=prompt('please enter the text of your link');
if(text != null && text!=''){
if(left(url, 7)!= 'http://'){ url='http://' + url; }
var linkcode='[url=' + url + ']' + text + '[/url]';
return linkcode;
}}}


function xmlhttpsendpost(url, data, req){
req.open('POST', url, 'false'); 
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.send(data);
}



function get_imagecode(){
var url=prompt('please enter the address of your image');
if(url != '' && url != null){
if(left(url, 7)!= 'http://'){ url='http://' + url; }
var linkcode='[img]' + url + '[/img]';
return linkcode;
}}

function showtags(){
void window.open('http://www.storm-artists.net/info/tags/' , '', 'directories=no, height=450, left=50, location=no, menubar=no, resizable=no, scrollbars=yes, status=yes, toolbar=no, top=50, width=300');
}

function showshoutbox(){
void window.open('http://www.storm-artists.net/shoutbox/' , '', 'directories=no, height=450, left=50, location=no, menubar=no, resizable=no, scrollbars=yes, status=yes, toolbar=no, top=50, width=300');
}

function showemoticons(){
void window.open('http://www.storm-artists.net/info/emoticons/' , '', 'directories=no, height=450, left=25, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, toolbar=no, top=25, width=400');
}


function add_to_textarea(targetid, newdata){
if(newdata!='' && newdata!=null && newdata!=undefined){
document.getElementById(targetid).value=document.getElementById(targetid).value + newdata;
document.getElementById(targetid).scrollTop=document.getElementById(targetid).scrollHeight;
}}


function createxmlhttp(){
var req=0;
if (window.XMLHttpRequest){ req=new XMLHttpRequest() }
if (window.ActiveXObject){ req=new ActiveXObject("Microsoft.XMLHTTP")  }
if(!req){ alert('XMLHttpRequest not supported; Upgrade your browser for this to work.'); }
return req;
}

function follow(evt) {
mouse_posx=parseInt(mouseX(evt));
mouse_posy=parseInt(mouseY(evt));
if (document.getElementById) {var obj = document.getElementById('mouse_popup').style;  
if(obj.visibility!='hidden'){ 
current_width=parseInt(document.getElementById('mouse_popup').offsetWidth );
doc_width=getclientwidth();

if((parseInt(mouseX(evt))+current_width)>doc_width){
obj.left = doc_width - current_width;
obj.top = (parseInt(mouseY(evt))+offY) + 'px';
} else {
obj.left = (parseInt(mouseX(evt))+offX) + 'px';  
obj.top = (parseInt(mouseY(evt))+offY) + 'px';
}

}}} 

function start_message(text, width_var){
var obj=document.getElementById('mouse_popup');
if(text!=0){
obj.style.width=width_var + 'px'; 
obj.innerHTML= text;
} obj.style.display='block'; 
}



function stop_message(){
var obj=document.getElementById('mouse_popup');
obj.style.display='none';
obj.innerHTML='';
}



function getclientwidth() {
var myWidth = 0, myHeight = 0;
if( typeof( document.body.offsetWidth ) == 'number' ) {
myWidth=document.body.offsetWidth;
} return myWidth; }



function getclientHeight() {
var myHeight=0;
if(window.innerHeight==undefined){
myHeight=document.documentElement.clientHeight;
} else {
myHeight=window.innerHeight;
} 
return myHeight; 
}


function go(url){
window.location=url; 
}



function redirect(message, url){
var where_to= confirm(message);
if (where_to== true) {
window.location=url; 
}}



function switchvisibility(idstring){
hide_obj=document.getElementById(idstring);
if(hide_obj.style.visibility=='hidden'){
hide_obj.style.visibility='visible';
hide_obj.style.display='block';
} else {
hide_obj.style.visibility='hidden';
hide_obj.style.display='none';
}}




function left(str, n){
if (n <= 0) {
return ""; } else if (n > String(str).length) {
return str; } else {
return String(str).substring(0,n);}}


function load_GET_into_id(GETstring, idstring, imgstring){
if(imgstring!=undefined){document.getElementById(imgstring).style.display='block';}
req = false;
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else {
if(window.ActiveXObject) {
req = new ActiveXObject('Microsoft.XMLHTTP');
}} 
if (req) { 
req.onreadystatechange = function() {
if (req.readyState == 4) { 
document.getElementById(idstring).innerHTML= req.responseText;
if(imgstring!=undefined){ 
obj=document.getElementById(imgstring);
obj.style.display='none'; }
}} 
req.open('GET', GETstring, 'false'); 
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.send(null);}}





function load_POST_into_id(url, datastring, objectid, imgid){
if(imgid!=undefined){document.getElementById(imgid).style.display='block';}
req = false;
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else {
if(window.ActiveXObject) {
req = new ActiveXObject('Microsoft.XMLHTTP');
}} 
if (req) { 
req.onreadystatechange = function() {
if (req.readyState == 4) { 
document.getElementById(objectid).innerHTML= req.responseText;
if(imgid!=''){ 
obj=document.getElementById(imgid);
}
if(obj){ obj.style.display='none'; }
}} 
req.open('POST', url, 'false'); 
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.send(datastring);}}




function sendgetquery(GETstring, MSGstring){
req = false;
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else {
if(window.ActiveXObject) {
req = new ActiveXObject('Microsoft.XMLHTTP');
}} 
if (req) { 
req.onreadystatechange = function() {
if (req.readyState == 4) { 
if(MSGstring!=''){
alert(MSGstring);
}
}} 
req.open('GET', GETstring, 'false'); 
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.send(null);}}



function set_visible(idstring){
hide_obj=document.getElementById(idstring);
hide_obj.style.visibility='visible';
hide_obj.style.display='block';
}



function set_invisible(idstring){
hide_obj=document.getElementById(idstring);
hide_obj.style.visibility='hidden';
hide_obj.style.display='none';
}





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 createpopup(popject, x , y, width, fatherid){
destroypopup();
x=parseInt(x);y=parseInt(y);
obj=document.getElementById(popject);
obj.style.display='block';
obj.style.left=x;obj.style.top=y;
obj.style.width=width;
current_popup.id=popject;
current_popup.screen_x1=x;current_popup.screen_y1=y;
current_popup.screen_x2=x+width;current_popup.screen_y2=y+parseInt(obj.offsetHeight);
current_popup.enabled=1;
current_popup.fatherid=fatherid;
}

function destroypopup(){
if(current_popup.enabled==1){
document.getElementById(current_popup.id).style.display='none';
current_popup.enabled=0;
current_popup.id='';
}}



function settab(object){
for (i=0; i<12; i++){
document.getElementById('tab' + i).className ='frontpage_art_tab';
}
object.className='frontpage_art_tab_active';
}


function shoutbox_post(){
load_POST_into_id('http://www.storm-artists.net/include/ajax/shoutbox_write.php', 'id=0&msg=' + document.shoutform.msg.value,  'shoutdata','shoutboxload');
document.shoutform.msg.value='';
}

function shoutbox_refresh(){
load_POST_into_id('http://www.storm-artists.net/include/ajax/shoutbox_write.php','id=0', 'shoutdata','shoutboxload');
}






function switchprev(object, commentid){
pholder=document.getElementById('previewcontent' + commentid);
switch(object.value){
case 'Edit':
object.value='Preview';
pholder.innerHTML=object.form.htmldataholder.value;
object.form.msg.value=object.form.dataholder.value;
break;
case 'Preview':
object.form.dataholder.value=object.form.msg.value;
object.form.htmldataholder.value=pholder.innerHTML;
comment_preview('previewcontent' + commentid, object.form.msg.value, object, commentid);
break;
}
}




function reply(commentid){

if(current_replybox!=''){
document.getElementById('message' + current_replybox).innerHTML='';
}
current_replybox=commentid;

document.getElementById('message' + commentid).innerHTML=" \
<div class='container_block_header'>Quick Reply</div> \
<div class='container_block'> \
<form id='postreply" + commentid + "' action='http://comments.storm-artists.net/post_reply.php' method='post'> \
<div style='float:right;'> \
[<a class='textlink' onclick='unreply();'>x</a>]<br/> \
</div> \
<table cellpadding=0 cellspacing=0 width=100%><tr><td valign=top> \
<div align='left'> \
<img src=http://img.storm-artists.net/text/button_link.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", get_linkcode());' onmouseover='start_message(\"Insert a hyperlink into your message.\",150);' onmouseout='stop_message();'> \
<img src=http://img.storm-artists.net/text/button_image.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", get_imagecode());' onmouseover='start_message(\"Insert an image into your message.\",150);' onmouseout='stop_message();'>&nbsp; \
<img src=http://img.storm-artists.net/text/button_underline.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \"[u][/u]\");' onmouseover='start_message(\"Make a block of text underlined.\",150);' onmouseout='stop_message();'> \
<img src=http://img.storm-artists.net/text/button_bold.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \"[b][/b]\");' onmouseover='start_message(\"Make a block of text bold.\",150);' onmouseout='stop_message();'> \
<img src=http://img.storm-artists.net/text/button_italic.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \"[i][/i]\");' onmouseover='start_message(\"Make a block of text italic.\",150);' onmouseout='stop_message();'>&nbsp; \
<img src=http://img.storm-artists.net/text/button_left.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \"[left][/left]\");' onmouseover='start_message(\"Align block of text to the left.\",150);' onmouseout='stop_message();'> \
<img src=http://img.storm-artists.net/text/button_center.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \"[center][/center]\");' onmouseover='start_message(\"Align block of text to the center.\",150);' onmouseout='stop_message();'> \
<img src=http://img.storm-artists.net/text/button_right.gif style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \"[right][/right]\");' onmouseover='start_message(\"Align block of text to the right.\",150);' onmouseout='stop_message();'> \
</div> \
<div name='previewcontent' id ='previewcontent" + commentid + "' style='height:150px;text-align:left;'> \
<textarea class='text' name='msg' id='textbox" + commentid + "' style='width:100%;'></textarea> \
</div> \
</td> \
<td width=150 valign=bottom> \
<div align=center> \
<b>Emoticons:</b><br/><br/> \
<img src='http://img.storm-artists.net/emoticons/blush.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":blush:\");'> \
<img src='http://img.storm-artists.net/emoticons/frown.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":frown:\");'> \
<img src='http://img.storm-artists.net/emoticons/grin.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":grin:\");'> \
<img src='http://img.storm-artists.net/emoticons/grr.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":grr:\");'><br/> \
<img src='http://img.storm-artists.net/emoticons/nuu.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":nuu:\");'> \
<img src='http://img.storm-artists.net/emoticons/ooh.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":ooh:\");'> \
<img src='http://img.storm-artists.net/emoticons/razz.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":razz:\");'> \
<img src='http://img.storm-artists.net/emoticons/wink2.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":wink2:\");'><br/> \
<img src='http://img.storm-artists.net/emoticons/XP.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":XP:\");'> \
<img src='http://img.storm-artists.net/emoticons/XD.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":XD:\");'> \
<img src='http://img.storm-artists.net/emoticons/yay2.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":yay2:\");'> \
<img src='http://img.storm-artists.net/emoticons/smile.gif' style='cursor:pointer;' onclick='add_to_textarea(\"textbox" + commentid + "\", \":smile:\");'> \
<br/><br/><a href='javascript:showemoticons();' class='textlink' tabindex='-1'>More smileys</a><br/><br/> \
<br/> \
<input type='button' class='button' value='Preview' style='width:60px;' tabindex='-1' onclick='switchprev(this," + commentid + ");'> \
<input type='hidden' name='id' value='" + commentid + "'> \
<input type='hidden' name='htmldataholder'> \
<input type='hidden' id='dataholder' name='dataholder'> \
<input type='button' value='Post' class='button' style='width:60px;' onclick='postreply(" + commentid + ", this.form.msg.value, this.form.dataholder.value);'> \
</div> \
</td></tr></table> \
</form>";
}

function unreply(){
if(current_replybox!=''){
document.getElementById('message' + current_replybox).innerHTML='';
}
current_replybox='';
}
