

var pgnm;
var level;
var ref;
function relPage(p,l){
var bEL = document.getElementById("b");
var atrval = bEL.getAttribute("onunload");
if(atrval==""){
atrval = "callpage('"+p+"','"+l+"');";
}else{
atrval = "callpage('"+p+"','"+l+"');";
}
//alert(atrval);
}

//Call the onload functions
function setUpOnLoad(){
 // loadImg();
  setPrevButt();
  }
//preload loader image
function loadImg(){
 var img1 = new Image();
 img1.src = "http://127.0.0.1/zenarcade/za_loader.gif";
 }

//Set up the previous button
function setPrevButt(){
var butt = document.getElementById('negbutt_lft');
var butt2 = document.getElementById('negbutt_rght');
    butt.style.background = 'url(bwd_arw_dsabld.png) no-repeat';
    butt.style.cursor= 'auto';
    butt2.onmouseover = changeIconFwd;
    butt2.onmouseout = resetIconFwd;
 }

//Function : track the current page

function pageTracker(pgnm,ref){
var p = pgnm;
var r = ref;
var t;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            t = new XMLHttpRequest();
            if (t.overrideMimeType) {
               t.overrideMimeType('text/xml');
              }
        }
        else if (window.ActiveXObject) { // IE
            try {
                t = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    t = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {}
            }
        }

var url="./page_tracker.php/"; //call page_tracker.php (writes the prev/next buttons to output)
url=url+"?pgnm="+p;
t.onreadystatechange = function() { getPageName(t,r); };/*Call funtion to write ajax response and reset*/
t.open("GET",url,true);                                 /* event handler actions for menu items and prev/next buttons.*/
t.send(null);
}

//Get the page content from db - this function called from getcontent_main_ajax.php
function callpage(pgnm,level,ref){
var p = pgnm;
var l = level;
var r = ref;
//Call the pagetracker function
pageTracker(p,r);

var xmlHttp;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            xmlHttp = new XMLHttpRequest();
            if (xmlHttp.overrideMimeType) {
               xmlHttp.overrideMimeType('text/xml');
              }
        }
        else if (window.ActiveXObject) { // IE
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {}
            }
        }

var url="./getcontent_main_ajax.php/";
url=url+"?"+p+"="+p+l+"&pgnm="+p;
xmlHttp.onreadystatechange = function() { getContent(xmlHttp,r); };
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

//call vd gallery
var vd_id;var relref;
function callvdgal(relref,vd_id){
var gal;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            gal = new XMLHttpRequest();
            if (gal.overrideMimeType) {
               gal.overrideMimeType('text/xml');
              }
        }
        else if (window.ActiveXObject) { // IE
            try {
                gal = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    gal = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {}
            }
        }
var url="./site_dbf.php/";
url=url+"?vd_id="+vd_id+"&gal=item&ref="+relref;
//alert(url);
gal.onreadystatechange = function() { getClip(gal); };
gal.open("GET",url,true);
gal.send(null);
}

//Paginate the video gallery
var galdb;var start;var nps;
function PaginateVdgal(galdb,start,nps){
var pgnte;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            pgnte = new XMLHttpRequest();
            if (pgnte.overrideMimeType) {
               pgnte.overrideMimeType('text/xml');
              }
        }
        else if (window.ActiveXObject) { // IE
            try {
                pgnte = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    pgnte = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {}
            }
        }
var url="./site_dbf.php/";
url=url+"?galdb="+galdb+"&s="+start+"&nps="+nps;
//alert(url);
pgnte.onreadystatechange = function() { paginate(pgnte); };
pgnte.open("GET",url,true);
pgnte.send(null);
}
function paginate(pgnte){
//alert(pgtitle);
  if (pgnte.readyState == 4) {
       if (pgnte.status == 200) {
       document.getElementById("content").innerHTML= pgnte.responseText;
         } else {
             alert('System error 1: Oops! Request status problem.');
            }
      }else{
      document.getElementById("content").innerHTML='Loading .... ';
   }
 }

function loader(){
var bar =new Object(document.getElementById("load"));
var temp=bar.value;
bar.value =temp+"|";
if(bar.value.length == 38){
bar.value="Loading: ";
}
 setTimeout("loader();","100");
}

//Funtion to write ajax response and reset event handler actions for menu items and prev/next buttons

function getPageName(t,ref){
var a = 0;
var b = 0;
//Define element arrays
var navbar = document.getElementById('navbar');
var linkarr = navbar.getElementsByTagName('a');
var actb = document.getElementById('buttbar');
var buttarr = actb.getElementsByTagName('input');
var tot = linkarr.length;

//Check ajax response
  if (t.readyState == 4) {
       if (t.status == 200) {
	 //Write the output
	document.getElementById('prevnext').innerHTML= t.responseText;
           //Previous/next buttons navigation actions
	 if(ref==0){
	   for(b=0;b<2;b++){
	      if(b==ref){
	      buttarr[b].style.background = 'url(bwd_arw_dsabld.png) no-repeat';
	      buttarr[b].style.cursor= 'auto';
	      buttarr[1].onmouseover = changeIconFwd;
	      buttarr[1].onmouseout = resetIconFwd;
	      }
	    }
	  }
	      else if(ref == (tot-1)){
		for(b=0;b<2;b++){
		  buttarr[1].style.background = 'url(fwd_arw_dsabld.png) no-repeat';
		  buttarr[1].style.cursor= 'auto';
		  buttarr[0].onmouseover = changeIconBwd;
		  buttarr[0].onmouseout = resetIconBwd;
	          }
		}
	      else{
		for(b=0;b<2;b++){
	        buttarr[0].style.background = 'url(bwd_gray.png) no-repeat';
		buttarr[1].style.background = 'url(fwd_gray.png) no-repeat';
		buttarr[0].onmouseover = changeIconBwd;
		buttarr[0].onmouseout = resetIconBwd;
		buttarr[1].onmouseover = changeIconFwd;
		buttarr[1].onmouseout = resetIconFwd;
	        }
	      }
             //sinc Menu items navigation actions with prev/next buttons
              for(a=0;a<tot;a++){
		if(linkarr[a].id > 0 ){
		   linkarr[a].setAttribute("onmouseover","this.style.opacity=1");
		   linkarr[a].setAttribute("onmouseout","this.style.opacity=0.7");
		   if(a == ref){
		   linkarr[a].style.color='#e43907';
	           linkarr[a].removeAttribute("onmouseout","this.style.color='#47494a'");
		   }
                   else if(a!=ref){
		   linkarr[a].style.color = '#47494a';
		   }
		}
             }
       }
    else{  //Throw request/response error
       alert('System error 1: Oops! Request status problem.');
    }
    }else{  //waiting for response .....
     document.getElementById("prevnext").innerHTML='';
    }
}

function getClip(gal){
//alert(pgtitle);
  if (gal.readyState == 4) {
       if (gal.status == 200) {
       document.getElementById("content").innerHTML= gal.responseText;
         } else {
             alert('System error 1: Oops! Request status problem.');
            }
      }else{
       document.getElementById("content").innerHTML='Loading ....';
   }
 }


function getContent(xmlHttp,ref){
//alert(pgtitle);

  if (xmlHttp.readyState == 4) {
       if (xmlHttp.status == 200) {
       document.getElementById("content").innerHTML= xmlHttp.responseText;
       /*loader image test*/
     // document.getElementById("content").innerHTML='<div id="loader"><img  src="ajax_loader.gif" ></div>';
       } else {
        alert('System error 1: Oops! Request status problem.');
        }
        }else{
        document.getElementById("content").innerHTML='<div id="loader"><img  src="ajax_loader.gif" ></div>';
   }
 }

function colorChange(){
 var navbar = document.getElementById('navbar');
 var linkarr = navbar.getElementsByTagName('a');
 var tot1 = linkarr.length;
 for(a=0;a<tot1;a++){
    linkarr[a].style.color='#00f200';
  }
}

function colorReset(){
 var navbar = document.getElementById('navbar');
 var linkarr = navbar.getElementsByTagName('a');
 var tot1 = linkarr.length;
  for(a=0;a<tot1;a++){
    linkarr[a].style.color='#ffffff';
}
}

function changeIconBwd(){
 var butt = document.getElementById('negbutt_lft');
 butt.style.background = 'url(bwd_or.png) no-repeat';
    }

function resetIconBwd(){
 var butt = document.getElementById('negbutt_lft');
 butt.style.background = 'url(bwd_gray.png) no-repeat';
 }


function changeIconFwd(){
   var butt = document.getElementById('negbutt_rght');
   butt.style.background = 'url(fwd_or.png) no-repeat';
   }

  function resetIconFwd(){
   var butt = document.getElementById('negbutt_rght');
   butt.style.background = 'url(fwd_gray.png) no-repeat';
   }
function showDrpMen(subid,listid,imgid){
  //alert(subid);
  var drop = document.getElementById(subid);
  var sub = document.getElementById(listid);
 // var img = document.getElementById(imgid);
 /// img.setAttribute("src","whte_arr_up.png");
 // img.setAttribute("style","border:2px solid #ffffff;-moz-border-radius:3px;padding:1px");
 // img.style.paddingBottom = 2 + 'px';
 // img.style.border
  sub.style.color = '#ffffff';
  sub.style.background = 'url(gray_arr_up.png) 90% 50% no-repeat #c89033';
  sub.style.paddingLeft = 3 +'px';
  sub.style.paddingTop = 3 +'px';
  sub.style.paddingBottom = 3 +'px';
  sub.style.fontWeight = 'bold';
  sub.style.fontSize = 14 + 'px';
  sub.style.textAlign = 'left';
  drop.style.display = '';
 // drop.style.color = '#2b6587';
  drop.style.top = 2 +'px';
  drop.style.left = -5 + 'px';
  drop.style.bottom = 5 + 'px';
  drop.style.marginBottom= 0 +'px';
  drop.style.paddingTop = 3 +'px';
  var par = 'closeDrop(\''+subid+'\',\''+listid+'\',\''+imgid+'\')';
 // alert(par);
  sub.setAttribute("onclick",''+par+'');

 }
function closeDrop(subid,listid,imgid){
  var drop = document.getElementById(subid);
  var sub = document.getElementById(listid);
  /*var img = document.getElementById(imgid);*/
 /* img.setAttribute("src","or_arr_dwn.png");*/
 // img.setAttribute("style","border:2px solid #e43907;-moz-border-radius:3px;padding:2px");

  drop.style.display = 'none';
  sub.style.color = '#000';
  sub.style.background = 'url(gray_arr_dwn.png) 90% 50% no-repeat #fff';
  sub.style.paddingLeft = 4 +'px';
  sub.style.paddingTop = 5 +'px';
  sub.style.paddingBottom = 5 +'px';
  sub.style.fontWeight = 'bold';
  sub.style.textAlign = 'left';
  sub.style.fontSize = 18 + 'px';
  var par = 'showDrpMen(\''+subid+'\',\''+listid+'\',\''+imgid+'\')';
  sub.setAttribute("onclick",''+par+'');
}



