/************************************************************************************************************
   (C) www.dhtmlgoodies.com, November 2005
   
   This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.    
   
   Terms of use:
   You are free to use this script as long as the copyright message is kept intact. However, you may not
   redistribute, sell or repost it without our permission.
   
   Thank you!
   
   www.dhtmlgoodies.com
   Alf Magne Kalleland
   
   ************************************************************************************************************/

var arrayOfRolloverClasses = new Array();
var arrayOfClickClasses = new Array();
var activeRow = false;
var activeRowClickArray = new Array();

/**
*
* listAllStates : This function is used to call the ajax method makeGETRequest() to display
    *                 the States drop-down based on the Country selected
* Parameters    : base_url  :   The base url to be used to locate the listAllStatesPT
* Return Value  : Shall not return any value
* Compatibility : IE v6.0.28, Mozilla Firefox v1.5.0.6
*
**/
function listAllStates(base_url)    {

    var country_selector_obj = document.getElementById('country_selector');
    var selected_country = country_selector_obj.options[country_selector_obj.selectedIndex].value;
    var url = base_url + '/listAllStatesPT?id_country=' + encodeURI(selected_country);
    var states_display_slot = 'state_list_slot_id';
    if(selected_country != "")    {
        makeGETRequest(url, states_display_slot);
    }
}


/** 
* clean    : This function is used to replace the html,spaces in the text entered 
*             and also covert entities to single character
* Parameters :content: this parameter is used to get the content entered in the description field
* Return Value: null
* Compatibility:IE 6.0,Mozilla Firefox 1.0.7, Netscape Navigator 7.1
**/
function cleanContent(content) {
    content = content.replace(/<(.+?)>/g, ' ');//remove html
    content = content.replace('&nbsp;', ' ', 'g');//replace &nbsp; with space
    content = content.replace(/&(.+?);/g, '1');//convert entities to single character
    return content;
} 

/**
* descriptionCountWords:This function is used to count the number of words.
* Parameters :content : Used to get the content.
* Return Value: null
* Compatibility:IE 6.0,Mozilla Firefox 1.0.7, Netscape Navigator 7.1
**/
function countWords(content) {    
    content = cleanContent( content );
    var arr = content.split(' ');
    var total = 0;
    for(var i=0; i<arr.length; i++) {
        if( arr[i].match(/\w/g))    {
            total ++;
        }
    }
    return total;
}

function highlightTableRow()
    {
    var tableObj = this.parentNode;

    if (tableObj.tagName != 'TABLE')
        tableObj = tableObj.parentNode;

    if (this != activeRow)
        {
        this.setAttribute('origCl', this.className);
        this.origCl = this.className;
        }

    this.className = arrayOfRolloverClasses[tableObj.id];

    activeRow = this;
    }

function clickOnTableRow()
    {
    var tableObj = this.parentNode;

    if (tableObj.tagName != 'TABLE')
        tableObj = tableObj.parentNode;

    if (activeRowClickArray[tableObj.id] && this != activeRowClickArray[tableObj.id])
        {
        activeRowClickArray[tableObj.id].className = '';
        }

    this.className = arrayOfClickClasses[tableObj.id];

    activeRowClickArray[tableObj.id] = this;
    }

function resetRowStyle()
    {
    var tableObj = this.parentNode;

    if (tableObj.tagName != 'TABLE')
        tableObj = tableObj.parentNode;

    if (activeRowClickArray[tableObj.id] && this == activeRowClickArray[tableObj.id])
        {
        this.className = arrayOfClickClasses[tableObj.id];
        return;
        }

    var origCl = this.getAttribute('origCl');

    if (!origCl)
        origCl = this.origCl;

    this.className = origCl;
    }

function addTableRolloverEffect(tableId, whichClass, whichClassOnClick)
    {
    arrayOfRolloverClasses[tableId] = whichClass;
    arrayOfClickClasses[tableId] = whichClassOnClick;

    var tableObj = document.getElementById(tableId);
    var tBody = tableObj.getElementsByTagName('TBODY');

    if (tBody)
        {
        var rows = tBody[0].getElementsByTagName('TR');
        }

    else
        {
        var rows = tableObj.getElementsByTagName('TR');
        }

    for (var no = 0; no < rows.length; no++)
        {
        rows[no].onmouseover = highlightTableRow;
        rows[no].onmouseout = resetRowStyle;

        if (whichClassOnClick)
            {
            rows[no].onclick = clickOnTableRow;
            }
        }
    }

function MM_swapImgRestore()
    { //v3.0
    var i, x, a = document.MM_sr;

    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
        x.src = x.oSrc;
    }

function MM_preloadImages()
    { //v3.0
    var d = document;

    if (d.images)
        {
        if (!d.MM_p)
            d.MM_p = new Array();

        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;

        for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0)
                {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
                }
        }
    }

function MM_findObj(n, d)
    { //v4.01
    var p, i, x;

    if (!d)
        d = document;

    if ((p = n.indexOf("?")) > 0 && parent.frames.length)
        {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
        }

    if (!(x = d[n]) && d.all)
        x = d.all[n];

    for (i = 0; !x && i < d.forms.length; i++)
        x = d.forms[i][n];

    for (i = 0; !x && d.layers && i < d.layers.length; i++)
        x = MM_findObj(n, d.layers[i].document);

    if (!x && d.getElementById)
        x = d.getElementById(n);

    return x;
    }

function MM_swapImage()
    { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;

    for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null)
            {
            document.MM_sr[j++] = x;

            if (!x.oSrc)
                x.oSrc = x.src;

            x.src = a[i + 2];
            }
    }




/**
 * Function to check browser type & version
 */
  
 function checkBrowser()
 {
  var  browserName=navigator.appName; 
  var  browserVer=parseInt(navigator.appVersion); 
   if (browserName=="Netscape" && browserVer>=3)
   {
     return 'NS';
   }
   
   if(browserName=="Microsoft Internet Explorer" && browserVer>=4) 
   {
     return 'IE';
   }

 }
/** 
 *  deleteAllTblRows function will delete 
 *  all the rows of a specified table
 *  
 *  Parameters: Table ID
 *  Return Value: None
 *  Compatibility: NN6, IE5.5
 */
function deleteAllTblRows(table_id)
{
    //get the Table Object based
    var table_obj = document.getElementById(table_id);   
    
    //Iterate through the Table and delete each row
    for(var row_index = 0; row_index < table_obj.rows.length ; row_index++)
       {
          table_obj.deleteRow(row_index);
          row_index--;
       }
} // End of Function deleteAllTblRows
    
/** 
 *  deleteAllTblRows function will delete 
 *  all the rows of a specified table
 *  
 *  Parameters: Table ID
 *  Return Value: None
 *  Compatibility: NN6, IE5.5
 */
function deleteAllTblRowsExceptHeader(table_id)
{
    //get the Table Object based
    var table_obj = document.getElementById(table_id);   
    
    //Iterate through the Table and delete each row
    for(var row_index = 1; row_index < table_obj.rows.length ; row_index++)
       {
          table_obj.deleteRow(row_index);
          row_index--;
       }
} // End of Function deleteAllTblRows
        
/** 
 *  addTblRows function will add a row
 *  with no of cells into the specified 
 *  table
 * 
 *  Parameters : ID of Table, Number of Cells(Columns) to be added in to the row
 *  Return Value: returns the id of the row which was added.
 *  Compatibility: NN6, IE5.5
 */
    
function addTblRow(table_id,no_of_cells)
{
    var table_obj = document.getElementById(table_id);
    var new_row = table_obj.insertRow(table_obj.rows.length);

    var numrows   = table_obj.rows.length;
    //generate ID for the new row

    if(numrows > 2) /* if the row is not the first row
                     * the generate id based on prev row_id
                     * this is done to avoid duplicates
                     */
    {
      var prev_row_id = table_obj.rows[numrows-2].id;     
      var prev_row_no = prev_row_id.substring(table_id.length,prev_row_id.length);
      var cur_row_no  = parseInt(prev_row_no) + 1;
      new_row.id      = table_obj.id+cur_row_no;
          
    }
    else
    {
        // if the row is the first row
        if(numrows !=  0)
         {
          var prev_row_id = table_obj.rows[0].id;     
      var prev_row_no = prev_row_id.substring(table_id.length,prev_row_id.length);
      var cur_row_no  = parseInt(prev_row_no) + 1;
          if(cur_row_no>0)
          {
             new_row.id = table_obj.id+cur_row_no;
          }
          else
      {
                 new_row.id = table_obj.id+(numrows-1);
      }    

        }
        else
        {
           new_row.id = table_obj.id+(numrows-1);
        }    
    }
    
    
                
        for(var cell_index=0; cell_index < no_of_cells; cell_index++)
        {
          var nc = new_row.insertCell(cell_index);
          var cellId = new_row.id+'__Col'+(parseInt(cell_index));
          nc.id = cellId;    
        }
    return new_row.id;    
} // End of function addTblRow

    

/** 
 *  addTblRows function will add a row
 *  with no of cells into the specified 
 *  table
 * 
 *  Parameters : ID of Table, ID of the Row, Number of Cells(Columns) to be added in to the row
 *  Return Value: None
 *  Compatibility: NN6, IE5.5
 */
    
function addTblRowWithId(table_id,row_id, no_of_cells)
{
    var table_obj = document.getElementById(table_id);
    var new_row = table_obj.insertRow(table_obj.rows.length);

    new_row.id = table_obj.id + row_id;
    
        for(var cell_index=0; cell_index < no_of_cells; cell_index++)
        {
          var nc = new_row.insertCell(cell_index);
          var cellId = new_row.id+'__Col'+(parseInt(cell_index));
          nc.id = cellId;    
        }
} // End of function addTblRowWithId


    
/** 
 *  addTblColumn function will add a column
 *  into the specified table
 * 
 *  Parameters : ID of Table 
 *  Return Value: returns cellIndex
 *  Compatibility: NN6, IE5.5
 */
 
 function addTblColumn(tblId)
 {
   
     var tableObj = document.getElementById(tblId);
     var noOfRows = tableObj.rows.length;
     var noOfCols = tableObj.rows[0].cells.length;
     var cellId= "";

     for(var indx=0; indx < noOfRows; indx++)
     {
         
         if(noOfCols > 1)
          {
            var prevCellId = tableObj.rows[indx].cells[noOfCols-1].id;
            var pivot = (prevCellId.indexOf('__Col')+5);
            var prevCellNo = prevCellId.substring(pivot, prevCellId.length);
            cellId = prevCellId.substring(0,pivot) + (parseInt(prevCellNo)+1) ;
          }
          else
          {
            cellId = tableObj.rows[indx].id+'__Col'+parseInt(indx);
          }
       
         var nc = tableObj.rows[indx].insertCell(noOfCols);
         nc.id = cellId;
     }
     
     return  tableObj.rows[0].cells[noOfCols].id; //return the 1 row - newly added columns id
 }

/** 
 *  deleteTblRow function will delete 
 *  the specfied row from the specified table
 * 
 *  Parameters : ID of the Table, ID of the Row 
 *  Return Value: None
 *  Compatibility: NN6, IE5.5
 */
function deleteTblRow(table_id,row_id)
{
    var table_obj = document.getElementById(table_id);
    var max_rows = table_obj.rows.length;
    var table_row_id = table_id + row_id;
    for (var row_index=0; row_index<max_rows ; row_index++)
       {
        if(table_row_id == table_obj.rows[row_index].id)
        {

          table_obj.deleteRow(row_index);
          break;
        }  
       // alert(table_row_id+'---'+table_obj.rows[row_index].id);
    }
  
    
    
} // End of Function deleteTblRow


/** 
 *  deleteTblColumn function will delete 
 *  the specfied column from the specified table
 * 
 *  Parameters : ID of the Table, column index 
 *  Return Value: None
 *  Compatibility: NN6, IE5.5
 */
function deleteTblColumn(tblId,rowId,columnId)
{
    var tblObj = document.getElementById(tblId);
    var rowObj = document.getElementById(rowId);
    var noOfCells = rowObj.cells.length;
    var columnNo  = -1;
    //find the cell index
    for (indx=0;indx<noOfCells;indx++)
    {
      if(columnId ==rowObj.cells[indx].id)
       { columnNo = indx; break;
       }
    }
    
    if (columnNo < noOfCells && columnNo >= 0 ) // if the column exists then delete it
    { 
        for(indx =0; indx < tblObj.rows.length ; indx++ )
        {
            tblObj.rows[indx].deleteCell(columnNo);
        }
    }
}// End of Function deleteTblColumn

/** 
 *  insertContentIntoCell function will take three parameters row_id, cell_no
 *  and content, Inserts the contents into the particular cell
 *
 *  Parameters : ID of the row, Cell number(starts from Zero), Cell Contents
 *  Return Value: None
 *  Compatibility: NN6, IE5.5
 */
 
function insertContentIntoCell(row_id,cell_no,cell_content)
{ 
    var row_obj = document.getElementById(row_id);
   
    var max_cells = row_obj.cells.length;
    
    if(cell_no < max_cells)
    {
      row_obj.cells.item(cell_no).innerHTML=cell_content;
      row_obj.cells.item(cell_no).align='left';
      
    }
} // End of Function insertContentIntoCell


function numberTblRows(table_id) {
    
     var table_obj = document.getElementById(table_id);
     for(var i=1; i < table_obj.rows.length; i++) {
        insertContentIntoCell(table_obj.rows[i].id,0,i+'. ');
        rowStyle = document.getElementById(table_obj.rows[i].id).style;
        //rowStyle.backgroundColor = (i%2==0)?'#CAD2E8':'#FFFFFF';
     }
}

/**
 * Function to give colors for Table Rows
 * Compatibility:  IE6, NS6, FF1.2
 */
function colorTblRows(table_id) {    
     var table_obj = document.getElementById(table_id);
     for(var i=1; i < table_obj.rows.length; i++) {        
        rowStyle = table_obj.rows[i].style;
        rowStyle.backgroundColor = (i%2==0)?'#CAD2E8':'#FFFFFF';
     }
}

//---------------------------
     function getSelectText(sobj)
     {
       var outval="";
        for (var i=0;i<=sobj.length-1;i++)
        {

         if (sobj.options[i].selected)
        {
          outval = sobj.options[i].text;
           return outval;
        }       }
        return outval;
     }

//---------------------------
     function getSelectValue(sobj)
     {
       
      //alert(sobj);
       var outval="";
        for (var i=0;i<=sobj.length -1;i++)
        {

         if (sobj.options[i].selected)
        {
          outval = sobj.options[i].value;
           return outval;
        }       }
        return outval;
     }


//---------------------------
     function setSelectValue(sobj,val)
     {
        
        for (var i=0;i<=sobj.length -1;i++)
        {
            
         if (sobj.options[i].value == val)
        {
        
          sobj.options[i].selected = true;
        
           return ;
        }       
         }     
     }
//---------------------------
     function setSelectText(sobj,text)
     {
        
        for (var i=0;i<=sobj.length -1;i++)
        {
            
         if (sobj.options[i].text == text)
        {
        
          sobj.options[i].selected = true;
        
           return ;
        }       
         }     
     }
     
     
//---------------------------
     function getradioval(robj)
     {
       var outval="";
       
        for (var i=0;i<=robj.length -1;i++)
        {
          
         if (robj[i].checked)
        {
           outval = robj[i].value;
           return outval;
        }       }
        return outval;
     }
//----------------------------
         function getcheckboxval(cobj)
     {
       var outval=new Array();
       var counter=0;
       for (var i=0;i<=cobj.length-1;i++)
       {
        if (cobj[i].checked)
        {       
         outval[counter++] = cobj[i].value;      
        }       
       }
      return outval;
     }


    function setcheckboxval(cobj,val)
     {
       var outval=new Array();
       for (var i=0;i<=cobj.length-1;i++)
       {
        if (cobj[i].value == val )
        {       
         cobj[i].checked = true;      
        }       
       }
      return outval;
     }
          
//------------------------------------

 function setradioval(sobj,val)
     {
        
        
        for (var i=0;i<=sobj.length -1;i++)
        {
              
         if (sobj[i].value == val)
        {
        
          sobj[i].checked = true;
        
           return ;
        }       
        }      
     }
//---------------------------

      function clearcombo(cmb){
         for (var i=cmb.options.length-1; i>=0; i--){
        cmb.options[i] = null;
         }
      cmb.selectedIndex = -1;
    }
//---------------------------   
//The first line assigns the MatchIgnoreCase function as an equalsIgnoreCase method of the String object

String.prototype.equalsIgnoreCase=MatchIgnoreCase;

function MatchIgnoreCase(strTerm){
var strToSearch = this.toLowerCase();
strTerm = strTerm.toLowerCase();
if(strToSearch==strTerm){
return true;
}else
{
return false;
}
} //End Function

    
//---------------------------
function openDesiredWin(myLink,windowName,desired_width,desired_height)
{
d_width = (screen.width*desired_width)/100;
d_left = (screen.width-d_width)/2;
d_height = (screen.height*desired_height)/100;
d_top = (screen.height-d_height)/2;
if(! window.focus)return;
var myWin=window.open(myLink,windowName,"left=" + d_left + ",top=" + d_top + ",width=" + d_width + ",height=" + d_height + ",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
try {myWin.focus();}
catch (err) {}
// myLink.target=windowName;
return false;
}


//---------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
 var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
 function LZ(x) {return(x<0||x>9?"":"0")+x}
 
 // ------------------------------------------------------------------
 // isDate ( date_string, format_string )
 // Returns true if date string matches format of format string and
 // is a valid date. Else returns false.
 // It is recommended that you trim whitespace around the value before
 // passing it to this function, as whitespace is NOT ignored!
 // ------------------------------------------------------------------
 function isDate(val,format) {
    var date=getDateFromFormat(val,format);
    if (date==0) { return false; }
    return true;
    }
 
 // ------------------------------------------------------------------
 // formatDate (date_object, format)
 // Returns a date in the output format specified.
 // The format string uses the same abbreviations as in getDateFromFormat()
 // ------------------------------------------------------------------
 function formatDate(date,format) {
    format=format+"";
    var result="";
    var i_format=0;
    var c="";
    var token="";
    var y=date.getYear()+"";
    var M=date.getMonth()+1;
    var d=date.getDate();
    var E=date.getDay();
    var H=date.getHours();
    var m=date.getMinutes();
    var s=date.getSeconds();
    var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
    // Convert real date parts into formatted versions
    var value=new Object();
    if (y.length < 4) {y=""+(y-0+1900);}
    value["y"]=""+y;
    value["yyyy"]=y;
    value["yy"]=y.substring(2,4);
    value["M"]=M;
    value["MM"]=LZ(M);
    value["MMM"]=MONTH_NAMES[M-1];
    value["NNN"]=MONTH_NAMES[M+11];
    value["d"]=d;
    value["dd"]=LZ(d);
    value["E"]=DAY_NAMES[E+7];
    value["EE"]=DAY_NAMES[E];
    value["H"]=H;
    value["HH"]=LZ(H);
    if (H==0){value["h"]=12;}
    else if (H>12){value["h"]=H-12;}
    else {value["h"]=H;}
    value["hh"]=LZ(value["h"]);
    if (H>11){value["K"]=H-12;} else {value["K"]=H;}
    value["k"]=H+1;
    value["KK"]=LZ(value["K"]);
    value["kk"]=LZ(value["k"]);
    if (H > 11) { value["a"]="PM"; }
    else { value["a"]="AM"; }
    value["m"]=m;
    value["mm"]=LZ(m);
    value["s"]=s;
    value["ss"]=LZ(s);
    while (i_format < format.length) {
        c=format.charAt(i_format);
        token="";
        while ((format.charAt(i_format)==c) && (i_format < format.length)) {
            token += format.charAt(i_format++);
            }
        if (value[token] != null) { result=result + value[token]; }
        else { result=result + token; }
        }
    return result;
    }
    
 // ------------------------------------------------------------------
 // Utility functions for parsing in getDateFromFormat()
 // ------------------------------------------------------------------
 function _isInteger(val) {
    var digits="1234567890";
    for (var i=0; i < val.length; i++) {
        if (digits.indexOf(val.charAt(i))==-1) { return false; }
        }
    return true;
    }
 function _getInt(str,i,minlength,maxlength) {
    for (var x=maxlength; x>=minlength; x--) {
        var token=str.substring(i,i+x);
        if (token.length < minlength) { return null; }
        if (_isInteger(token)) { return token; }
        }
    return null;
    }
    
 // ------------------------------------------------------------------
 // getDateFromFormat( date_string , format_string )
 //
 // This function takes a date string and a format string. It matches
 // If the date string matches the format string, it returns the 
 // getTime() of the date. If it does not match, it returns 0.
 // ------------------------------------------------------------------
 function getDateFromFormat(val,format) {
    val=val+"";
    format=format+"";
    var i_val=0;
    var i_format=0;
    var c="";
    var token="";
    var token2="";
    var x,y;
    var now=new Date();
    var year=now.getYear();
    var month=now.getMonth()+1;
    var date=1;
    var hh=now.getHours();
    var mm=now.getMinutes();
    var ss=now.getSeconds();
    var ampm="";
    
    while (i_format < format.length) {
        // Get next token from format string
        c=format.charAt(i_format);
        token="";
        while ((format.charAt(i_format)==c) && (i_format < format.length)) {
            token += format.charAt(i_format++);
            }
        // Extract contents of value based on format token
        if (token=="yyyy" || token=="yy" || token=="y") {
            if (token=="yyyy") { x=4;y=4; }
            if (token=="yy")   { x=2;y=2; }
            if (token=="y")    { x=2;y=4; }
            year=_getInt(val,i_val,x,y);
            if (year==null) { return 0; }
            i_val += year.length;
            if (year.length==2) {
                if (year > 70) { year=1900+(year-0); }
                else { year=2000+(year-0); }
                }
            }
        else if (token=="MMM"||token=="NNN"){
            month=0;
            for (var i=0; i<MONTH_NAMES.length; i++) {
                var month_name=MONTH_NAMES[i];
                if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
                    if (token=="MMM"||(token=="NNN"&&i>11)) {
                        month=i+1;
                        if (month>12) { month -= 12; }
                        i_val += month_name.length;
                        break;
                        }
                    }
                }
            if ((month < 1)||(month>12)){return 0;}
            }
        else if (token=="EE"||token=="E"){
            for (var i=0; i<DAY_NAMES.length; i++) {
                var day_name=DAY_NAMES[i];
                if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
                    i_val += day_name.length;
                    break;
                    }
                }
            }
        else if (token=="MM"||token=="M") {
            month=_getInt(val,i_val,token.length,2);
            if(month==null||(month<1)||(month>12)){return 0;}
            i_val+=month.length;}
        else if (token=="dd"||token=="d") {
            date=_getInt(val,i_val,token.length,2);
            if(date==null||(date<1)||(date>31)){return 0;}
            i_val+=date.length;}
        else if (token=="hh"||token=="h") {
            hh=_getInt(val,i_val,token.length,2);
            if(hh==null||(hh<1)||(hh>12)){return 0;}
            i_val+=hh.length;}
        else if (token=="HH"||token=="H") {
            hh=_getInt(val,i_val,token.length,2);
            if(hh==null||(hh<0)||(hh>23)){return 0;}
            i_val+=hh.length;}
        else if (token=="KK"||token=="K") {
            hh=_getInt(val,i_val,token.length,2);
            if(hh==null||(hh<0)||(hh>11)){return 0;}
            i_val+=hh.length;}
        else if (token=="kk"||token=="k") {
            hh=_getInt(val,i_val,token.length,2);
            if(hh==null||(hh<1)||(hh>24)){return 0;}
            i_val+=hh.length;hh--;}
        else if (token=="mm"||token=="m") {
            mm=_getInt(val,i_val,token.length,2);
            if(mm==null||(mm<0)||(mm>59)){return 0;}
            i_val+=mm.length;}
        else if (token=="ss"||token=="s") {
            ss=_getInt(val,i_val,token.length,2);
            if(ss==null||(ss<0)||(ss>59)){return 0;}
            i_val+=ss.length;}
        else if (token=="a") {
            if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
            else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
            else {return 0;}
            i_val+=2;}
        else {
            if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
            else {i_val+=token.length;}
            }
        }
    // If there are any trailing characters left in the value, it doesn't match
    if (i_val != val.length) { return 0; }
    // Is date valid for month?
    if (month==2) {
        // Check for leap year
        if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
            if (date > 29){ return 0; }
            }
        else { if (date > 28) { return 0; } }
        }
    if ((month==4)||(month==6)||(month==9)||(month==11)) {
        if (date > 30) { return 0; }
        }
    // Correct hours value
    if (hh<12 && ampm=="PM") { hh=hh-0+12; }
    else if (hh>11 && ampm=="AM") { hh-=12; }
    var newdate=new Date(year,month-1,date,hh,mm,ss);
    return newdate.getTime();
    }
// ------------------------------------------------------------------
 // parseDate( date_string [, prefer_euro_format] )
 //
 // This function takes a date string and tries to match it to a
 // number of possible date formats to get the value. It will try to
 // match against the following international formats, in this order:
 // y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
 // M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
 // d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
 // A second argument may be passed to instruct the method to search
 // for formats like d/M/y (european format) before M/d/y (American).
 // Returns a Date object or null if no patterns match.
 // ------------------------------------------------------------------
 function parseDate(val) {
    var preferEuro=(arguments.length==2)?arguments[1]:false;
    generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
    monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
    dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
    var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
    var d=null;
    for (var i=0; i<checkList.length; i++) {
        var l=window[checkList[i]];
        for (var j=0; j<l.length; j++) {
            d=getDateFromFormat(val,l[j]);
            if (d!=0) { return new Date(d); }
            }
        }
    return null;
    }
  
  //------------------------------------------
  // Function for trimming
  //------------------------------------------

  function trim(s) {
      return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
  } //End of Function trim()

  //------------------------------------------
  // Function to see empty or not
  //------------------------------------------

  function isEmpty(value) {
   
      return (trim(value) == "") ? true : false;
   
   } // End of Function isEmpty()
   
   
   
   
   function takeYear(theDate)
   {
    x = theDate.getYear();
    var y = x % 100;
    y += (y < 38) ? 2000 : 1900;
    return y;
   }
   
   function prePopulateYearCombo(cmbObj,HOW_MANY_YEARS)
    {
      var curDate = new Date();
      var curYear = takeYear(curDate);
      
      for (var i=0; i <= HOW_MANY_YEARS ; i++)
      {
       cmbObj.options[i]  = new Option ((curYear+i),(curYear+i))
      }  
    }
/**
 * fmt = 0 ==> Numeric Format 
 * fmt = 1 ==> 3 letter Format
 * fmt = 2 ==> Full month format
 */
 

function prePopulateMonthCombo(cmbObj,fmt)
{

var month_arr_short = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep' , 'Oct' , 'Nov' , 'Dec']
var month_arr_full = ['January' ,'February','March','April','May','June','July','August','September','October','November','December']
var month_arr_default = ['01', '02', '03', '04', '05', '06', '07', '08', '09' , '10' , '11' , '12']

var curDate = new Date();
var curMonth = curDate.getMonth();

       for (var i=1; i <= 12 ; i++)
        {
           switch (fmt)
            {
              case 0 : cmbObj.options[i-1]  = new Option (month_arr_default[i-1],month_arr_default[i-1]);
                       break;
              case 1 : cmbObj.options[i-1]  = new Option (month_arr_short[i-1],month_arr_default[i-1]);
                       break;
              case 2 : cmbObj.options[i-1]  = new Option (month_arr_full[i-1],month_arr_default[i-1]);
                       break;
              default: cmbObj.options[i-1]  = new Option (month_arr_default[i-1],month_arr_default[i-1]);
                       break;
           }            

         
      }  
      
      cmbObj.options[curMonth].selected = true;
}

 function closeDiv(divid)
         {
          var obj_div =  document.getElementById(divid);
          obj_div.style.display = 'none';
         }
         
 function showDiv(divid,event) {
   var IE = document.all ? true : false
  if (!IE)
   document.captureEvents(Event.MOUSEMOVE)
  var tempX = 0
  var tempY = 0
  if (IE) {
   tempX = event.clientX + document.body.scrollLeft
   tempY = event.clientY + document.body.scrollTop
  }
  else {
   tempX = event.pageX
   tempY = event.pageY

  }
  if (tempX < 0) {
   tempX = 0
  }
  if (tempY < 0) {
   tempY = 0
  }
  var obj_div = document.getElementById(divid);
  obj_div.style.left = tempX+"px";
  obj_div.style.top = tempY+"px";
  obj_div.style.display = 'block';
 
 }

function showDivScreen(divid,event) {
   var IE = document.all ? true : false
  if (!IE)
   document.captureEvents(Event.MOUSEMOVE)
  var tempX = 0
  var tempY = 0
  var screen_tempX = 0
  var screen_tempY = 0
  if (IE) {
   tempX = event.clientX + document.body.scrollLeft
   tempY = event.clientY + document.body.scrollTop
  }
  else {
   tempX = event.pageX
   tempY = event.pageY

  }
  if (tempX < 0) {
   tempX = 0
  }
  if (tempY < 0) {
   tempY = 0
  }
  var screen_size = screen.width;
  screen_tempX = tempX + 600
  screen_tempY = tempY + 600
  if (screen_tempX > screen_size)
  {
      var temp_screen = screen_tempX - screen_size
      tempX = tempX - temp_screen - 50
   }      
  var obj_div = document.getElementById(divid);
  obj_div.style.left = tempX+"px";
  obj_div.style.top = tempY+"px";
  obj_div.style.display = 'block';
 
 }


function showDivReset(divid,event,parameter) {
   var IE = document.all ? true : false
  if (!IE)
   document.captureEvents(Event.MOUSEMOVE)
  var tempX = 0
  var tempY = 0
  if (IE) {
   tempX = event.clientX + document.body.scrollLeft
   tempY = event.clientY + document.body.scrollTop
      if (parameter=='replace')
      {
          tempX = tempX-150
      }
  }
  else {
   tempX = event.pageX
   tempY = event.pageY
   if (parameter=='replace')
      {
          tempX = tempX-150
      }
  }
  if (tempX < 0) {
   tempX = 0
  }
  if (tempY < 0) {
   tempY = 0
  }
  var obj_div = document.getElementById(divid);
  obj_div.style.left = tempX+"px"
  obj_div.style.top = tempY+"px"
  obj_div.style.display = 'block';
 
 }
 
 
 
function displayWindow(divid, form_name)
{
    
    var w, h, l, t;
    w = 400;
    h = 200;
    var div_obj = document.getElementById(divid);
    var div_width = div_obj.style.width;
    var px_index = div_width.indexOf('px');
    
    if(px_index != -1)  {
        div_width = div_width.slice(0,px_index);
    }
    
    div_start = (screen.width/2) - (div_width/2) - 10;
    
    //l = screen.width/4;
    l = div_start;
    t = screen.height/4;
    if(divid == 'webstreaming_slot')    {
        t = 100;
    }

    // with title  

    displayFloatingDiv(divid, 'Floating and Dimming Div', w, h, l, t, form_name);
}


    /**                
    * getObjFromElement    : It will get the child node of the object 
    * Parameters            : cell   : the cell object
    * Return Value          : No Return Value
    * Compatibility         : IE 6.0,Mozilla Firefox 1.0.7, Netscape Navigator 7.1
    **/
    function getObjFromElement(cell,obj)
    {
    var select_element;
    for (var ci=0;ci<cell.childNodes.length;ci++) {
        if (cell.childNodes[ci].tagName && cell.childNodes[ci].tagName.toLowerCase() == obj) select_element = cell.childNodes[ci];
    }
    return select_element;
    }
    
    
    function showHideContent(dest)
    {
       var style=(document.getElementById(dest).style.display=='block')?'none':'block';
       document.getElementById(dest).style.display=style;
    }

    /**
    *
    *  URL encode / decode
    *  http://www.webtoolkit.info/
    *
    **/
    
    var UrlLib = {
    
        // public method for url encoding
        encode : function (string) {
            return escape(this._utf8_encode(string));
        },
    
        // public method for url decoding
        decode : function (string) {
            return this._utf8_decode(unescape(string));
        },
    
        // private method for UTF-8 encoding
        _utf8_encode : function (string) {
            string = string.replace(/\r\n/g,"\n");
            var utftext = "";
    
            for (var n = 0; n < string.length; n++) {
    
                var c = string.charCodeAt(n);
    
                if (c < 128) {
                    utftext += String.fromCharCode(c);
                }
                else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
                else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
    
            }
    
            return utftext;
        },
    
        // private method for UTF-8 decoding
        _utf8_decode : function (utftext) {
            var string = "";
            var i = 0;
            var c = c1 = c2 = 0;
    
            while ( i < utftext.length ) {
    
                c = utftext.charCodeAt(i);
    
                if (c < 128) {
                    string += String.fromCharCode(c);
                    i++;
                }
                else if((c > 191) && (c < 224)) {
                    c2 = utftext.charCodeAt(i+1);
                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                    i += 2;
                }
                else {
                    c2 = utftext.charCodeAt(i+1);
                    c3 = utftext.charCodeAt(i+2);
                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                    i += 3;
                }
    
            }
    
            return string;
        }
    
}