var IsSearchFocused = false;
var SearchMoto      = new String();

/* Get Page Element by Id */
function GetDocumentElement (elementId) {
  if (this.document.all) {
	return this.document.all(elementId);
  }
  else if (this.document.getElementById) {
    return this.document.getElementById(elementId);
  }
  else {
    return null;  
  }
}


/* Get Form Element by Name */
function GetFormElementByName (baseControl,elementName) {
  var objForm    = null;
  var objField   = null;
  var objElement = null;
  var strName    = new String();
  var strControl = new String();
  var objArray   = new Array();
  var i;
    
  if (self.document.forms.length>0) {
      objForm = self.document.forms[0];
      
      for (i=0;i<objForm.elements.length;i++) {
           strName = objForm.elements[i].name.toString();
           // Split Name
           if (strName.indexOf (":",0)>=0) {
              objArray = strName.split (":");
           }
           else if (strName.indexOf ("$",0)>=0) {
              objArray = strName.split ("$");
           }
           else {
              objArray[0] = strName; 
           };
            
           // Get Control Name    
           strControl = "";
           if (objArray.length>1){
               strControl = objArray[objArray.length-2].toString();
           }
			
		   // Get Name	
           strName = objArray[objArray.length-1].toString();
           if ((strControl==baseControl) && (strName==elementName)) {
              objElement = objForm.elements[i];
              break;
           };
      };
  };
  return objElement;
}


/* Handle the Key Stroke text fields */
function HandleKeyStroke (cElementId) {
	if (window.event) {
		if (window.event.keyCode == 13) {
			var objButton = null;
			objButton = GetDocumentElement(cElementId); 	
			if (objButton!=null) {
				objButton.click();
			}
			return false;
		}
	}
}

/* Handles the focus of the search box control */
function HandleSearchFocus (cElement) {
   if (!IsSearchFocused) {
       IsSearchFocused = true;
       SearchMoto      = cElement.value.toString();
       cElement.value  = "";
   }
}

/* Handles the blur of the search box control */
function HandleSearchBlur (cElement) {
   var value = new String();
   value = cElement.value.toString();
   
   if ((value=="") || (value.length==0)) {
	   cElement.value = SearchMoto;			   
	   IsSearchFocused = false;
   }
   else if (value==SearchMoto) {
	   IsSearchFocused = false;	
   }
   else {
	   IsSearchFocused = true;	
   }
}

/* Launches the branch sites to a new window */
function LaunchBranch(ddList) {
   var win = null;
   var url = new String();
   var i   = 0;
   
   i = ddList.selectedIndex;
   
   if (i>0) {
      url = ddList.options[i].value.toString();
      win = window.open (url,"","");
   
      if (win!=null) {
		  win.focus();
      }
   }
}


function NavigateBack () {
   if (self.history.length!=0) {
       self.history.back();
   }
}


function LaunchPrintPopup (isLocal) {
   var win = null;
   var url = new String ();	
   if (isLocal) {
      url = "ECPrintPopupBG.html";
   }
   else {
      url = "ECPrintPopupEN.html";
   }
   win = window.open (url,"","status=1,toolbar=0,menubar=0,location=0,channelmode=0,resizable=1,titlebar=0,directories=0,scrollbars=1");   
}


function PrintPageContent () {
   var sourceWindow = null;
   var prHolder     = null;
   var plHolder     = null;
   var pcTool       = null;
   var i = 0;
	
   try {
		if (self.opener!=null) {
			sourceWindow = self.opener;
			self.document.title = sourceWindow.document.title;
			prHolder = sourceWindow.GetDocumentElement ("ContentHolder");
			plHolder = GetDocumentElement ("PrintContentHolder");
			if ((prHolder!=null) && (plHolder!=null)) {
				// Add Content
			    plHolder.innerHTML = prHolder.innerHTML;
				// Clear any link
				for (i=0; i<self.document.links.length; i++) 
				{
				  self.document.links[i].href="#";
				}
				 
				// Remove Page Tools 
				pcTool = GetDocumentElement ("_ctl0_pcTools_pcPrint");
				if (pcTool!=null) {
				   var parent = pcTool.offsetParent;
				   parent.removeChild(pcTool);
				}
				pcTool = GetDocumentElement ("pcSendMail");
				if (pcTool!=null) {
				   var parent = pcTool.offsetParent;
				   parent.removeChild(pcTool);
				}
			 
				
				// focus and print
				self.focus();
				self.print();
			}   
		}  
	}
	
	catch (ex) {
		self.close();
	}
}


function SendEmail () {
   var win = null;
   var url = new String();
  
   url = "mailto:?subject=ICAP Group&body=" + escape(window.location.href);
   self.window.location.href = url;
}