// EETIMES JavaScript Document //

 

// DROP DOWN MENU SCRIPT START//

 

function MM_jumpMenu(targ,selObj,restore){ //v3.0

 

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}

 

 

function MM_reloadPage(init) {  //reloads the window if Nav4 resized

  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}

  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

 

MM_reloadPage(true);

 

// DROP DOWN MENU SCRIPT END//

 

 

 

/* Top Story Tab Script Start*/
function searchtab( searchtab )
{
      if( searchtab == "topstory" )
      {
            var div_obj_pub = document.getElementById( 'topstory' );
            var div_obj_unpub = document.getElementById( 'mostpopularstories' );

            if( div_obj_pub.style.display == "none" ){
            div_obj_pub.style.display = "inline";
           }
            if ( div_obj_unpub.style.display == "inline" ){
                    div_obj_unpub.style.display = "none";
            }
      }
       if( searchtab == "mostpopularstories" )
      {
            var div_obj_pub = document.getElementById( 'topstory' );
            var div_obj_unpub = document.getElementById( 'mostpopularstories' );
            
            if( div_obj_pub.style.display == "inline" ){
                  div_obj_pub.style.display = "none";
            }
            if( div_obj_unpub.style.display == "none" ){
                  div_obj_unpub.style.display = "inline";
            }
      }
}
/* Top Story Tab Script End*/

/* Latest News Tab Script Start*/ 
function latestnewstab( latestnewstab )
{
      var div_obj_pub = document.getElementById( 'currentweek' );
      var div_obj_unpub = document.getElementById( 'lastweek' );
      var div_obj_unpub1 = document.getElementById( 'lastmonth' );
      if( latestnewstab == "currentweek" ){
            if( div_obj_pub.style.display == "none" ){
                  div_obj_pub.style.display = "inline";
            }

            if ( div_obj_unpub.style.display == "inline" ){
                  div_obj_unpub.style.display = "none";
            }

            if ( div_obj_unpub1.style.display == "inline" ){
                  div_obj_unpub1.style.display = "none";
            }

      }

       if( latestnewstab == "lastweek" ){
            if( div_obj_pub.style.display == "inline" ){
                  div_obj_pub.style.display = "none";
            }


            if( div_obj_unpub.style.display == "none" ){
                  div_obj_unpub.style.display = "inline";
            }

            if ( div_obj_unpub1.style.display == "inline" ){
                  div_obj_unpub1.style.display = "none";
            }
      }

            if( latestnewstab == "lastmonth" )
        {

            if( div_obj_pub.style.display == "inline" ){
                  div_obj_pub.style.display = "none";
            }
                            

            if( div_obj_unpub.style.display == "inline" ){
                  div_obj_unpub.style.display = "none";
            }

            if ( div_obj_unpub1.style.display == "none" ){
                  div_obj_unpub1.style.display = "inline";
            }

      }

}

 

/* Latest News Tab Script End*/

 

 

/* Top Story News Tab Script Start*/

function topstorytab( todaytopstory )
{
      var div_obj_pub = document.getElementById( 'today' );
      var div_obj_unpub = document.getElementById( 'topstorylastweek' );
      var div_obj_unpub1 = document.getElementById( 'topstorylastmonth' );

      if( todaytopstory == "today" ){
            if( div_obj_pub.style.display == "none" ){
                  div_obj_pub.style.display = "inline";
            }

            if ( div_obj_unpub.style.display == "inline" ){
                  div_obj_unpub.style.display = "none";
            }

            if ( div_obj_unpub1.style.display == "inline" ){
                  div_obj_unpub1.style.display = "none";
            }
      }
       if( todaytopstory == "topstorylastweek" ){
            if( div_obj_pub.style.display == "inline" ){
                  div_obj_pub.style.display = "none";
            }

            if( div_obj_unpub.style.display == "none" ){
                  div_obj_unpub.style.display = "inline";
            }

            if ( div_obj_unpub1.style.display == "inline" ){
                  div_obj_unpub1.style.display = "none";
            }
      }

      if( todaytopstory == "topstorylastmonth" )
      {
            if( div_obj_pub.style.display == "inline" ){
                  div_obj_pub.style.display = "none";
            }

            if( div_obj_unpub.style.display == "inline" ){
                  div_obj_unpub.style.display = "none";
            }

            if ( div_obj_unpub1.style.display == "none" ){
                  div_obj_unpub1.style.display = "inline";
            }
      }

}

/* Top Story News Tab Script End*/

 

/* For Design Articles */
    function openDesignSite(){
        if( document.getElementById("designArticles").value=="" ){
            alert("Please Select an option and click on GO button");
            document.getElementById("designArticles").select();
            //return false;
        }else{
            window.open(document.getElementById("designArticles").value);
        }
        //return flag;
    }
    
    function openNewProductSite(){
        if( document.getElementById("newProducts").value=="" ){
            alert("Please Select an option and click on GO button");
            document.getElementById("newProducts").select();
            //return false;
        }else{
            window.open(document.getElementById("newProducts").value);
        }
        //return flag;
    }
    
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function



function urlDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

var END_OF_INPUT = -1;

var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);

var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}

var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != END_OF_INPUT){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != END_OF_INPUT){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != END_OF_INPUT){
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}
function readReverseBase64(){   
    if (!base64Str) return END_OF_INPUT;
    while (true){      
        if (base64Count >= base64Str.length) return END_OF_INPUT;
        var nextCharacter = base64Str.charAt(base64Count);
        base64Count++;
        if (reverseBase64Chars[nextCharacter]){
            return reverseBase64Chars[nextCharacter];
        }
        if (nextCharacter == 'A') return 0;
    }
    return END_OF_INPUT;
}

function ntos(n){
    n=n.toString(16);
    if (n.length == 1) n="0"+n;
    n="%"+n;
    return unescape(n);
}

function decodeBase64(str){
    setBase64Str(str);
    var result = "";
    var inBuffer = new Array(4);
    var done = false;
    while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT
        && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){
        inBuffer[2] = readReverseBase64();
        inBuffer[3] = readReverseBase64();
        result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
        if (inBuffer[2] != END_OF_INPUT){
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
            if (inBuffer[3] != END_OF_INPUT){
                result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3]));
            } else {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return result;
}

var digitArray = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
function toHex(n){
    var result = ''
    var start = true;
    for (var i=32; i>0;){
        i-=4;
        var digit = (n>>i) & 0xf;
        if (!start || digit != 0){
            start = false;
            result += digitArray[digit];
        }
    }
    return (result==''?'0':result);
}

function pad(str, len, pad){
    var result = str;
    for (var i=str.length; i<len; i++){
        result = pad + result;
    }
    return result;
}

function encodeHex(str){
    var result = "";
    for (var i=0; i<str.length; i++){
        result += pad(toHex(str.charCodeAt(i)&0xff),2,'0');
    }
    return result;
}



function decodeHex(str){
    str = str.toUpperCase().replace(new RegExp("s/[^0-9A-Z]//g"));
    var result = "";
    var nextchar = "";
    for (var i=0; i<str.length; i++){
        nextchar += str.charAt(i);
        if (nextchar.length == 2){
            result += ntos(hexv[nextchar]);
            nextchar = "";
        }
    }
    return result;
    
}    



function calc_Month(year,num_p,val)
    {
        
        if(num_p==1 || num_p== 3 || num_p == 5 || num_p == 7 || num_p == 8 || num_p==10 || num_p==12)
        {
            return 31;
        }
        else if(num_p==4 || num_p== 6 || num_p == 9 || num_p == 11 )
        {
             return 30;
        }
        else if(num_p==2)
        {
            if(calc_Leap(year))        
            {
                return 29;
            }
            else
            {
                return 28;
            }
        }

    }

function calc_Leap(year)
{
        if(year%4!=0)
        {
            return false;
        }
        else 
        {
            if(year%100!=0)
            {
                return true;
            }
            else
            {
                if (year% 400 != 0) 
                { 
                    return false;
                 } 
                 else 
                { 
                    return true;
                 } 
            }
        }
}
 

 function getMonthString(month){
    var monthString;

    switch( month ){
    case 1:{
            monthString = "Jan";        
            break;
        }
    case 2:{
            monthString = "Feb";
            break;
        }
    case 3:{
            monthString = "Mar";        
            break;
        }
    case 4:{
            monthString = "Apr";
            break;
        }
    case 5:{
            monthString = "May";        
            break;
        }
    case 6:{
            monthString = "Jun";
            break;
        }
    case 7:{
            monthString = "Jul";        
            break;
        }
    case 8:{
            monthString = "Aug";
            break;
        }
    case 9:{
            monthString = "Sep";        
            break;
        }
    case 10:{
            monthString = "Oct";
            break;
        }
    case 11:{
            monthString = "Nov";        
            break;
        }
    case 12:{
            monthString = "Dec";
            break;
        }

    }
    return monthString;
}


    function arrangeDates( datesString ){
        var datesArray = datesString.split(",");
        var datesAfterArranging = "";
        var dateVal = "";
        for( var dateCounter=0; dateCounter<datesArray.length; dateCounter++ ){
            var tempDate = datesArray[ dateCounter ];
            var tempDateArray = tempDate.split("/");
            tempDate = arrangeDayOfDate( tempDateArray[0] ) + "/" + arrangeMonthOfDate( tempDateArray[1] ) + "/" + tempDateArray[2];
            if( datesAfterArranging == "" ){
                datesAfterArranging = tempDate;
            }else{
                datesAfterArranging = datesAfterArranging + "," + tempDate;
            }
        }
        alert( datesAfterArranging );
        return datesAfterArranging;
    }
    
    function arrangeDayOfDate( dayVal ){
        if( dayVal.length<2 ){
            dayVal = "0"+dayVal;
        }
        return dayVal;
    }

    function arrangeMonthOfDate( monthVal ){
        if( monthVal.length<2 ){
            monthVal = "0" + monthVal;
        }
        return monthVal;
    }
