BR_DOM  = (document.getElementById) ? true : false;
BR_NS4  = (document.layers) ? true : false;
BR_IE   = (document.all) ? true : false;
BR_IE4  =  BR_IE && !BR_DOM;
BR_Mac  = (navigator.appVersion.indexOf("Mac") != -1);
BR_IE4M =  BR_IE4 && BR_Mac;
BR_NS6  =  BR_DOM && !BR_IE;
BR_Safari  = (navigator.appVersion.indexOf("Safari") != -1);

clear = new Image (110,18);
clear.src = "http://g.ggimg.com/gtx/images/b_clear.gif"
prevsearch = new Image (110,18);
prevsearch.src = "http://g.ggimg.com/gtx/images/b_prevsearch.gif"
mysaved = new Image (110,18);
mysaved.src = "http://g.ggimg.com/gtx/images/b_mysaved_full.gif"
printe = new Image (110,18);
printe.src = "http://g.ggimg.com/gtx/images/b_print.gif"
email = new Image (110,18);
email.src = "http://g.ggimg.com/gtx/images/b_email.gif"
dict = new Image (110,18);
dict.src = "http://g.ggimg.com/gtx/images/b_dict.gif"
titlelist = new Image (110,18);
titlelist.src = "http://g.ggimg.com/gtx/images/b_titlelist.gif"
help = new Image (110,18);
help.src = "http://g.ggimg.com/gtx/images/b_help.gif"
infomark = new Image (110,18);
infomark.src = "http://g.ggimg.com/gtx/images/b_infomark.gif"
find = new Image (110,18);
find.src = "http://g.ggimg.com/gtx/images/b_find.gif"
applyprefs = new Image (118,15);
applyprefs.src = "http://g.ggimg.com/gtx/images/b_applyprefs.gif"
restoreprefs = new Image (118,15);
restoreprefs.src ="http://g.ggimg.com/gtx/images/b_restoredefaults.gif"
remove = new Image (110,18);
remove.src = "http://g.ggimg.com/gtx/images/b_remove.gif"
download = new Image (110,18);
download.src = "http://g.ggimg.com/gtx/images/b_download.gif"
//Go button in the limit/expand.
goc = new Image (110,18);
goc.src = "http://g.ggimg.com/gtx/images/b_go_options.gif"

/* Alert messgae constant for Page no validation */
var PAGE_NO_VALIDATION = "Enter valid page no";

function img_act(tag)
{
}

function img_inact(tag)
{
}

function img_act_new (tag) {
}

function img_inact_new (tag) {
}

function setCookie(name, value) {
  document.cookie = name + "=" + escape(value);
}

function initRelated() {
  var initTopix = "inline,none,none,none"
  setCookie("currTopix", initTopix);
}

function createCustomPopupWindow(url, windowName, width, height) {
    var loc = url;
    remote = window.open("",windowName,"alwaysRaised=yes,width="+width+",height="+height+",screenX=50,screenY=50,top=50,left=50,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,status=no");
    remote.location.href=url;
    if (remote.opener == null) remote.opener = window;
    else remote.focus();
}

// like createCustomPopupWindow with no tool bar.
function createAppPopupWindow(url, windowName, width, height) {
    var loc = url;
    remote = window.open("",windowName,"alwaysRaised=yes,width="+width+",height="+height+",screenX=50,screenY=50,top=50,left=50,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,status=no");
    remote.location.href=url;
    if (remote.opener == null) remote.opener = window;
    else remote.focus();
}


function makeRemote(url) {
	var argumentObj = makeRemote.arguments;
	var argumentsCount = argumentObj.length;
	var width = 720;
	var height = 520;
	if(argumentsCount>=3) {
		width = argumentObj[1];
		height = argumentObj[2];
	}
    createCustomPopupWindow(url,"galeChildWindow",width,height);
}

//For # links only Ex.

var openerURL = '';
function notifyParent(lineNumber) {

	if(openerURL == ''){
		openerURL = opener.location.href;
	}

	opener.location.href=openerURL + lineNumber;
}

function makeFullNavRemote(url) {
    var loc = url;
    remote = window.open("","galeChildWindow","alwaysRaised=yes,width=720,height=520,screenX=50,screenY=50,top=50,left=50,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,status=yes,location=yes");
    remote.location.href=url;
  if (remote.opener == null) remote.opener = window;
  else remote.focus();
  }

// Function to hide the current tag for Safari Browsers.
// Used for document infomarks to prevent horizontal scrolling.
function hideIfSafari(elem) {
  if (BR_Safari && null != elem) {
    elem.style.display = "none";
  }
}


// function to select the word highlighted,
var str = "";
function autodict() {
	if (document.selection && document.selection.createRange) {	
        if (event.srcElement.tagName == "A" || event.srcElement.tagName == "IMG" ||
            event.srcElement.tagName == "INPUT") {
            return false;
        }
        if(document.selection.type == "Text"){
           	var range = document.selection.createRange();
            str = range.text;
        }
    }
    else if(window.getSelection){	    
       	str=window.getSelection();
     }else if(BR_NS6 || BR_NS4){	    
       	str=document.getSelection();
     }
    if (str.length > 50)
          str = "";
}
if (window.Event)
    document.captureEvents (Event.MOUSEUP);
document.onmouseup = autodict;

// for dictionary
function dictionary(url) {
    var link = url+'&queryTerm='+str;
    remote = window.open("","galeChildWindow","alwaysRaised=yes,width=720,height=520,screenX=50,screenY=50,top=50,left=50,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,status=no");
    remote.location.href=link;
    if (remote.opener == null) remote.opener = window;
    else remote.focus();
}

// Show/hide error message

function getObj(name) {
  if (document.getElementById)
  {this.obj = document.getElementById(name);
  this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {this.obj = document.all[name];
  this.style = document.all[name].style;
  }
  else if (document.layers)
  {this.obj = document.layers[name];
  this.style = this.obj
  }
}


function errorMessage(name) {
  var thisSquib = new getObj(name);
  thisSquib.style.display = "block";
  }


//show-hide More Options
function showHideResultsLimiters() {
  var limiters = new getObj('limiters');
  var expandlimitlink = new getObj('expandlimitlink');
  var hidelimitlink   = new getObj('hidelimitlink');
  showLimiters = limiters.style.display;
  if (showLimiters == "none") {
  	limiters.style.display = "";
  	expandlimitlink.style.display = "none";
  	hidelimitlink.style.display =""
  }else{
  	limiters.style.display = "none";
  	expandlimitlink.style.display = "";
  	hidelimitlink.style.display ="none"
  }
}

//show-hide More Options
function showhideExpand() {
  var thisExpand = new getObj('limiters');
  var thisMore = new getObj('moreoptions');
  showLimiters = thisExpand.style.display;
  moreOpts = thisMore.style.display;
  if (showLimiters == "none") {
  thisExpand.style.display = "inline";
  thisMore.style.display = "none";
  }
  else if (showLimiters == "inline") {
  thisExpand.style.display = "none";
  thisMore.style.display = "inline";
  }
}

function addRow1() {
  var newrow = new getObj('newrow1');
  var addrow = new getObj('add2');
  var hiderow = new getObj('add1');
  newrow.style.display = "";
  addrow.style.display = "";
  hiderow.style.display = "none";
}

function addRow2() {
  var newrow = new getObj('newrow2');
  var addrow = new getObj('add3');
  var hiderow = new getObj('add2');
  newrow.style.display = "";
  addrow.style.display = "";
  hiderow.style.display = "none";
}

function addRow3() {
  var newrow = new getObj('newrow3');
  var addrow = new getObj('add4');
  var hiderow = new getObj('add3');
  newrow.style.display = "";
  addrow.style.display = "";
  hiderow.style.display = "none";
}

function hideRow3() {
  var newrow = new getObj('newrow3');
  var hiderow = new getObj('add4');
  var showrow = new getObj('add3');
  newrow.style.display = "none";
  hiderow.style.display = "none";
  showrow.style.display = "";
}

function hideRow2() {
  var newrow = new getObj('newrow2');
  var hiderow = new getObj('add3');
  var showrow = new getObj('add2');
  newrow.style.display = "none";
  hiderow.style.display = "none";
  showrow.style.display = "";
}

function hideRow1() {
  var newrow = new getObj('newrow1');
  var hiderow = new getObj('add2');
  var showrow = new getObj('add1');
  newrow.style.display = "none";
  hiderow.style.display = "none";
  showrow.style.display = "";
}

// Change the background color of a row as an item is marked/unmarked

function Highlight(whichRow) {
	var r = null;
	if (whichRow.parentNode && whichRow.parentNode.parentNode) {
		r = whichRow.parentNode.parentNode;
	}
	if (r) {
		if (r.className == "unselectedRow") {
			r.className = "selectedRow";
		}
	}
}

function Unhighlight(whichRow) {
	var r = null;
	if (whichRow.parentNode && whichRow.parentNode.parentNode) {
		r = whichRow.parentNode.parentNode;
	}
	if (r) {
		if (r.className == "selectedRow") {
			r.className = "unselectedRow";
	    }
	}
}

function Toggle(whichRow) {
	if (whichRow.checked) {
		Highlight(whichRow);
	}
	else {
		Unhighlight(whichRow);
	}
}


function CheckAll(whichRow) {
	whichRow.checked = true;
	Highlight(whichRow);
}

function ClearAll(whichRow) {
	whichRow.checked = false;
	Unhighlight(whichRow);
}


// Toggle all checkboxes from marked to clear

function ToggleAll(whichRow) {
	if (whichRow.checked) {
		CheckAll();
	}
	else {
		ClearAll();
	}
}

function setCurrentPosition(t){ 
	if(t != null){
   		var formObj = getDynamicSearchFormObj();
	   if(formObj!=null){  
		    formObj.currentPosition.value = t;  
	   }	   
   }
}


function getCurrentPosition()
{
   return document.resultsForm.currentPosition.value;
}

function getNoOfPages()
{
   return document.resultsForm.noOfPages.value;
}


function selectValue(pullDown, value){
	for(i=0; i < pullDown.options.length; i++){
		if(pullDown.options[i].value == value){
			pullDown.options[i].selected=true;
		}
	}
}

function validatePageNumber(){
	var curpos = 0;
	if(getCurrentPosition() !="" && !isNaN(getCurrentPosition()))
		curpos = parseInt(getCurrentPosition(),10);
	else
		curpos = parseInt("-1",10);

	var noOfPages = parseInt(getNoOfPages(),10);
	if( curpos <= 0 || curpos > noOfPages)
	{
		alert(PAGE_NO_VALIDATION);
		return false;
	}
	return true;
}

function showhideFullCitation(hide , show, hideLink, showLink) {
  var hideCitationObj = new getObj(hide);
  var showCitationObj = new getObj(show);
  var hideLinkObj = new getObj(hideLink);
  var showLinkObj = new getObj(showLink);

  selectedLink = hideCitationObj.style.display;

  if (selectedLink == "none") {
  hideCitationObj.style.display = "inline";
  hideLinkObj.style.display = "inline";
  showCitationObj.style.display = "none";
  showLinkObj.style.display = "none";
  }
  else if (selectedLink == "inline") {
  hideCitationObj.style.display = "none";
  hideLinkObj.style.display = "none";
  showCitationObj.style.display = "inline";
  showLinkObj.style.display = "inline";
  }
}

