function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue 
                  + myField.value.substring(endPos, myField.value.length);
	myField.selectionStart = startPos;
	myField.selectionEnd = endPos;
  } else {
    myField.value += myValue;
  }
}

function findPos(obj) {
	var curleft = curtop = 0;
if (obj.offsetParent) {
do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];
}
}

function displaySwitch(showID, hideID)
{
	document.getElementById(showID).style.display = 'block';
	document.getElementById(hideID).style.display = 'none';
}

function displayNone(elementID)
{

}

function confirmation(myForm, myAlert) {
	var answer = confirm(myAlert);
	if (answer){
		myForm.submit();
	}
}

function edit_event(eventID)
{
	document.edit_event_form.edit_event_subject.value = document.getElementById('title'+eventID).innerHTML;
	document.edit_event_form.edit_event_desc.value = document.getElementById('desc'+eventID).innerHTML;
	document.edit_event_form.wallstLiveID.value = eventID;

	return;
}
 
function add_link(textbox, linkURL, link_display)
{
	textbox.value = textbox.value + '<a href="'+linkURL.value+'">'+link_display.value+'</a>';
}
 
function displayBox(obj, box) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} 
		while (obj = obj.offsetParent);
	}

	document.getElementById(box).style.left = curleft+'px';
	document.getElementById(box).style.top = curtop+'px';
	document.getElementById(box).style.display = 'block';
	document.getElementById('iframe').style.left = document.getElementById(box).style.left;
	document.getElementById('iframe').style.top = document.getElementById(box).style.top;
	document.getElementById('iframe').style.width = document.getElementById(box).offsetWidth;
	document.getElementById('iframe').style.height = document.getElementById(box).offsetHeight;
	document.getElementById('iframe').style.zIndex = document.getElementById(box).style.zIndex;
	document.getElementById('iframe').style.display = 'block';
	document.getElementById('blockoutBg').setAttribute('activeBox', box);
	document.getElementById('blockoutBg').style.height = getPageHeight();
	document.getElementById('blockoutBg').style.width = getPageWidth();
	document.getElementById('blockoutBg').style.display = 'block';			
}

function hideBox(box) {				
	document.getElementById(box).style.display = 'none';
	document.getElementById('iframe').style.display = 'none';
	document.getElementById('blockoutBg').style.display = 'none';
}

function getPageWidth(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		xWithScroll = document.body.offsetWidth;
  	}
	return xWithScroll+'px'
}
function getPageHeight(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
  	}
	return yWithScroll+'px';
}
 
function clearText(thefield)
		{
			if (thefield.defaultValue==thefield.value)
			{
				thefield.value = ""
				thefield.style.color = "black";
			}
		}

function setCheckboxes(the_form, do_check)
{
	var elts      = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;
	
    for (var i = 0; i < elts_cnt; i++) {
        elts[i].checked = do_check;
		if (the_form + "_submit" == elts[i].name) {
			elts[i].disabled = !do_check;
		}
    } // end for

    return true;
} // end of the 'setCheckboxes()' function

function setCheckbox(the_form)
{
    var elts      = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;
    
    var allUnchecked = true;
	
    for (var i = 0; i < elts_cnt; i++)
    {
        if(elts[i].checked) allUnchecked = false;
    }
    
    for (var i = 0; i < elts_cnt; i++)
    {
        if(elts[i].name == (the_form + "_submit")) elts[i].disabled = allUnchecked;
    }

    return true;
}


var win = "width=500,height=600,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
function get_gallery(id_prof)
{
   window.open("photos_gallery.php?ID="+id_prof,'gallery',win);
}

function launchTellFriend ()
{   
    var win = "width=300,height=300,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php",'tellfriend',win);
    return false;
}

function launchTellFriendProfile ( sID )
{
    var win = "width=300,height=300,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php?ID="+sID,'tellfriendprofile',win);
    return false;
}

function ShowShowHide ( show_name, show_name2, hide_name )
{
    if (hide_name) hide_name.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
    if (show_name2) show_name2.style.display = 'inline';
}

function ShowHideHide ( show_name, hide_name, hide_name2 )
{
    if (hide_name) hide_name.style.display = 'none';
    if (hide_name2) hide_name2.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
}


/**
 * change images onHover mouse action
 */
function show(FileName,jpg1Name)
{
	document.images[FileName].src = jpg1Name;
}

/**
 * set status of the browser window to 's'
 */
function ss(s) 
{
	window.status = s;
	return true;
}

/**
 * set status of the browser window to empty
 */
function ce()
{
	window.status='';
}


/**
 * insert emotion item
 */
function emoticon( txtarea, text ) {

	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function launchAddToIM (id)
{
    var win = "width=600,height=160,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
    window.open("explanation.php?explain=imadd&ID="+id,'add_to_im',win);
    return false;
}

function docOpen(text)
{
	newWindow=window.open('','','toolbar=no,resizable=yes,scrollbars=yes,width=400,height=300');
	newWindow.document.open("text/html");
	newWindow.document.write(unescape(text));
	newWindow.document.close();
}
//######################################################################

	var NicknameInput_ID = 'Login_NickName';
	var NicknameInput_isEmpty = true;
	var NicknameInput_emptyBackground;
	var NicknameInput_nonEmptyBackground;
	
	/*
	var NicknameInput_emptyColor = 'rgb(170, 170, 170)';
	var NicknameInput_nonEmptyColor = 'rgb(0, 0, 0)';
	var NicknameInput_emptyText = 'Nickname';
	*/

	var PasswordInput_ID = 'Login_Password';
	var PasswordInput_isEmpty = true;
	var PasswordInput_emptyBackground;
	var PasswordInput_nonEmptyBackground;
	
	/*
	var PasswordInput_emptyColor = 'rgb(170, 170, 170)';
	var PasswordInput_nonEmptyColor = 'rgb(0, 0, 0)';
	var PasswordInput_emptyText = 'Password';
	var PasswordInput_emptyType = 'text';
	var PasswordInput_nonEmptyType = 'password';
	*/

	function NicknameInput_init(sEmptyBackground, sNonEmptyBackground)
	{
	    var elt = document.getElementById(NicknameInput_ID);
	    
	    NicknameInput_emptyBackground = 'url('+sEmptyBackground+')';
	    NicknameInput_nonEmptyBackground = 'url('+sNonEmptyBackground+')';
	
	    elt.style.backgroundImage = NicknameInput_emptyBackground;
	}
	
	function PasswordInput_init(sEmptyBackground, sNonEmptyBackground)
	{
	    var elt = document.getElementById(PasswordInput_ID);
	    
	    PasswordInput_emptyBackground = 'url('+sEmptyBackground+')';
	    PasswordInput_nonEmptyBackground = 'url('+sNonEmptyBackground+')';

	    elt.style.backgroundImage = PasswordInput_emptyBackground;
	}
	
	function NicknameInput_onfocus()
	{
	    var elt = document.getElementById(NicknameInput_ID);
	
	    if (NicknameInput_isEmpty)
	    {
	        elt.style.backgroundImage = NicknameInput_nonEmptyBackground;
	    }
	
	    return true;
	}
	
	function PasswordInput_onfocus()
	{
	    var elt = document.getElementById(PasswordInput_ID);
	
	    if (PasswordInput_isEmpty)
	    {
	        elt.style.backgroundImage = PasswordInput_nonEmptyBackground;
	    }
	
	    return true;
	}
	
	function NicknameInput_onblur()
	{
	    var elt = document.getElementById(NicknameInput_ID);
	
	    if (elt.value == '')
	    {
	        elt.style.backgroundImage = NicknameInput_emptyBackground;
	        NicknameInput_isEmpty = true;
	    } else {
	        NicknameInput_isEmpty = false;
	    }
	
	    return true;
	}
	
	function PasswordInput_onblur()
	{
	    var elt = document.getElementById(PasswordInput_ID);
	
	    if (elt.value == '')
	    {
	        elt.style.backgroundImage = PasswordInput_emptyBackground;
	        PasswordInput_isEmpty = true;
	    } else {
	        PasswordInput_isEmpty = false;
	    }
	
	    return true;
	}
	
///////////////////////////////////////////////////////////////////NAVBAR SWITCH/////////////////////////////////////////////////////////////////////

function popitup(url)
{
	newwindow=window.open(url);
	if (window.focus) {newwindow.focus()}
	return false;
}


function showNavbar(source)
{
	if (source == "mywallst")
	{ 
	  document.getElementById('mywallst').className='active_tab';
	  document.getElementById('mywallst_l').className='active_tab_l';
	  document.getElementById('mywallst_r').className='active_tab_r';
	  document.getElementById('wallst').className='inactive_tab';
	  document.getElementById('wallst_l').className='inactive_tab_l';
	  document.getElementById('wallst_r').className='inactive_tab_r';
	  document.getElementById('radio').className='inactive_tab';
	  document.getElementById('radio_l').className='inactive_tab_l';
	  document.getElementById('radio_r').className='inactive_tab_r';
	  document.getElementById('tv').className='inactive_tab';
	  document.getElementById('tv_l').className='inactive_tab_l';
	  document.getElementById('tv_r').className='inactive_tab_r';	  
	  document.getElementById('mywallst_links').style.display="block";
	  document.getElementById('wallst_links').style.display="none";
	  document.getElementById('radio_links').style.display="none";
	  document.getElementById('tv_links').style.display="none";
	}
	else if ( source == "wallst")
	{	 
	  document.getElementById('mywallst').className='inactive_tab';
	  document.getElementById('mywallst_l').className='inactive_tab_l';
	  document.getElementById('mywallst_r').className='inactive_tab_r';
	  document.getElementById('wallst').className='active_tab';
	  document.getElementById('wallst_l').className='active_tab_l';
	  document.getElementById('wallst_r').className='active_tab_r';
	  document.getElementById('radio').className='inactive_tab';
	  document.getElementById('radio_l').className='inactive_tab_l';
	  document.getElementById('radio_r').className='inactive_tab_r';
	  document.getElementById('tv').className='inactive_tab';
	  document.getElementById('tv_l').className='inactive_tab_l';
	  document.getElementById('tv_r').className='inactive_tab_r';	  
	  document.getElementById('mywallst_links').style.display="none";
	  document.getElementById('wallst_links').style.display="block";
	  document.getElementById('radio_links').style.display="none";
	  document.getElementById('tv_links').style.display="none";
	}
	else if ( source == "radio")
	{
	  document.getElementById('mywallst').className='inactive_tab';
	  document.getElementById('mywallst_l').className='inactive_tab_l';
	  document.getElementById('mywallst_r').className='inactive_tab_r';
	  document.getElementById('wallst').className='inactive_tab';
	  document.getElementById('wallst_l').className='inactive_tab_l';
	  document.getElementById('wallst_r').className='inactive_tab_r';
	  document.getElementById('radio').className='active_tab';
	  document.getElementById('radio_l').className='active_tab_l';
	  document.getElementById('radio_r').className='active_tab_r';
	  document.getElementById('tv').className='inactive_tab';
	  document.getElementById('tv_l').className='inactive_tab_l';
	  document.getElementById('tv_r').className='inactive_tab_r';
	  document.getElementById('mywallst_links').style.display="none";
	  document.getElementById('wallst_links').style.display="none";
	  document.getElementById('radio_links').style.display="block";
	  document.getElementById('tv_links').style.display="none";
	}	
	else if ( source == "tv")
	{
	  document.getElementById('mywallst').className='inactive_tab';
	  document.getElementById('mywallst_l').className='inactive_tab_l';
	  document.getElementById('mywallst_r').className='inactive_tab_r';
	  document.getElementById('wallst').className='inactive_tab';
	  document.getElementById('wallst_l').className='inactive_tab_l';
	  document.getElementById('wallst_r').className='inactive_tab_r';
	  document.getElementById('radio').className='inactive_tab';
	  document.getElementById('radio_l').className='inactive_tab_l';
	  document.getElementById('radio_r').className='inactive_tab_r';
	  document.getElementById('tv').className='active_tab';
	  document.getElementById('tv_l').className='active_tab_l';
	  document.getElementById('tv_r').className='active_tab_r';
	  document.getElementById('mywallst_links').style.display="none";
	  document.getElementById('wallst_links').style.display="none";
	  document.getElementById('radio_links').style.display="none";
	  document.getElementById('tv_links').style.display="block";
	}	
 
}

function movieBtnOver(source)
{
	if (document.getElementById(source).className == "inactive_mov")
	{
		document.getElementById(source).className = "hover_mov";
	}	
}

function movieBtnOut(source)
{
	if (document.getElementById(source).className == "hover_mov")
	{
		document.getElementById(source).className = "inactive_mov";
	}	
}

function joinOver(){
document.images["joinNow"].src = "http://my.wallst.net/templates/tmpl_dfl/images/join_now2.gif"; 
}
function joinOut(){
document.images["joinNow"].src = "http://my.wallst.net/templates/tmpl_dfl/images/join_now.gif"; 
}
function logOver(){
document.images["memLogin"].src = "http://my.wallst.net/templates/tmpl_dfl/images/mem_login2.gif"; 
}
function logOut(){
document.images["memLogin"].src = "http://my.wallst.net/templates/tmpl_dfl/images/mem_login.gif"; 
}
function logOpen(){
document.getElementById('logForm').style.display="block";
document.getElementById('logTab').style.display="block";
}
function logClose(){
document.getElementById('logForm').style.display="none";
document.getElementById('logTab').style.display="none";
}

//generic javascript search
function search(value, type, page, div, indicator, total)
{
	new Ajax.Updater(div, page, 
	{			
		onLoading:function(request)
		{
			Element.show(indicator);
		}, 
		onComplete:function(request)
		{
			Element.hide(indicator);
			//setTimeout("fixHeight()",700);
		}, 
		parameters:'action=search&value='+value+'&type='+type+'&total='+total, 
		evalScripts:true, 
		asynchronous:true
	})		
}

//clears textfield with value
function clearText(thefield)
{
	if (thefield.defaultValue==thefield.value)
	{
		thefield.value = ""
		thefield.style.color = "black";
	}
} 

function hideDiv(div)
{
	document.getElementById(div).style.display='none';
}

function showDiv(div)
{
	document.getElementById(div).style.display='block';
}