﻿
var _timer;
var _arr = new Array();
var _tmpvar;

function $(id){ return document.getElementById(id); }

function FindAll(oNode, sIdPart){
    var aryElements = new Array();
    FindAllHelper(oNode, aryElements, sIdPart);
    return aryElements;
}

function FindAllHelper(oNode, aryElements, sIdPart){
    if(oNode.id && oNode.id.indexOf(sIdPart) >= 0) aryElements.push(oNode);

    if(oNode.firstChild) FindAllHelper(oNode.firstChild, aryElements, sIdPart);
    if(oNode.nextSibling) FindAllHelper(oNode.nextSibling, aryElements, sIdPart);
} 

function GetRootPath(){
    var root = window.location.toString().split('/');
    return root[0] + '//' + root[2] + '/' + root[3] + '/';
}
function IsIE(){
return !!document.all;
}

  function SearchSite(o){
    window.location = _ROOTPATH +'searchsite.aspx?cx=001993386287184627138%3Aopxo8dhcecw&cof=FORID%3A11&sa=Search&q=' + document.getElementById(o).value; 
    }    
    
function ConvertItemContentHtml(html){return html;
var R = /______ItemContentStartPath______/gi;
    return html.replace(R,"http://www.infoverge.info/codeverge/item_content/");
}

function DoTopBg(id){    
    var img; 
    var hour= new Date().getHours();
    if(hour< 1) img = 'url('+_ROOTPATH+'/Images/grad_darkblue.png)';
    else if(hour <7)  img = 'url('+_ROOTPATH+'/Images/grad/blueyellow.png)';
    else if(hour <14)  img = 'url('+_ROOTPATH+'/Images/grad_blue.png)';
    else if(hour <17)  img = 'url('+_ROOTPATH+'/Images/grad_blue_orange2.png)';
    else  img = 'url('+_ROOTPATH+'/Images/grad_blue_orange.png)';
    $(id).style.backgroundImage = img;
}
function t(){
    return new Date().valueOf();
}
function JSProbe(O){  
        if ( typeof O != "object" ) O = EL(O);       
        var str;
        for( i in O) str +=  ("<br/>" +  eval(" i + '-' + O." + i ) );
        var W = window.open("about:blank");
        W.document.write(str) ;     
        return str;
}

function ApplyHotSpot(source, which){
    var tmpStr = '';  

        //strip quotes , put spaces between commas
      var argSplit = source.innerHTML.replace('\'', '').replace('"', '').replace(',', ' , ').split(' ');
//    switch(source.getAttribute('which')){ 
//    case 'item':             
//        which = 'item_tag';
//      break; 
//    case 'interests':
//       which = 'interests';
//    break; 
//    case 'FavBooks':
//        break;            
//   } 
      for(n =0; n< argSplit.length; n++){            
            tmpStr += '<span onclick="OpenIframe(\'iframes/search_results.aspx?which='+which+'&where='+argSplit[n]+
            '&t=\' + new Date().valueOf(), 800, 400) " class="HotSpot">' + argSplit[n] + '</span>&nbsp';
      } 

       source.innerHTML = tmpStr;    
}

function MakeLinksPopup(doc){
    var links = doc.getElementsByTagName('a');
    for(var i =0; i < links.length; i++){
        links[i].target = '_';
    }
}

function ButtonSubmitting(btn){
    if( typeof(Page_ClientValidate) != 'undefined' && !Page_ClientValidate() ){//&& !Page_IsValid
    
     return false;
   }
     btn.onclick = function (){return false};
       btn.style.backgroundImage ='url('+_ROOTPATH+'images/spinner.gif)'
       btn.style.backgroundRepeat='no-repeat'
       btn.style.backgroundPosition='center';
}
function OnlyPosInt(E){
    var code = E.keyCode || E.charCode;
    if( /\D/.test( String.fromCharCode(code) ) ) return false;
}
function GetQsValue(name){
   var qsVar = window.location.toString().split('?');
   if(qsVar[1]) {
   qsVar = qsVar[1].split('&');
       for(i = 0 ;i<qsVar.length; i++){
            var pair = qsVar[i].split('=');
            if(pair[0].toLowerCase() == name.toLowerCase() )
                return pair[1].split('#')[0];      
       }
   }
}
function GetUrlNonQs(){
    return window.location.toString().split('?')[0];
}
function RedirectMain(url){
   var P = window.parent;   
  P = P.parent;
//  P = P.parent;
//  P = P.parent;   
   
//  if (P.opener != null)   P = P.opener;
//  if (P.opener != null)   P = P.opener;
//  if (P.opener != null)   P = P.opener;
   
   P.location = url;
}
function GetQsAnchor(){
    var qsVar = window.location.toString().split('?');
   if(qsVar[1]) qsVar=qsVar[1].split('#');
   else qsVar= window.location.toString().split('#');
   return qsVar[1] ? qsVar[1] : '';
}
function Redirect( arrKeys, arrValues){
     
    var arrQs = window.location.toString().split('?');
     var sPath = arrQs [0]; 
    if(arrQs.length > 1){
        //var arrKeys = new Array() ; var arrValues = new Array(); 
   
        arrQs = arrQs[1].toString().split('&');
       
        for(var p=0; p < arrQs.length; p ++){
              var param = arrQs[p].split('='); 
              //arrKeys.push(param[0]); arrValues.push(param[1]);        
              //alert(qsKeys);
             var bFound = true; 
                for ( x =0; x < arrKeys.length; x++){
                   if( param[0] == arrKeys[x]){ 
                      bFound = false;  break;                  
                   }           
                }      
                if(bFound == true ){ 
                    arrKeys.push( param[0] ) 
                    arrValues.push( param[1] );
                }
//               else{ alert(9);
//                    arrKeys[x] = param[0];
//                    arrValues[x] = param[1];
//               } 
        }      
   }
   
   var sPathAndQuery =   sPath  + '?';    
     for( var p =0; p < arrKeys.length; p++){
            sPathAndQuery +=  '&' + arrKeys[p] + '=' + arrValues[p];   
     }
       
      window.location = sPathAndQuery;
    
}
function BuildNewQs(arrQs, arrNewKeys, arrNewValues){
    var newQS='';
    if(arrQs.length > 1){
        arrQs = arrQs[1].toString().split('&');
        for(var p=0; p < arrQs.length; p++){
             var param = arrQs[p].split('='); 
             var bFound = true; 
                for ( x =0; x < arrNewKeys.length; x++){
                   if( param[0] == arrNewKeys[x]){ 
                      bFound = false;  break;                  
                   }           
                }      
                if(bFound == true ){ 
                    arrNewKeys.push( param[0] ) 
                    arrNewValues.push( param[1] ); 
                  // sPathAndQuery +=  '&' + param[0] + '=' + param[1];   
                }             
        }      
   }

        for ( x =0; x < arrNewValues.length; x++){
              if(x>0) newQS +=  '&' + arrNewKeys[x] + '=' + arrNewValues[x];   
              else newQS +=  '?' + arrNewKeys[x] + '=' + arrNewValues[x];   
        }
        return newQS.split('#')[0];
}
function RedirectSelf(){
 var arrQs = window.location.toString().split('?');
    //var sPath = arrQs [0]; 

    var arrNewKeys=[]; var arrNewValues = [];
    for (i=0; i<arguments.length; i+=2){
        arrNewKeys.push(arguments[i]);
        arrNewValues.push(arguments[i+1]);
   } 
  window.location = window.location.toString().split('?')[0] + BuildNewQs(arrQs, arrNewKeys,arrNewValues);
}

function RedirectNew( url){
 var arrQs = window.location.toString().split('?');
    //var sPath = arrQs [0]; 

    var arrNewKeys=[]; var arrNewValues = [];
    for (i=1; i<arguments.length; i+=2){
        arrNewKeys.push(arguments[i]);
        arrNewValues.push(arguments[i+1]);
   } 
 window.location =url + BuildNewQs(arrQs, arrNewKeys,arrNewValues);
}

function RedirectSort2(){
        
        var  arrQs = GetQsArray().split('&');
      
    var sortDesc = false;
        var args=''; 
        for(var p=0; p < arrQs.length; p ++){
              var param = arrQs[p].split('=');
                if (param[0].toLowerCase() == 'order_desc'){                
                        if( param[1] == '0' ){
                          sortDesc = true;
                        }                           
               }      
             //  args += param[0] + ',' + param[1];
        }
      
      if(sortDesc == true) {
            args += '"order_desc"' + ', "1"';
      }else{
            args += '"order_desc"' + ', "0"';
      }
 
      eval('RedirectSelf('+args+')');        
//     if( QS[QsName.order_desc] != null ) {
//            QS[QsName.order_desc] = QS[QsName.order_desc] == "1" ? "0" :"1";
//        }
//        else {
//            QS[QsName.order_desc] = "0";
//        }       
}

function RedirectSort( arrKeys, arrValues){
        
        var  arrQs = GetQsArray().split('&');
        
         arrKeys.push('order_desc'); arrValues.push('0'); 
        for(var p=0; p < arrQs.length; p ++){
              var param = arrQs[p].split('=');
                if (param[0].toLowerCase() == 'order_desc'){                
                        if( param[1] == '0' ){
                            arrValues.pop();
                            arrValues.push('1');
                        }                           
               }       
        }
      
      Redirect(arrKeys, arrValues);        
//     if( QS[QsName.order_desc] != null ) {
//            QS[QsName.order_desc] = QS[QsName.order_desc] == "1" ? "0" :"1";
//        }
//        else {
//            QS[QsName.order_desc] = "0";
//        }       
}

function GetQsArray(){
    
   var qs = document.location.search; 
      if(qs != null) return qs.substring(1);

    return '';
}

function AppendAnchor(url, anchor){
    return url.toString().split('#')[0] + '#' + anchor;
}

function GoToAnchor(){
  var A = GetQsAnchor();
    if(A){
        window.location = AppendAnchor(window.location , A);    
    }
}
function GoToIframeAnchor(iframeId){
     var A = GetQsAnchor();
       if(A){
        $(iframeId).src = AppendAnchor( $(iframeId).src , A);    
    }
}

function JumpPageSection(){
    if(window.location.toString().indexOf('#') >= 0) setTimeout(function(){  window.location = window.location }, 500);//jump to reply
}
function RedirectParent(url){
    window.parent.location = url;
}

function OnTimeout(){
    alert('Timed Out');
}
function OnError(ex){
    alert(ex.get_message());
}
//function EnforceMaxLength(obj, length ){ //only ie
//    if( obj.value.length > length ) obj.value = obj.value.substring(0, length);
//}
