// JavaScript Document
function $i$(element) {
         if (typeof element == 'string')
         element = document.getElementById(element);
         return (element);
}

function getMousePos(e) {
         var posx = 0;
         var posy = 0;
         if (!e) var e = window.event;
         if (e.pageX || e.pageY)
            { posx = e.pageX;
              posy = e.pageY;
            }
         else if (e.clientX || e.clientY)
            { posx = e.clientX + document.body.scrollLeft
                     + document.documentElement.scrollLeft;
              posy = e.clientY + document.body.scrollTop
                     + document.documentElement.scrollTop;
            }
         mouseX = posx;
         mouseY = posy;
         ecy = e.clientY;
         dbs = document.body.scrollTop;
         dde = document.documentElement.scrollTop;
}

function sendRequestG(url,callback,postData,target) {
         var req = createXMLHTTPObject();
         if (!req) return;
         var method = (postData) ? "POST" : "GET";
         req.open(method,url,true);
         req.setRequestHeader('User-Agent','XMLHTTP/1.0');
         if (postData)
            req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
         req.onreadystatechange = function () { if (req.readyState != 4) return;
                                                      if (req.status != 200 && req.status != 304)
                                                         { var content = document.getElementById(target);
                                                           var errortext = "<div class=error> HTTP ERROR</div>";
                                                           content.innerHTML = errortext;
                                                           return;
                                                         }
                                                      callback(req,target);
                                               }
         if (req.readyState == 4) return;
         req.send(postData);
}

var XMLHttpFactories = [
                           function () {return new XMLHttpRequest()},
                           function () {return new ActiveXObject("Msxml2.XMLHTTP")},
                           function () {return new ActiveXObject("Msxml3.XMLHTTP")},
                           function () {return new ActiveXObject("Microsoft.XMLHTTP")}
                           ];

function createXMLHTTPObject() {
         var xmlhttp = false;
         for (var i=0;i<XMLHttpFactories.length;i++)
             { try
                 { xmlhttp = XMLHttpFactories[i]();
                 }
               catch (e)
                 { continue;
                 }
               break;
             }
         return xmlhttp;
}


function msgRequestG(urlstring,target){
         var content = document.getElementById(target);
         content.innerHTML = urlstring.responseText;
}

function showLoading(target){
         var content = document.getElementById(target);
         content.innerHTML = '<img src="images/ajax-loader.gif" />';
}

function showpopLoading(){
         var content = document.getElementById('popwinContent');
         content.innerHTML = '<img src="images/ajax-loader.gif" />';
         openpopWin();
         }

function popForm(formname) {
         ftop = mouseY-100;
          //  ftop = 100;

         var target = 'popwinContent';
         var poststring = '';
         var frm = document.forms[formname];
         var linkstring = frm.action;
         for (var i = 0; i < frm.length; i++ )
             { if ((frm.elements[i].type == "radio" && !frm.elements[i].checked) ||  frm.elements[i].type == "submit")
               {
               }
            else
               { poststring = poststring  + frm.elements[i].name + '=' + frm.elements[i].value + '&';
               }
            }
          poststring = poststring.substr(0,poststring.length-1);
          showpopLoading();
         //   alert(linkstring + ' -- '+poststring)
         sendRequestG(linkstring, popResponse, poststring, target);
}


function popScript(linkstring){
         var x=getScrollXY1() ;
          

            ftop = (x[1] + 100) ;

       //  ftop = mouseY-100;
       //  ftop = mouseY+100;
         //  ftop = 100;
         target = 'popwinContent';
         showpopLoading();
        // alert(linkstring);
         sendRequestG(linkstring ,popResponse,'',target);
}

function popScriptRenew(linkstring){
         ftop = mouseY-100;
         //  ftop = 100;
         target = 'popwinContent';
         refreshtoURL = location.href;
         showpopLoading();
         //    alert(cat + '-' + boxnum);
         sendRequestG(linkstring ,popResponse,'',target);
}

function popFrame (url, div, width, height) {

  document.getElementById(div).innerHTML = "<div class='popFrameHdrwrapper' style='width:100%;'>" +
  " <span class='popFrameHdr' style='width: "+(width-20)+"px;'></span>" +
    "<span class='popFrameClose' onClick='closeOpts(\""+ div + "\")' title='Close Window'></span>" +
   "</div><iframe src='" + url + "' width='"+width+"' height='" + height + "'></iframe>";
  document.getElementById(div).style.display = 'block';
  return false;
}



function setReturnURL (URL) {
         refreshtoURL = URL;
}

function popResponse (originalRequest,target) {
         $i$(target).innerHTML = originalRequest.responseText;

         openpopWin();
         return false;
}

function openpopWin() {
         $i$('popwinFloater').style.visibility= 'hidden';
         $i$('popwinFloater').style.position = 'absolute';
         $i$('popwinFloater').style.top = ftop+'px';
         $i$('popwinFloater').style.display = 'block';
         $i$('popwinBg').style.display= 'block'  ;
         var xx = setTimeout("pop2()",100);
}

function pop2(){

         var winsize = winSize();
         var wwidth = winsize[0];
         fwidth = $i$('popwinContframe').scrollWidth;
         $i$('popwinClose').style.left = (fwidth-20)+'px';
         $i$('popwinFloater').style.width = fwidth+'px';
         $i$('popwinFloater').style.left = ((wwidth-fwidth)/2)+'px';
         $i$('popwinFloater').style.visibility= 'visible';
         $i$('popwinHdr').style.width = (1000 - 20) + 'px';
        // var to = setTimeout('findpopJScripts("popwinContent")' ,1000);
        // findpopJScripts("popwinContent")         ;
}
function closepopWin() {

          if('undefined' != typeof(refreshtoURL))
            { var  xx = 1 + window.location.pathname.lastIndexOf('/')
              var   xloc = window.location.pathname.substr(xx)+ window.location.search + window.location.hash
            if (xloc == refreshtoURL)
               {
              window.location.reload(true)
              }
            else
              { window.location.replace(refreshtoURL);
              }
            }

          $i$('popwinFloater').style.display = 'none';
          $i$('popwinBg').style.display = 'none';
          $i$('popwinContent').innerHTML = '';
}

function findpopJScripts(divid) {
    div = $i$(divid)
    var x = div.getElementsByTagName("SCRIPT");  
   // alert (x.length)
    for(var i=0;i<x.length;i++)  
    { // alert(i + x[i].text + typeof(x[i].text)+x[i].text.length)
       if (x[i].text.length > 0)
       {  var code = ('self.ajaxjs' + i + ' = '+ x[i].text); 
          var code = (x[i].text);
          if ((window.attachEvent && ! window.opera)) 
          { 
      // ie 
      execScript (code); 
          } 
          else 
          {      
            window.eval(code); 
          }
       } 
       else
       { // alert (x[i].src);
         var headID = document.getElementsByTagName("head")[0];
         var newScript = document.createElement('script');
         newScript.type = 'text/javascript';
         newScript.src = x[i].src; 
         headID.appendChild(newScript);
       }          
    }  
    
   
 }



function clearCatboxes(boxnum) {
         for ( i = boxnum +1; i<=5; i++)
         { var target =  document.getElementById('catbox'+i);
           target.innerHTML = '';
         }
}


function getNextCat(cat, boxnum){
         boxnum = parseInt(boxnum);
         if ( null != ($i$('done3')))
            { $i$('done3').style.display = 'none';
              $i$('done4').style.display = 'none';
              $i$('done5').style.display = 'none';
               if (boxnum > 2)
               { document.forms[('step3')].groupcat.value = cat;
                 $i$('done'+  boxnum).style.display = 'inline';
               }
               else
              { document.forms['step3'].topcat.value = cat;

              }

            }
         else
            { if (boxnum > 2 )
              { document.forms['step3'].groupcat.value = cat;

              }
              else
              { document.forms['step3'].topcat.value = cat;

              }

            }
         if (cat == '6')
            { return;
            }
         var rand = Math.random(9999);
         var target = 'catbox'+ boxnum;
         clearCatboxes(boxnum);
         showLoading(target);
         var linkstring = 'hi_get_nextcat.php?cat=' + cat +'&boxnum=' + boxnum;
         sendRequestG(linkstring ,msgRequestG,'',target);
}

function showAddCat(boxnum){
         boxnum = parseInt(boxnum);
         clearCatboxes(boxnum);
         document.getElementById('catinput' + boxnum).style.display = 'inline';
         document.getElementById('catsub' + boxnum).style.display = 'inline';
         document.getElementById('catinput' + boxnum).focus() ;
}

function addCat(formname)  {
      if (null != $i$('done3'))
            { $i$('done3').style.display = 'none';
              $i$('done4').style.display = 'none';
              $i$('done5').style.display = 'none';
            }
      var frm = document.forms[formname];
      target='catbox' + (document.forms[formname].boxnum.value);
      if (frm.catname.value == '')
         {  return false;
         }
      st2box = frm.boxnum.value;
      var linkstring = 'hi_get_nextcat.php'
      var poststring = 'cat=' + frm.cat.value + '&boxnum=' + frm.boxnum.value + '&catname=' + frm.catname.value + '&add=yes';
      sendRequestG(linkstring, addCatStep2, poststring, target);
}


function addCatStep2(req, target)  {
         msgRequestG(req, target);
         getNextCat($i$('catSave'+st2box).innerHTML,$i$('boxSave'+st2box).innerHTML);
}

function formHandler(formname) {
         var poststr = '';
         var frm = document.forms[formname];
         var linkstring = frm.action;
         for (var i = 0; i < frm.length; i++ )
             {
               poststr = poststr + frm.elements[i].name + '=' + frm.elements[i].value + '&';
             }
            // documents.forms[formname].elements[number].
         alert(poststr.substr(0,poststr.length-1));
         sendRequestG(linkstring, msgRequestG, poststring, target);
}

function getScrollXY1() {
         var scrOfX = 0, scrOfY = 0;
         if ( typeof( window.pageYOffset ) == 'number' )
            { scrOfY = window.pageYOffset;  //Netscape compliant
              scrOfX = window.pageXOffset;
            }
         else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
           {  scrOfY = document.body.scrollTop;        //DOM compliant
              scrOfX = document.body.scrollLeft;
           }
         else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
           {  scrOfY = document.documentElement.scrollTop;  //IE6 standards compliant mode
              scrOfX = document.documentElement.scrollLeft;
           }
         return [ scrOfX, scrOfY ];
}

function winSize() {
         var myWidth = 0, myHeight = 0;
         if ( typeof( window.innerWidth ) == 'number' )
            { myWidth = window.innerWidth;  //Non-IE
              myHeight = window.innerHeight;
            }
         else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
            { myWidth = document.documentElement.clientWidth;        //IE 6+ in 'standards compliant mode'
              myHeight = document.documentElement.clientHeight;
            }
         else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
            { myWidth = document.body.clientWidth;     //IE 4 compatible
              myHeight = document.body.clientHeight;
            }
         return[myWidth, myHeight]
}

AIM = {
 
  frame : function(c) {
 
    var n = 'f' + Math.floor(Math.random() * 99999);
    var d = document.createElement('DIV');
    d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
    document.body.appendChild(d);
 
    var i = document.getElementById(n);
    if (c && typeof(c.onComplete) == 'function') {
      i.onComplete = c.onComplete;
    }
 
    return n;
  },
 
  form : function(f, name) {
    f.setAttribute('target', name);
  },
 
  submit : function(f, c) {
    AIM.form(f, AIM.frame(c));
    if (c && typeof(c.onStart) == 'function') {
      return c.onStart();
    } else {
      return true;
    }
  },
 
  loaded : function(id) {
    var i = document.getElementById(id);
    if (i.contentDocument) {
      var d = i.contentDocument;
    } else if (i.contentWindow) {
      var d = i.contentWindow.document;
    } else {
      var d = window.frames[id].document;
    }
    if (d.location.href == "about:blank") {
      return;
    }
 
    if (typeof(i.onComplete) == 'function') {
      i.onComplete(d.body.innerHTML);
    }
  }
 
}

    function startCallbackX() {
        // make something useful before submit (onStart)
       // alert(refreshtoURL);
         ftop = mouseY-100;
        showpopLoading();
        return true;
      }


      function startCallback() {
        // make something useful before submit (onStart)
        var frm = document.forms['addimage'];
        window.pars = '?ID=' + frm.groupid.value +'&act=0';
        return true;
      }

      function startCallback1() {
        // make something useful before submit (onStart)
        var frm = document.forms['addimage'];
        window.pars = '?ID=' + frm.groupid.value +'&act=0';
        return true;
      }

      function startCallbackVid() {
        // make something useful before submit (onStart)
        var frm = document.forms['addimage'];
        window.pars = '?ID=' + frm.groupid.value +'&act=1';
        return true;
      }

      function startCallbackYt() {
        // make something useful before submit (onStart)
        var frm = document.forms['addimage'];
        window.pars = '';
        return true;
      }

      function startCallbackRec() {
        // make something useful before submit (onStart)
        var frm = document.forms['addrec'];
        window.pars = '?page=' + frm.groupname.value ;
        return true;
      }

      function completeCallback(response) {
        // make something useful after (onComplete)
       if (response != '' )
         { document.getElementById('popwinContent').innerHTML = response;
           openpopWin();
         }
       else
         {  var sURL = unescape(window.location.pathname);
            window.location.href = sURL + window.pars;
         }
      }

      function completeCallbackLoad(response) {
        // make something useful after (onComplete)
       if (response != '' )
         { document.getElementById('popwinContent').innerHTML = response;
           firstflag = 0;
           loadPlayer('Elv8_sW6atc');
           openpopWin();
         }
       else
         {  var sURL = unescape(window.location.pathname);
            window.location.href = sURL + window.pars;
         }
      }
      function startCallbackCloseImage() {

        // make something useful before submit (onStart)
        var frm = document.forms['addimage'];
        window.pars = '?ID=' + frm.groupid.value +'&act=0';
        return true;
      }

      function completeCallbackClose(response) {
        // make something useful after (onComplete)
        var sURL = unescape(window.location.pathname);
        window.location.href = sURL + window.pars;

      // window.location.reload( true );
      // document.getElementById('popwinContent').innerHTML = response;
      // openpopWin();
      }

      function checknoValue(field){     
     if (field.value == "")    
        { alert('Please Enter a Title');
          return false
        }
     return true
}      

