﻿/* ************************************************************************
* File  : utils.js                                  Part of Sitecore *
* Version: 1.00                                          www.sitecore.net *
* Author : Alexandr Tsvirchkov                                            *
*                                                                         *
* Purpose: To implement JScript utility functions                         *
*                                                                         *
* Bugs   : None known.                                                    *
*                                                                         *
* Status : Published.                                                     *
*                                                                         *
* Copyright (C) 1999-2004 by SiteCore A/S. All rights reserved.           *
*                                                                         *
* This work is the property of:                                           *
*                                                                         *
*        Sitecore A/S                                                     *
*        Tornebuskegade 1                                                 *
*        1131 Copenhagen K.                                               *
*        Denmark                                                          *
*                                                                         *
* This is a Sitecore published work under Sitecore's                      *
* shared source license.                                                  *
*                                                                         *
* *********************************************************************** */

// -------------------------------------------------------------
// Sets focus to a control 
// -------------------------------------------------------------        
function SetFocus(elmID){
  try{
    var obj=document.getElementById(elmID);
    if ( obj ){
      obj.focus();      
    }
    return true;
  }
  catch(e){
  }
}
function GotoHref(URL, sParam, sVal){
  var arrGet, i, sBeforeQuestion, sAfterQuestion, sNewURL
  i=URL.indexOf("?");
  URL=URL.replace("#","");
  if (i!==-1){
    sBeforeQuestion= URL.substr(0,i);
    sAfterQuestion = URL.substr(i+1);
  }
  else{
    sBeforeQuestion= URL;
    sAfterQuestion = "";
  }
  sNewURL="";
  if (sAfterQuestion!=""){
    arrGet=sAfterQuestion.split("&");
    for (i=0;i<=arrGet.length-1;i++){
      // Cut old sParam if exist
      if (arrGet[i].split("=")[0]!=sParam)
      {
        sNewURL+=(sNewURL.substr(0)!="&" ? "&" : "" )+arrGet[i];
      }
    }
  }
  sNewURL=sParam+"="+sVal+sNewURL;
  document.location.href=sBeforeQuestion+"?"+sNewURL;
  return(true);
}

function GetElementValueByID(elmID){
  try{
    var obj=document.getElementById(elmID);
    if ( obj ){
      return obj.value;      
    }
    return true;
  }
  catch(e){
  }
  return null;      
}
