var OutFlag = 0;
//var GrumpFlag = 0;
var RightBarHTML = ''
var RightBarFlag = true;
var HtmlForShow = [];

function ChangeReplyToText(Commentor,CommentTo)
	{
	if (Login_Flag == 'true')
		{
		document.getElementById('replytext').innerHTML = '<span class="bigins">Reply to '+Commentor+':</span>';
		document.addresponse.parentcomment.value  = CommentTo;	
		JumpScroll('addresponse');
		}
	else
		{
		RegisterScreen('gencont');	
		}
	}

function ShowLoginBox(html)
	{
	document.getElementById('loginbox').innerHTML = html;
	}

function SiteSearchSelect()
	{

	if (document.getElementById('sitesearch').value == 'Search Grumper')
		{
		document.getElementById('sitesearch').focus(); 
		document.getElementById('sitesearch').select();
		}
	}
	
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
	
function StartSubmitGrump(guid, score)
{
	var button = document.getElementById('button_' + guid);
	if(button.className == 'grumpsb')
		return;

	var xmlObject = GetXmlHttpObject();
	if(xmlObject == null) // no ajax support
	{
		SubmitGrumpOld(guid,score);
		return;
	}
	var url = 'grump.php' + '?guid=' + guid;
	xmlObject.onreadystatechange=function()
	{
		if(xmlObject.readyState == 4)
		{
			button.innerHTML = '<span class="greyout">grumped</span>';
			score = score + 1;
			document.getElementById('score_'+guid).innerHTML = '<span class="dgrumps">'+ score + '</span><br /><span class="sgrumps">grumps</span>';
		}
	};
	xmlObject.open("GET", url, true);
	xmlObject.send(null);
	
	button.className ='grumpsb';
}

function SubmitGrumpOld(guid,score)
	{
	var button = document.getElementById('button_' + guid);
	document['form_'+guid].submit();
	button.innerHTML = '<span class="greyout">grumped</span>';
	score = score + 1;
	document.getElementById('score_'+guid).innerHTML = '<span class="dgrumps">'+ score + '</span><br /><span class="sgrumps">grumps</span>';
	button.className ='grumpsb';
	}
	
function LoginScreen(container)
	{
	grayOut(true);
	document.getElementById(container).innerHTML = '<div id="login_popup" class="popup_screen"><div class="popup_title">You have to login to do that!</div><div class="x_close"><a class="silent" href="#" onclick=CloseScreen(\''+container+'\')>X</a></div><br /><br /><form action="" method="post" enctype="application/x-www-form-urlencoded" name="login"><span class="bigins"><div style="float:left;width:100px;">Username:</div><div style="float:left;"><input id = "username" class="stylish_form" name="username" type="text" value="" size="10" maxlength="30" /></div><br /><div style="float:left;width:100px;">Password:</div><div style="float:left;"><div style="float:left;"><input id = "password" class="stylish_form" name="password" type="password" value="" size="10" maxlength="32" /></div></span><br /><div  style="margin-left:10px;float:left;"><a href="javascript:document.login.submit();"><img border="0" alt="go" src="images/go.gif"/></a></div><input type="submit" style="width:0px;height:0px;border:none" /></form><br /><br /><span class="headblack"><a href="javascript:RegisterScreen(\''+container+'\');">Not registered? Click here to create an account</a></span></div>';
	document.getElementById('login_popup').style.zIndex = 55;
	document.getElementById('login_popup').style.left = (screen.width/2 - 200)+"px";
	}

function RegisterScreen_long(container)
	{
	document.getElementById(container).innerHTML = '<div id="register_popup" name="register_popup" class="popup_screen"><div class="popup_title">You must be registered to do that!</div><div class="x_close"><a class="silent" href="#" onclick=CloseScreen(\''+container+'\')>X</a></div><br /><br />It only takes a second<br /><form action="register.php" method="post" enctype="multipart/form-data" name="register"><br /><table cellspacing="3" cellpadding="0"><tr><td width="200" valign="top"><span class="ClearText">Desired Username: </span></td><td><input name="r_username" id="r_username"  maxlength="30" type="text" value="" size="20" /></td></tr><tr><td><span class="ClearText">Password:</span></td><td><input name="password" id="password" type="password"  maxlength="32" value="" size="20" /><br /></td></tr><tr><td><span class="ClearText">Repeat Password:</span></td><td><input name="rpassword" id="rpassword" type="password"  maxlength="32" value=""  size="20" /><br /></td></tr><tr><td><span class="ClearText">Email Address:</span></td><td><input name="email" type="text"  maxlength="50" value=""  size="20" /><br /></td></tr><tr><td><span class="ClearText">First Name:</span></td><td><input name="fname" id="fname"  maxlength="20" type="text" value=""  /><br /></td></tr><tr><td><span class="ClearText">Last Name:</span></td><td><input name="lname" id="lname"  maxlength="30" type="text" value=""  /><br /></td></tr><tr><td><span class="ClearText">Age:</span></td><td><input name="age" id="age"  maxlength="2" type="text" size="3" value="" /><br /></td></tr><tr><td><input type="hidden" name="ref" id="ref" value="" /></td></tr></table><input name="rterms" type="checkbox" value="CHECK" /> I agree to the <a target="_blank" href="terms.php">Terms of Use</a> and <a target="_blank" href="privacy.php">Privacy Policy</a><br /><input name="rsubmit" type="submit" value="Continue" /></form><br /><br /><span class="headblack"><a href="javascript:LoginScreen(\''+container+'\');">Already Registered? Click here to login</a></span></div>';
	//JumpScroll('register_popup');
	}
	
function RegisterScreen(container)
	{
		
	window.location = "http://www.grumper.org/register.php";
//	if (IE6_Flag == 'true')
//		{
//		window.location = "http://www.grumper.org/register.php";
//		}
//	else
//		{
//		grayOut(true);
//		document.getElementById(container).innerHTML = '<div id="register_popup" name="register_popup" class="popup_screen"><div class="popup_title">You must be registered to do that!</div><div class="x_close"><a class="silent" href="#" onclick=CloseScreen(\''+container+'\')>X</a></div><br /><br />It only takes a second<br /><form action="register.php" method="post" enctype="multipart/form-data" name="register"><br /><table cellspacing="3" cellpadding="0"><tr><td width="200" valign="top"><span class="ClearText">Desired Username: </span></td><td><input name="r_username" id="r_username"  maxlength="30" type="text" value="" size="20" /></td></tr><tr><td><span class="ClearText">Password:</span></td><td><input name="password" id="password" type="password"  maxlength="32" value="" size="20" /><br /></td></tr><tr><td><span class="ClearText">Repeat Password:</span></td><td><input name="rpassword" id="rpassword" type="password"  maxlength="32" value=""  size="20" /><br /></td></tr><tr><td><span class="ClearText">Email Address:</span></td><td><input name="email" type="text"  maxlength="50" value=""  size="20" /><br /></td></tr><tr><tr><td><span class="ClearText">Repeat Email:</span></td><td><input name="remail" type="text"  maxlength="50" value=""  size="20" /><br /></td></tr><tr><tr><td><input type="hidden" name="ref" id="ref" value="" /></td></tr></table><input name="rterms" type="checkbox" value="CHECK" /> I agree to the <a target="_blank" href="terms.php">Terms of Use</a> and <a target="_blank" href="privacy.php">Privacy Policy</a><br /><input name="rsubmit" type="submit" value="Continue" /></form><br /><br /><span class="headblack"><a href="javascript:LoginScreen(\''+container+'\');">Already Registered? Click here to login</a></span></div>';
//		//JumpScroll('register_popup');
//		document.getElementById('register_popup').style.left = (screen.width/2 - 200)+"px";
//		document.getElementById('register_popup').style.zIndex = 55;
//		
//		}
	}
	
function ConfirmDelete(container,url)
	{
	grayOut(true);
	document.getElementById(container).innerHTML = '<div id="confirmDelete_popup" name="confirmDelete_popup" class="popup_screen_short"><br /><div class="popup_title">Are you sure to delete this?</div><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Yes" onclick="window.location=\''+url+'\'" />&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="No" onclick=CloseScreen(\''+container+'\') /><br /><br /></div>';
		//JumpScroll('register_popup');
	document.getElementById('confirmDelete_popup').style.zIndex = 55;
	}
	
function FlagScreen(guid,type,offender)
	{
	if (Login_Flag == 'true')
		{
		document.getElementById('flag_'+guid).innerHTML = '<div class="popup_screen"><div class="popup_title">Report this as Inappropriate</div><div class="x_close"><a class="silent" href="#" onclick=CloseScreen(\'flag_'+guid+'\')>X</a></div> Please tell us why this is inappropriate, choose the reason from the drop down list<br /><form action="#label_'+guid+'" method="post" enctype="mutlipart/form-data"><select name="flag_options" id="flag_options"><option value="null" selected="selected">Select a reason </option><option value="slander">Slandering my brand</option><option value="sexual">Sexual Content</option><option value="abuse">Abusive towards site user</option><option value="racism">Racism or hatred</option><option value="spam">Spam</option><option value="copyright">Infringes my copyright</option></select><br />Tell us more: (optional)<br><textarea name="flag_more" cols="25" rows="3" id="flag_more"></textarea><br /><input type="hidden" name="flag_offender" id="flag_offender" value="'+offender+'" /><input type="hidden" name="flag_guid" id="flag_guid" value="'+guid+'" /><input name="flag_type" id="flag_type" type="hidden" value="'+type+'" /><input name="flag_submit" type="submit" value="Send Report"></form></div>';	
		}
	else
		{
		document.getElementById('flag_'+guid).innerHTML = '<div class="popup_screen"><div class="popup_title">You must be registered and logged in to flag</div><div class="x_close"><a class="silent" href="#" onclick=CloseScreen(\'flag_'+guid+'\')>X</a></div>';
		}
	}

function CloseScreen(guid)
	{
	grayOut(false);
	document.getElementById(guid).innerHTML = '';
	}
	
function TabBehavior(Zone,Html)
	{
	document.getElementById(Zone).innerHTML = Html;
	}
	
function FinalApprove()
	{
	document.preview.approve.value = 1;
	document.preview.step.value = 3;
	document.preview.submit();
	}
	
function ShowRightBar()
	{
	RightBarFlag = true;
	document.getElementById("rightbar").innerHTML = RightBarHTML;
	}
	
function DDMenuOpen(Zone,Html)
	{
//	if (Zone == 'menu_life' && RightBarFlag)
//		{
//		RightBarFlag = false;
//		RightBarHTML = document.getElementById("rightbar").innerHTML;
//		document.getElementById("rightbar").innerHTML = "";
//		}
	document.getElementById(Zone).innerHTML = Html;
	}

function DDMenuClose(Zone,e)
	{
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.toElement;
	if (relTarg.id.search('menu') == -1)
		{
//		if (Zone == 'menu_life')
//			{
//			setTimeout("ShowRightBar();",1000);
//			}
		document.getElementById(Zone).innerHTML = '';	
		}
	else
		{
		
		}
	}


function MailSelectAll(MailIDs)
	{
	for (i in MailIDs)
		{
		document.getElementById('delete_mail_'+MailIDs[i]).checked = true;	
		}
	}

function JumpScroll(div) 
	{
 	window.scroll(0,document.getElementById(div).offsetTop); // horizontal and vertical scroll targets
	}


 function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';  
  } else {
     dark.style.display='none';
  }
}

function HideGrumps(userId,username,count)
{
	document.getElementById('hidden_grumps_' + userId).innerHTML = '';
	document.getElementById('new_grumps_show_' + userId).innerHTML = '<div class="smallline_more_link"><a class="ShowMoreTitle" rel="nofollow" onmouseover="this.style.cursor=\'pointer\';" onclick="ShowGrumps(\''+ userId +'\',HtmlForShow[\''+ userId +'\'],\''+username+'\','+count+')" >Show '+count+' more by '+username+'</a></div>';
}

function ShowGrumps(userId,html,username,count)
{
	//document.getElementById(userId + '_new_grumps_header').style.display = 'block';
	document.getElementById('hidden_grumps_' + userId).innerHTML = html;
	ShowHtml = document.getElementById('new_grumps_show_' + userId).innerHTML;
	document.getElementById('new_grumps_show_' + userId).innerHTML = '<div class="smallline_more_link"><a class="ShowMoreTitle" rel="nofollow" onmouseover="this.style.cursor=\'pointer\';" onclick="HideGrumps(\''+ userId +'\',\''+username+'\','+count+')" >Hide new grumps by '+username+'</a></div>';
//	document.getElementById('new_grumps_show_' + userId).style.margin = '0px';
//	document.getElementById('new_grumps_show_' + userId).style.padding = '0px';
//	document.getElementById('new_grumps_show_' + userId).style.height = '0px';
	
}