
/*
$j("#docDrop").mouseleave(function(){
      $(this).toggle();
    }).mouseenter(function(){
      $(this).toggle();
    });
*/

function toggleDrop(element) {
	var el = document.getElementById(element);
	closeOverlay();
	(el.style.display == 'none') ? el.style.display = 'block' : el.style.display = 'none';
	return false;
}

function showDropDown(element) {
	var el = document.getElementById(element);
	closeOverlay();
	el.style.display = 'block';
	return false;
}
function hideDropDown(element) {
	var el = document.getElementById(element);
	closeOverlay();
	if (el && el.style && el.style.display) { 
		el.style.display = 'none';
	}
	return false;
}
function toggleMore(element) {
	var el = document.getElementById(element);
	var links = document.getElementById(element +'Plus');

	if (el.style.display == 'none') {
		el.style.display = 'block';
		links.style.display = 'none';
	} else {
		el.style.display = 'none';
		links.style.display = 'block';
	}
	return false;
}
function toggleMoreOverlay(element) {
	closeOverlay();
	$j(element).show(300);
	return false;
}
function toggleInOverlay(element) {
	closeOverlay();
	$j(element).show(300);
	return false;
}
function toggleHideOverlay(element) {
	$j(element).hide(300);
	return false;
}

function closeOverlay() {
	$j('.overlay').hide();
}
function writeFields(element) {
	var txtBoxCls = '.' + element + 'Txt';
	var txtBox = $j(txtBoxCls);
	var dropDown = document.getElementById(element);
	if(dropDown == null)
	  return;
	var links = dropDown.getElementsByTagName('a');
	for (var i = 0; i < links.length; i++) {
		links[i].onclick = function() {
			txtBox.text(this.innerHTML);
			closeOverlay();
			return false;
		}
	}
}
$j( function() {

	$j('.dropDown').click( function(){
		closeOverlay();
		document.getElementById('selProd').style.display = 'block';
	});


	writeFields('docDrop');
	writeFields('pubDrop');
	writeFields('pane01');

} );
var advancedSearchProduct = 'advancedSearchProduct';
var advancedSearchDocumentType = 'advancedSearchDocumentType';
var advancedSearchDatePublished = 'advancedSearchDatePublished';
var Id = 'Id';
var Name = 'Name';
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ')
        c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0)
          return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function isEmpty(s){
  if(s == null || s == '')
    return true;
  return false;
}
function nullSafe(s){
  if(s == null)
    return "";
  return s;
}
function dropCookie(name, value){
  document.cookie = name + '=' + value + '; path=/';
}
function dropGuidedSearchFormCookie(){
  dropCookie('searchFormDisplay', 'simple');
}
function dropAdvancedSearchFormCookie(){
  dropCookie('searchFormDisplay', 'advanced');
}
function removeSearchFormCookie(){
  dropCookie('searchFormDisplay', '');
}
function getSearchFormCookie(){
  return readCookie('searchFormDisplay');
}
function getAdvancedSearchProductNameCookie(){
  return readCookie(advancedSearchProduct + Name);
}
function getAdvancedSearchProductIdCookie(){
  return readCookie(advancedSearchProduct + Id);
}
function getAdvancedSearchDocumentTypeNameCookie(){
  return readCookie(advancedSearchDocumentType + Name);
}
function getAdvancedSearchDocumentTypeIdCookie(){
  return readCookie(advancedSearchDocumentType + Id);
}
function getAdvancedSearchDatePublishedNameCookie(){
  return readCookie(advancedSearchDatePublished + Name);
}
function getAdvancedSearchDatePublishedIdCookie(){
  return readCookie(advancedSearchDatePublished + Id);
}
function setProduct(name, id){
  getSearchForm().product.value = id;
  dropCookie(advancedSearchProduct + Name, name);
  dropCookie(advancedSearchProduct + Id, id);
	var queryfield = $('gsSearchString');
	var advqueryfield = $('advSearchString');
	var query = "";
	var gsquery = $F(queryfield);
	var advquery = $F(advqueryfield);
	if (queryfield.present() || advqueryfield.present()) {
		if (!advquery.empty()) {
			query = advquery.replace(/(\[.*\]\s?)/,'');
		} else {
			query = gsquery.replace(/(\[.*\]\s?)/,'');
		}
// Consona PS 04/07/2010 Disable the pre-population of the product selected in the query string
//		if (name != 'All Products') {
//			queryfield.value = "[" + name + "] " + query;
//			advqueryfield.value = "[" + name + "] " + query;
//		} 
//		else {
			queryfield.value = query;
			advqueryfield.value = query;
//		}
	} //no current query
	else {
//		if (name != 'All Products') {
//			queryfield.value = "[" + name + "] " + "";
//			advqueryfield.value = "[" + name + "] " + "";
//		} 
	}
  myTextNode = document.createTextNode(name);
  var elem = document.getElementById('productTextFieldId');
  elem.replaceChild(myTextNode, elem.firstChild);
  hideDropDown('selProd');
}
function setDocumentType(name, id){
  	var myForm = getSearchForm();
  getSearchForm().document.value = id;
  dropCookie(advancedSearchDocumentType + Name, name);
  dropCookie(advancedSearchDocumentType + Id, id);
  myTextNode = document.createTextNode(name);
  var elem = document.getElementById('docTypeTextFieldId');
  elem.replaceChild(myTextNode, elem.firstChild);
  $j("#docDrop").toggle();
  //if ( document.getElementById('docDrop') ) {
  // hideDropDown('docDrop');
  // }
}
function setDatePublished(name, id){
  getSearchForm().datepublished.value = id;
  dropCookie(advancedSearchDatePublished + Name, name);
  dropCookie(advancedSearchDatePublished + Id, id);
  myTextNode = document.createTextNode(name);
  var elem = document.getElementById('publishedDateTextFieldId');
  elem.replaceChild(myTextNode, elem.firstChild);
  hideDropDown('pubDrop');
}
function getProduct(){
  if(!isEmpty(getAdvancedSearchProductIdCookie())){
    document.getElementById('productTextFieldId').innerHTML = getAdvancedSearchProductNameCookie();
    getSearchForm().product.value = getAdvancedSearchProductIdCookie();
  }
}
function getDocumentType(){
  if(!isEmpty(getAdvancedSearchDocumentTypeIdCookie())){
    document.getElementById('docTypeTextFieldId').innerHTML = getAdvancedSearchDocumentTypeNameCookie();
    getSearchForm().document.value = getAdvancedSearchDocumentTypeIdCookie();
  }
}
function getDatePublished(){
  if(!isEmpty(getAdvancedSearchDatePublishedIdCookie())){
    document.getElementById('publishedDateTextFieldId').innerHTML = getAdvancedSearchDatePublishedNameCookie();
    getSearchForm().datepublished.value = getAdvancedSearchDatePublishedIdCookie();
  }
}
function retrieveAdvancedSearchFields(){
  getProduct();
  getDocumentType();
  getDatePublished();
}
function clearAdvancedSearchFields(){
  getSearchForm().product.value = "";
  getSearchForm().document.value = "";
  getSearchForm().datepublished.value = "";
}
function switchToAdvancedSearchForm(){
  retrieveAdvancedSearchFields();
  $('#advSearch').slideDown(1500);
  $('#advSearchLink').fadeOut(300);
  dropAdvancedSearchFormCookie();
}
function showAdvancedSearchForm(){
  retrieveAdvancedSearchFields();
  $('#advSearch').slideDown(0);
  $('#advSearchLink').fadeOut(0);
}
function switchToGuidedSearchForm(){
  closeOverlay();
  alert( "Inside switchToGuidedSearchForm()");
  $('#advSearch').slideUp(1250);
  $('#advSearchLink').fadeIn(300);
  clearAdvancedSearchFields();
  dropGuidedSearchFormCookie();
  alert( "Leaving switchToGuidedSearchForm()");
}
function clearDefaultText(element, defaultText){
  if(element.value == defaultText)
    element.value = "";
}
function isAdvancedSearch(){
  if(getSearchFormCookie() == 'advanced')
    return true;
  return false;
}
function isSearchFormCookieExist(){
  if(getSearchFormCookie() == null)
    return false;
  return true;
}
function go(what) { 
        what.submit(); 
} 

var isNav, isIE 

if (parseInt(navigator.appVersion) >= 4) { 
  if (navigator.appName == "Netscape") 
    isNav = true 
  else 
    isIE = true 
} 


function showKeyValue(evt) 
{ 
  var keyValue 

  if (isNav) 
    keyValue = evt.which 
  else 
    keyValue = window.event.keyCode 

  if (keyValue == 13) 
  { 
  
  //strip leading spaces before submitting query 
        if (document.base.querytext.value.charAt(0)==' ') 
        { 
                while(''+document.base.querytext.value.charAt(0)==' ') 
                {document.base.querytext.value=document.base.querytext.value.substring(1,document.base.querytext.value.length);}

        
                if (document.base.querytext.value.length < 2) 
                { 
                        document.base.querytext.focus(); 
                        return false; 
                }       
                
        } 
        
        if (document.base.querytext.value.length < 2) 
                { 
                        document.base.querytext.focus(); 
                        return false; 
                }       
        else 
        { 
                if (document.base.querytext.value.length > 200) 
                { 
                        document.base.querytext.focus(); 
                        return false; 
                } 
                
                else 
                { 
                go(document.base); 
                } 
        } 
      
  } 
  return false 
  
} 



function validateSearchBoxForm() 
{ 

if (document.base.querytext.value == 'Search Avaya') {
  alert("Please type a specific search term and try again.")
  document.base.querytext.focus(); 
  return false; 
}



        //strip leading spaces before submitting query 
        if (document.base.querytext.value.charAt(0)==' ') 
        { 
        //alert("leading space"); 
        while(''+document.base.querytext.value.charAt(0)==' ') 
                {document.base.querytext.value=document.base.querytext.value.substring(1,document.base.querytext.value.length);}

                
                if (document.base.querytext.value.length < 2) 
                { 
alert("Could not process your search.\n Please enter a search term at least 2 characters long and try again.");

                document.base.querytext.focus(); 
                        return false; 
                }       
        } 
                
        //check that more than one character is entered in search field 
        if (document.base.querytext.value.length < 2) 
        { 
    alert("Could not process your search.\n Please enter a search term at least 2 characters long and try again.");

                document.base.querytext.focus(); 
    return false; 
        } 
        
        //check that more than 200 characters are entered in search field 
        if (document.base.querytext.value.length > 200) 
        { 
    alert("The search text you've submitted is too long (more than 250 characters).\n Please shorten your query and try again.");

    document.base.querytext.focus(); 
    return false; 
        } 
        
                
} 




