function windowPos(left,top) 
{
	this.left=left;
	this.top=top;
}


function centerWindow(width,height) 
{
	var sh=screen.height;
	var sw=screen.width;

	 x = (sw-width)/2;
	 y=  (sh-height)/2;

	 return new windowPos(x,y);
}


function fillInFavoriteSearchForm(serviceRequest)
{
	document.FavoriteSearch.servicerequest.value = serviceRequest;
	return true;
}
function strReplace(str1, str2, str3) { 
  while(str1.indexOf(str2) != -1) {
   str1 = str1.replace(str2, str3);
 } 
  return str1;     
}
function fixUrl(url){
 url= strReplace(url,"#","%23");
 url= strReplace(url,"+","%2b");
 return url;
} 

function openViewDoc(url)
{
	url=fixUrl(url);
    window.open(url,'viewDoc', 'toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=800,height=600').focus();
}


function callSaveKC()
{
    var o=centerWindow(355,227);
    window.open("",'saveThisKC','top=' + o.top + ',left=' + o.left + ',toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=355,height=227').focus();
    document.forms['FavoriteKC'].submit();
}


function callSaveSearch(SearchName)
{
    document.FavoriteSearch.target = 'saveThisDialog';
    document.FavoriteSearch.SearchName.value = SearchName;
    var o=centerWindow(355,227);
    window.open("",'saveThisDialog','top=' + o.top + ',left=' + o.left + ',toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=355,height=227').focus();
    document.forms['FavoriteSearch'].submit();
}


function callSaveDocument()
{
    document.FavoriteKC.target = 'saveThisDocument';
    var o=centerWindow(355,227);
    window.open("",'saveThisDocument','top=' + o.top + ',left=' + o.left + ',toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=355,height=227').focus();
    document.forms['FavoriteKC'].submit();
}


/** Called by EmailDocument link on Homepage */
function EmailDocuments(locale)
{
	var docIds = "";
	var nCount = 0;
	var url = "emaildocuments.do?locale=" + escape(locale) + "&docIds=";

	//alert(document.SavedDocuments.emailcheckbox.value);
	//alert(document.SavedDocuments.emailcheckbox.length);
	if( document.SavedDocuments.emailcheckbox.value != null)
	{
		if(document.SavedDocuments.emailcheckbox.checked)
		{
			docIds = docIds + document.SavedDocuments.emailcheckbox.value + ",";
			nCount++;
		}
	}
	else if( document.SavedDocuments.emailcheckbox.length != null)
	{
		for(i=0; i < document.SavedDocuments.emailcheckbox.length; i++)
		{
			if(document.SavedDocuments.emailcheckbox[i].checked)
			{
				docIds = docIds + document.SavedDocuments.emailcheckbox[i].value + ",";
				nCount++;
			}
		}
	}
	//alert(nCount);

	if(nCount == 0)
	{
		alert("Select a document(s) before using the email feature");
		return;
	}

	url += escape(docIds);
	var o= centerWindow(510,427);
	window.open(url,'saveThisDialog','top=' + o.top + ',left=' + o.left + ',toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=510,height=427').focus();
}

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false


function show(id)
{
	if (ns4) document.layers[id].visibility = "show"
	else if (ie4) document.all[id].style.display = "block"
	else document.getElementById(id).style.visibility = "visible"
}


function hide(id)
{
	if (ns4) document.layers[id].visibility = "hide"
	else if (ie4) document.all[id].style.display = "none"

	else document.getElementById(id).style.visibility = "hidden"
}


function validateDocumentID()
{
	if(document.KanisaSearchForm.searchFor != null
		&& document.KanisaSearchForm.searchFor.value == 'searchByID')
	{
		if( document.KanisaSearchForm.searchString.value == '' )
		{
			alert('Please enter a documentID.');
			document.KanisaSearchForm.searchString.focus();
			return false;
		}
	}
	document.KanisaSearchForm.submit();
}


function validateFunc()
{
	if(document.KanisaSearchForm.searchFor != null
		&& document.KanisaSearchForm.searchFor.value == 'searchByID')
	{
		if( document.KanisaSearchForm.searchString.value == '' )
		{
			alert('Please enter a documentID.');
			document.KanisaSearchForm.searchString.focus();
			return false;
		}
	}
	return true;
}


function showGuidedSearch()
{
  var objgs=document.getElementById("div_guidedsearch");
  var objes=document.getElementById("div_expertsearch");
  if (objgs!=null && objes!=null){
  	objgs.style.display="block";
    objes.style.display="none";
  }
  //document.all["div_guidedsearch"].style.display="block";
  //document.all["div_expertsearch"].style.display="none";
}


function showExpertSearch()
{
  var objgs=document.getElementById("div_guidedsearch");
  var objes=document.getElementById("div_expertsearch");
  if (objgs!=null && objes!=null){  	
  	objgs.style.display="none";
    objes.style.display="block";    
  }
  //document.all["div_guidedsearch"].style.display="none";
  //document.all["div_expertsearch"].style.display="block";
}


function changeColor(obj,id)
{
  if (!document.all && !document.getElementById) return;
  if (document.getElementById) {
    var o=document.getElementById(id);
  } else {
    var o=document.all[id];
  }
  if (o==null) return;
  if (obj.checked) {
	o.bgColor='D3D3D3';
  } else {
	o.bgColor='#FFFFFF';
  }
}

function sortSavedDocs(field,order){
  var url = "home.do?saveDocSortOn" + field + "&amp;saveDocSortOrder=" + order;    
   try{
   	  url= url.replace("?style=block","");
   	  url= url.replace("&style=block","");
   	  url= url.replace("?style=none","");   	  
   	  url= url.replace("&style=none","");    	  
       var sep="?";
       if (url.indexOf("?")!=-1) sep="&";
       var st= sep + "style=block&";
       if (document.all["div_guidedsearch"]!=null && document.all["div_guidedsearch"].style.display!=null){
       	 st =sep +"style=" + document.all["div_guidedsearch"].style.display;
       }       
	url=url+st;
   }catch (err){}
   self.location.href = url;  
}

