
//==============GLOBAL Vars===================
// Classic MouseOver Animation Function Created By Geo.

var sImgPath = "http://images3.stardock.com/gc2/T_DL/"; 	//Universal Path to Image Folder.  (UC_Header_LinkBar)
var strLoad; 						//Header Bar Global Var for storing StoryBoard vars (UC_Header_LinkBar)
var strNew;  						//Header Bar Global Var for storing StoryBoard vars (UC_Header_LinkBar)

//-=========================================

// This will detect your browser and allow only compatable
// browsers to use the "animBut" function by setting
// "browserVer" = 1 or 2 (2 = not compatable)

agent = navigator.userAgent;
var browserVer = 2;
if (agent.substring(0,7) == "Mozilla")
{
   if (parseInt(agent.substring(8,9)) >= 3) {browserVer = 1;}
}

function animBut(imgBase,imgLit) 
{
	if (browserVer == 1) 
	{
		document.images[imgBase].src = eval(imgLit + ".src")
	}
}
// ==============End Of RollOver Code====================

// Login Dialog Box Options ================================
function LoginFocus(item){
	if(item.value == ''){
		item.className='LoginBox_UserName';
	}
	//if(m_LoginPasswordTimerID==0){
	//   checkLoginPasswordField();
	//}
}
function LoginBlur(item){
	if(item.value == '')	{
		item.className='LoginBox_UserName LoginBox_UserName_BG';
	}else{
		item.className='LoginBox_UserName';
	}
}
function PasswordFocus(item){
	item.className='LoginBox_Password';
}
function PasswordBlur(item){
	if(item.value == '')	{
		item.className='LoginBox_Password LoginBox_Password_BG'
	}else{
		item.className='LoginBox_Password';
	}
}
// ============= End Login Dialog Functions ================


//=========Header Bar RollOver + Menu StoryBoard Code========
function setMenuState(state){
var menuOne = document.getElementById("ddl_headerlist01");
var menuTwo = document.getElementById("ddl_headerlist02");
	if (state == '1'){
		menuOne.style.visibility='visible';
		menuTwo.style.visibility='visible';
	}else{
		menuOne.style.visibility='hidden';
		menuTwo.style.visibility='hidden';
	}
}
function UpdateStoryBoard(id, option){
	var obj = document.getElementById(id);
	var str = obj.innerHTML;
	
	if(strLoad != '1'){
		strNew = obj.innerHTML;
		strLoad = 1;
	}
	if(option == '1'){
		obj.innerHTML = "<B>My Account</B><BR>This link will allow you to access details about your personal preferences and account information."
	}else if(option == '2'){
		obj.innerHTML = "<B>My Stats</B><BR>Sorry, this link is not available at this time."
	}else if(option == '3'){
		obj.innerHTML = "<B>Create Post</B><BR>This link will allow you to add to the GalCiv community with your own article that others can reply to."
	}else if(option == '4'){
		obj.innerHTML = "<B>Watch List</B><BR>This link allows you to keep track of articles of special interest."
	}else if(option == '5'){
		obj.innerHTML = "<B>My Posts</B><BR>Sorry, this link is not available at this time."
	}else{
			obj.innerHTML = strNew;
	}
}
//========End Header Bar RollOver + Menu StoryBoard Code=====

<!-- // load htmlarea
	_editor_url = "/htmlarea/";                     // URL to htmlarea files
	var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
	if (win_ie_ver >= 5.5) {
	document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
	document.write(' language="Javascript1.2"></scr' + 'ipt>');  
	} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// -->

// JScript source code
//function format_quote(ID) {
//  var str;

//	if (document.getSelection) {
//    str = document.getSelection();
//  } else if (document.selection && document.selection.createRange) {
//    var range = document.selection.createRange();
//    str = range.text;
//  } else {
//  }


//    str = str.replace(/\r\n/g, '<BR>');
//    strs = str.replace(/\n/g, '<BR>');
//    str = str.replace(/\r/g, '<BR>');
// <!--  str = str.replace(/\r\n/g, '\r' + "<BR><BR>");

//  str = "[quote]" + str + "[/quote]" + '\r\r';

//  editor_insertHTML(ID, str)

//  return;
//}

function format_quote(editorId)
{
   var str;

   if (document.getSelection) {
      str = document.getSelection();
   } 
   else if (document.selection && document.selection.createRange) {
      var range = document.selection.createRange();
      str = range.text;
   } 
   else {
   }

   str = str.replace(/\r\n/g, '<BR>');
   strs = str.replace(/\n/g, '<BR>');
   str = str.replace(/\r/g, '<BR>');

   str = "[quote]" + str + "[/quote]" + '\r\r';

   var config = document.getElementById(editorId).config;

   if(config.basic == false)
   {
      editor_insertHTML(editorId, str);
   }
   else
   {
      if(m_IE == true)
      {
         editor_insertHTML(editorId, str);
      }
      else
      {
         editor_formatselection(editorId, str, true);
      }
   }

   return;
}

function insert_link() {
  var str = document.selection.createRange().text;
  document.frmAddReply.message.focus();
  var my_link = prompt("Enter URL:","http://");
  if (my_link != null) {
    var sel = document.selection.createRange();
	if (str){
	sel.text = "<a class=\"content\" href=\"" + my_link + "\">" + str + "</a>";
	}else{
	sel.text = "<a class=\"content\" href=\"" + my_link + "\">link</a>";
	}
  }
  return;
}

function doInsert(ibTag, ibClsTag, isSingle)
{
var isClose = false;
var sel = document.selection;
var rng = sel.createRange();

rng.colapse;
	if((sel.type == "Text" || sel.type == "None") && rng != null){
		if(ibClsTag != "" && rng.text.length > 0)
			ibTag += rng.text + ibClsTag;
		else if(isSingle)

		isClose = true;
		rng.text = ibTag;
	}
return isClose;
}	


function Format_Selection(ID, sItem) {
	var sStr;

	if (window.getSelection) {
		var sStr = window.getSelection();
	} else if (document.selection && document.selection.createRange) {
		var range = document.selection.createRange();
		var sStr = range.text;
	} else {
	}

	//alert(navigator.userAgent);
	// Mozilla + Opera Browsers ====================================
	if (navigator.userAgent.indexOf('Gecko')>= 0) { 

		var objTextArea = document.getElementById(ID);
		var ss = objTextArea.selectionStart;
		var st = objTextArea.scrollTop;
		var es = objTextArea.selectionEnd;
		
		if (es <= 2){ es = objTextArea.textLength; }
		
		var start  = (objTextArea.value).substring(0, ss);
		var middle = (objTextArea.value).substring(ss, es);
		var end    = (objTextArea.value).substring(es, objTextArea.textLength);
		
		if (objTextArea.selectionEnd - objTextArea.selectionStart > 0){
			middle = "[" + sItem + "]" + middle + "[/" + sItem + "]";
		}
		else { alert("Sorry, unable to insert the HTML [" + sItem + "] tag.  No Text Has Been Highlighted."); }
		
		objTextArea.value = start + middle + end;
		
		return;
	} else if (navigator.userAgent.indexOf('Opera')>= 0) { return alert("Sorry, unable to insert the HTML [" + sItem + "] tag.  \n\nOpera browsers are not supported at this time."); }
	//=====================================================

 if (sStr == '') { return alert("Sorry, unable to insert the HTML [" + sItem + "] tag.  No Text Has Been Highlighted."); }

   	sStr = sStr.replace(/\r\n/g, '<BR>');
   	sStr = sStr.replace(/\n/g, '<BR>');
   	sStr = sStr.replace(/\r/g, '<BR>');
    	// sStr  = "[" + sItem + "]" + sStr  + "[/" + sItem + "]"; 

	doInsert("[" + sItem + "]" + sStr + "[/" + sItem + "]", "", false)

  return;
}

function InsertIMG(ID) {
	var sImgURL = prompt("Enter the URL to an image you wish to insert.","");
	sImgURL = "[img]" + sImgURL + "[/img]" + '\r\r';
  	editor_insertHTML(ID, sImgURL)
	return;
}

function InsertLink(ID) {
	var sLinkURL = prompt("Enter the URL of the link you wish to insert.","");
	sLinkURL = "[link]" + sLinkURL  + "[/link]" + '\r\r';
  	editor_insertHTML(ID, sLinkURL)
	return;
}

function InsertEmail(ID) {
	var sLinkURL = prompt("Enter the email address you wish to insert.","");
	sLinkURL = "[email]" + sLinkURL  + "[/email]" + '\r\r';
  	editor_insertHTML(ID, sLinkURL)
	return;
}

function ValidateCommentField(ID, bValidateName)
{

	var str = document.getElementById(ID).value;
	if( Trim(str) == '' )
	{
		alert("You cannot Leave the TextArea Blank.");
		return false;
	}
	
	if( bValidateName == true )
	{
		if( Trim(document.getElementById("ucCommentForm_txtNickName").value) == '' )
		{
			alert("You must enter a name before you can leave a comment.");
			return false;
		}
	}
	
	return true;
}

function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function validateDelete() 
{
 if (!confirm("Are you sure you wish to delete this item!")) 
 {
        event.returnValue=false;
       }
}


function getCookie(name) {

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;

  return unescape(dc.substring(begin + prefix.length, end));

}

function setHeaderImages()
	{
		if (browserVer == 1) 
		{
		btn_a01 = new Image();
		btn_a02 = new Image();
		btn_b01 = new Image();
		btn_b02 = new Image();
		btn_c01 = new Image();
		btn_c02 = new Image();
		btn_d01 = new Image();
		btn_d02 = new Image();
		//btn_e01 = new Image();
		//btn_e02 = new Image();
		btn_f01 = new Image();
		btn_f02 = new Image();
		btn_g01 = new Image();
		btn_g02 = new Image();
		//btn_h01 = new Image();
		//btn_h02 = new Image();

		btn_a01.src = sImgPath + "lb_btn_01_up.gif";
		btn_a02.src = sImgPath + "lb_btn_01_down.gif";
		btn_b01.src = sImgPath + "lb_btn_02_up.gif";
		btn_b02.src = sImgPath + "lb_btn_02_down.gif";
		btn_c01.src = sImgPath + "lb_btn_03_up.gif";
		btn_c02.src = sImgPath + "lb_btn_03_down.gif";
		btn_d01.src = sImgPath + "lb_btn_menu_01_up.gif";
		btn_d02.src = sImgPath + "lb_btn_menu_01_down.gif";
		//btn_e01.src = sImgPath + "lb_btn_menu_02_up.gif";
		//btn_e02.src = sImgPath + "lb_btn_menu_02_down.gif";
		btn_f01.src = sImgPath + "lb_btn_menu_03_up.gif";
		btn_f02.src = sImgPath + "lb_btn_menu_03_down.gif";
		btn_g01.src = sImgPath + "lb_btn_menu_04_up.gif";
		btn_g02.src = sImgPath + "lb_btn_menu_04_down.gif";
		//btn_h01.src = sImgPath + "lb_btn_menu_05_up.gif";
		//btn_h02.src = sImgPath + "lb_btn_menu_05_down.gif";
		}
	}

function setControls()
{
	if (getCookie("AuthCookie2")){
		//pnlShowLoginScreen
		document.getElementById('_UserName').innerHTML = getCookieKey("UserInfo","NickName");
		document.getElementById('_Logout_Box').style.display='';
		document.getElementById("_Login_Box").style.display='none';
		if(document.getElementById('_AccountOptions')) { document.getElementById('_AccountOptions').style.display=''; }
	}else{
		//pnlShowLoginScreen
		document.getElementById('_Logout_Box').style.display='none';
		document.getElementById('_Login_Box').style.display='';
		if(document.getElementById('PageTheme__TopLogin__UserField')){
			LoginBlur(document.getElementById('PageTheme__TopLogin__UserField'));
		}else if(document.getElementById('_ucPageHeader_ucHeaderBar_ucLogin__UserField')){
			LoginBlur(document.getElementById('_ucPageHeader_ucHeaderBar_ucLogin__UserField'));
		}
		if(document.getElementById('_AccountOptions')) { document.getElementById('_AccountOptions').style.display='none'; }
	}
}

function getCookieKey(mainKey,subKey) {
 var reg = new RegExp("(^| )"+mainKey+"=([^;]*)(;|$)");
 var arr = document.cookie.match(reg);
 if (arguments.length == 2) {
  if (arr!=null)
   return key(subKey,arr[2]);
  else
   return null;
 } else if (arguments.length == 1) {
  if (arr!=null)
   return unescape(arr[2]);
  else
   return null;
 }

 function key(subKey,findWith) {
  var arr,reg = new RegExp("(^| |&)"+subKey+"=([^&]*)(&|$)");
  var findWith = findWith?findWith:document.cookie;
  if (arr =  findWith.match(reg))
   return unescape(arr[2]);
  else
   return null;
 }
}

function setImageSize_onLoad(safeWidth,item)
{
   try{
      if(m_Opera == true){ safeWidth = 650; }
      if(safeToResizeImage(item.src)&&item.width>safeWidth){   
         var _link = 'onclick="window.open(\'' + item.src + '\');"';
         var _str = '<div style="padding:2px;background-color:#FFF089;border:solid 1px #CCCCCC;margin-bottom:2px;margin-top:2px;width:645px;cursor:pointer;font-size:11px;color:#000000;font-weight:normal;" ' + _link + '>';
         _str += '<img src="/images/alert.gif" align="absmiddle"> ';
         _str += 'This image has been resized. Click this bar to view the full image. The original image is sized ' + item.width + 'x' + item.height
         if(m_IE){
            _str += ' and weighs ' + parseInt(item.fileSize/1024) + 'k.';
         }else{
            _str += '.';
         }
         _str += '</div>';
         _str += '<img src="' + item.src + '" width="' + safeWidth + '" >';
         var div = document.createElement('div');
         div.style.width='650px';
         div.align='center';
         div.innerHTML = _str;
         item.parentNode.replaceChild(div,item);
      }
   }catch(e){
      //alert(e.message);
   }
}

var checkflag = false;
function checkAll() 
{
   var fmobj = document.getElementById('aspnetForm');
   for (var i=0;i<fmobj.elements.length;i++)
   {
      var e = fmobj.elements[i];
      if ( (e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled) ) 
      {
         if (checkflag == false)
         {       
            e.checked = fmobj.allbox.checked;
            checkflag = true;
         }
         else 
         {
            e.checked = fmobj.allbox.checked;
            checkflag = false;         
         }
      }     
   }
}

//QueryString Parsing Functions
function PageQuery(q) {

if(String(this.q) == 'undefined') this.q = '';

if(q.length > 1) 
	this.q = q.substring(1, q.length);
else
	this.q = null;

this.keyValuePairs = new Array();

if(q)
{
	if(this.q)
	{
		for(var i=0; i < this.q.split("&").length; i++)
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return '';
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key)
{
   var search = window.location.search;
   if(search == null) search = '';
   if(key == null) key = '';

   var page = new PageQuery(search.toLowerCase()); 

   return unescape(page.getValue(key.toLowerCase())); 

}


function PagerRoll(currentPage, lastPage, element, over)
{
   //if(currentPage == lastPage) { return };
   if((element.className.indexOf('Previous')!=-1||element.className.indexOf('First')!=-1)&&currentPage<=1){
	return
   }else if((element.className.indexOf('Next')!=-1||element.className.indexOf('Last')!=-1)&&currentPage>=lastPage){
	return
   }
   if(over)
      element.className = element.className + '_OVER'; 
   else
      element.className = element.className.replace('_OVER',''); 
}


function movePage(page, lastPage)
{
   var loc = window.location + '?'
   var skinId = queryString('skinid');
   var libId = queryString('libid');
   var articleId = queryString('aid');
   var search = queryString('search');
   var sort = queryString('sort');
   var g = queryString('g');
   var acid = queryString('acid');
   var p = queryString('p');
   var view = queryString('view');
   var type = queryString('type');
   var cat = queryString('cat');
   var pageSize = queryString('size');
   var cid = queryString('cid');
   var full = ''; // for the user replies
   
   if(window.location.search.indexOf('full') >= 0)
      full = 'full';
     
   var newloc = '';
   
   var checknum = parseInt(page)
   if(isNaN(checknum))
   {
     return false;
   } 
     
   if(page < 1) page = 1;
   if(page > lastPage) page = lastPage;      
   
   if(parseInt(p) == page) return false;
   if(p == '' && lastPage == 1) return false;
   
   if(g != '' && g != null)
      newloc = 'g=' + g;   
      
//   In the case where the code is using ParseSimpleNav for Urls like "skins.aspx?new" and we need to use paging,
//   the code file should use RegisterScript("SimpleNav", "var simpleNav = 'new';")
//   This will add the simple nav string to the paging url string.
   try{   
   if(simpleNav && simpleNav != 'undefined' & simpleNav != '')
      newloc = simpleNav;   
   }catch(e){}
  
   if(acid != '' && acid != null)
   {
      if(newloc == '')
         newloc = 'acid=' + acid;    
      else
         newloc = newloc + '&acid=' + acid; 
   }
   
   if(sort != '' && sort != null)
   {
      if(newloc == '')
         newloc = 'sort=' + sort;
      else
         newloc = newloc + '&sort=' + sort;
   }
  
   if(skinId != '' && skinId != null)
   {
      if(newloc == '')
         newloc = 'skinid=' + skinId;    
      else
         newloc = newloc + '&skinid=' + skinId; 
   }  
      
   if(libId != '' && libId != null)
   {
      if(newloc == '')
         newloc = 'libid=' + libId;    
      else
         newloc = newloc + '&libid=' + libId; 
   }        
      
   if(articleId != '' && articleId != null)
   {
      if(newloc == '')
         newloc = 'aid=' + articleId;    
      else
         newloc = newloc + '&aid=' + articleId; 
   }

   if(view != '' && view != null)
   {
      if(newloc == '')
         newloc = 'view=' + view;    
      else
         newloc = newloc + '&view=' + view; 
   }
   
   if(type != '' && type != null)
   {
      if(newloc == '')
         newloc = 'type=' + type;    
      else
         newloc = newloc + '&type=' + type; 
   }

   if(search != '' && search != null)
   {
      if(newloc == '')
         newloc = 'search=' + search;    
      else
         newloc = newloc + '&search=' + search; 
   }

   if(cat != '' && cat != null)
   {
      if(newloc == '')
         newloc = 'cat=' + cat;    
      else
         newloc = newloc + '&cat=' + cat; 
   }
   
   if(pageSize != '' && pageSize != null)
   {
      if(newloc == '')
         newloc = 'size=' + pageSize;
      else
         newloc = newloc + '&size=' + pageSize;
   }

   if(cid != '' && cid != null)
   {
      if(newloc == '')
         newloc = 'cid=' + cid;    
      else
         newloc = newloc + '&cid=' + cid; 
   }

   if(full != '')
      newloc = newloc + '&' + full;

   if(newloc == '')
      newloc = 'p=' + page;    
   else
      newloc = newloc + '&p=' + page; 

   window.location = '?' + newloc;
}