
function popitup(url) {
	newwindow=window.open(url,'name','height=600,width=924,scrollbars=no,location=yes,menubar=yes,status=yes,toolbar=yes,resizable=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}

function checkHelp ()
{
if(Get_Cookie('HelpView') == 'off') 
	{
		toggleHelpView();
	}
}

function toggleHelpView()
{	
/*
	   if ( typeof toggleHelpView.topHTML == 'undefined' ) {
        // It has not... perform the initilization
        toggleHelpView.topHTML = "";
		Set_Cookie( 'HelpView', 'on', 1000 * 60 * 60 * 24 * 30, '/', '', '' )
		}
  */
  
  var innerHelp = document.getElementById("innerHelpHtml");
  var SH = document.getElementById("showHideLink");

  if (innerHelp.innerHTML.length > 20)
  {
	  toggleHelpView.topHTML = innerHelp.innerHTML;
	  innerHelp.innerHTML = "";
	  SH.innerHTML = "<a href='javascript:toggleHelpView()'>Show</a>";
	  Set_Cookie( 'HelpView', 'off', '30', '/', '', '' )
	  
  }
  else
  {
	  
	  innerHelp.innerHTML = toggleHelpView.topHTML;
	  toggleHelpView.topHTML = "";
	  SH.innerHTML = "<a href='javascript:toggleHelpView()'>Hide</a>"; 
	  Set_Cookie( 'HelpView', 'on', '30', '/', '', '' )
  }
  
  resizeIframe();
	
	
}

function kRadioToggle()
{
	var kRadio = document.getElementById("kRadio");
	var kStyle = kRadio.style;
	if(kRadio.style.backgroundColor = "#FFFFCC")
	{
		kRadio.style.backgroundColor = "#FFFFFF";
	}
	else
	{
		kRadio.style.backgroundColor = "#FFFFCC";
	}
}


function postForm(dir)
{
	
	var d; 
	
	d = document.getElementById('direction');

	d.value = dir;
	
	var f = document.getElementById('editFields');

	f.submit();
}


// JavaScript Document

<!-- ALWAYS ON TOP FLOATING LAYER POP-UP -->


<!-- Copyright 2003, Sandeep Gangadharan -->
<!-- For more free scripts go to http://sivamdesign.com/scripts/ -->

var y1 = 200;   // change the # on the left to adjuct the Y co-ordinate
(document.getElementById) ? dom = true : dom = false;

function hideIt() {
  if (dom) {
  document.getElementById("messageLayer").style.visibility='hidden';
  
  }
}

function showIt() {
  if (dom) {
  document.getElementById("messageLayer").style.visibility='visible';
  
  
  
  }
  
  
}

function placeIt() {
  if (dom && !document.all) {
  document.getElementById("messageLayer").style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1)) + "px";}
  if (document.all) {
  document.all["messageLayer"].style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - (document.documentElement.clientHeight-y1)) + "px";}
  window.setTimeout("placeIt()", 10); }


function basename (path, suffix) {
    // Returns the filename component of the path  
    // 
    // version: 910.820
    // discuss at: http://phpjs.org/functions/basename    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');    // *     returns 1: 'home'
    // *     example 2: basename('ecra.php?p=1');
    // *     returns 2: 'ecra.php?p=1'
    var b = path.replace(/^.*[\/\\]/g, '');
        if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function URLDecode(url) //function decode URL
{
// Replace + with ' '
// Replace %xx with equivalent character
// Put [ERROR] in output if %xx is invalid.

 if(url == null) {return;}

var HEXCHARS = "0123456789ABCDEFabcdef";

var encoded = url;

var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2)
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
alert( 'Bad escape combination near ...' + encoded.substr(i) );
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while

return plaintext;
}; 

var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = URLDecode(val);

}
}
} 

/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.1.2
Last Update: 5 November 2009

Changes:
1.1.2 explicitly declares i in Get_Cookie with var
1.1.1 fixes a problem with Get_Cookie that did not correctly handle case
where cookie is initialized but it has no "=" and thus no value, the 
Get_Cookie function generates a NULL exception. This was pointed out by olivier, thanks
1.1.0 fixes a problem with Get_Cookie that did not correctly handle
cases where multiple cookies might test as the same, like: site1, site
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



function showEval() 
{	
	var c;
	
	if(qsParm['resultMsg']!=undefined)
	{
		showMessage(qsParm['resultMsg']);
	}
	else
	{
		c = URLDecode(Get_Cookie("rr_Msg"));
		if(c != null)
		{
			showMessage(c);
			Delete_Cookie("rr_Msg","/","retroread.com");		
		}
	}
}

function showMessageSpin(msg) {

var msgTag =      document.getElementById('message_box');
var uploadImage = document.getElementById('uploader');
msgTag.innerHTML = msg;
uploadImage.style.visibility = "visible";

  

showIt();

}



function showMessage(msg) {

var msgTag = document.getElementById('message_box');
msgTag.innerHTML = msg;
showIt();

}



function break_right(s,n)
{
	var l = s;
	var r = "";
	
	if(s.length > n)
	{
		l = s.substring(0,n);
		r = s.substring(n,100);
		l = l + "<br>" + break_right(r,n);
	}
	
	
	return l;
}
		





function showFileMessage()
{
	
	
if(Get_Cookie('rr_user') != null)
{	
	var ULfile = document.getElementById('file2UL');
	
	 
	
	var mymsg = 'Uploading <em><br /><br /><span style="color: chocolate">' + break_right(basename(ULfile.value),28) + '</span></em><br /><br />Please Wait';
	
	
	showMessageSpin(mymsg);
}
else
{	
	showMessage("<br /><br />Cookies must enabled to use this feature<br /><br />Enable Cookies and login again");		
}

}


function pokeEditFlag()
{
	
var eField = document.getElementById('editFlag');

eField.value = "edit";
	
var ULfile = document.getElementById('file2UL');

var mymsg = 'Uploading <em><br /><br /><span style="color:chocolate;">' + break_right(basename(ULfile.value),28) + '</span></em><br /><br />for editing<br /><br />please wait';



showMessageSpin(mymsg);
}





function resizeIframe() {
   
	var height = document.documentElement.clientHeight;
	if(height == 0) { height = document.body.clientHeight; }
	
	
	// alert("height is: " + height);
    height = height - document.getElementById('frame').offsetTop;
   
    // not sure how to get this dynamically
    height = height - 20; /* whatever you set your body bottom margin/padding to be */
  
    document.getElementById('frame').style.height = height +"px";
    
};



// this will resize the iframe every
// time you change the size of the window.


