function imageholderclass(){
  this.over=new Array();
  this.down=new Array();
  this.src=new Array();
  this.store=store;
  
  function store(src, down, over){
    var AL=this.src.length;
    this.src[AL]=new Image(); this.src[AL].src=src;
    this.over[AL]=new Image(); this.over[AL].src=over;
    this.down[AL]=new Image(); this.down[AL].src=down;
  }
}

var ih = new imageholderclass();
var mouseisdown=0;

function preloader(t){
  for(i=0;i<t.length;i++){
    if(t[i].getAttribute('srcover')||t[i].getAttribute('srcdown')){
      
      storeimages(t[i]);
      var checker='';
      checker=(t[i].getAttribute('srcover'))?checker+'A':checker+'';
      checker=(t[i].getAttribute('srcdown'))?checker+'B':checker+'';
      
      switch(checker){
      case 'A' : mouseover(t[i]);mouseout(t[i]); break;
      case 'B' : mousedown(t[i]); mouseup2(t[i]); break;
      case 'AB' : mouseover(t[i]);mouseout(t[i]); 
                  mousedown(t[i]); mouseup(t[i]); break;
      default : return;      
      }
      
      if(t[i].src){t[i].setAttribute("oldsrc",t[i].src);}
    }
  }
}

function mouseup(t){
  var newmouseup;
  if(t.onmouseup){
    t.oldmouseup=t.onmouseup;
    newmouseup= 
      function(){mouseisdown=0;
                 this.src=this.getAttribute("srcover");
                 this.oldmouseup();}

  }
  else{
    newmouseup = 
      function(){mouseisdown=0;
                 this.src=this.getAttribute("srcover");}
  }
  t.onmouseup=newmouseup;
}

function mouseup2(t){
  var newmouseup;
  if(t.onmouseup){
    t.oldmouseup=t.onmouseup;
    newmouseup=function(){mouseisdown=0;
               this.src=this.getAttribute("oldsrc");
               this.oldmouseup();}
    }
  else{newmouseup=function(){mouseisdown=0;
                  this.src=this.getAttribute("oldsrc");}}
  t.onmouseup = newmouseup;
}

function mousedown(t){
  var newmousedown;
  if(t.onmousedown){
    t.oldmousedown=t.onmousedown;
    newmousedown=
      function(){if(mouseisdown==0)
                 {this.src=this.getAttribute("srcdown");
                  this.oldmousedown();}}
  }
  else{newmousedown=
       function(){if(mouseisdown==0){
                      this.src=this.getAttribute("srcdown");}}}
  t.onmousedown=newmousedown;
}

function mouseover(t){
  var newmouseover;
  if(t.onmouseover){
    t.oldmouseover=t.onmouseover;
    newmouseover= function(){this.src=this.getAttribute("srcover");
                             this.oldmouseover();}
  }
  else{newmouseover=function(){this.src=this.getAttribute("srcover");}}
  t.onmouseover=newmouseover;
}

function mouseout(t){
  var newmouseout;
  if(t.onmouseout){
    t.oldmouseout=t.onmouseout;
    newmouseout = 
   function(){this.src=this.getAttribute("oldsrc");this.oldmouseout();}
  }
  else{newmouseout=function(){this.src=this.getAttribute("oldsrc");}}
  t.onmouseout=newmouseout;
}

function storeimages(t){
  var s=(t.getAttribute('src'))?t.getAttribute('src'):'';
  var d=(t.getAttribute('srcdown'))?t.getAttribute('srcdown'):'';
  var o=(t.getAttribute('srcover'))?t.getAttribute('srcover'):'';
  ih.store(s,d,o);
}

function preloadimgsrc(){
  if(!document.getElementById) return;
  var it=document.getElementsByTagName('IMG');
  var it2=document.getElementsByTagName('INPUT');
  preloader(it);
  preloader(it2);
}

if(window.addEventListener)
  {window.addEventListener("load", preloadimgsrc, false);} 
else{
  if(window.attachEvent){window.attachEvent("onload", preloadimgsrc);}
  else{if(document.getElementById){window.onload=preloadimgsrc;}}
}

/*
function ShouldWeRefresh ()
{
	try
	{
		if (document.form2.needtorefresh.value == 'y') 
		{
		location.reload()
		} 
	document.form2.needtorefresh.value = 'y' 
	}
	catch (exceptionObject) 
	{ 
	 
	} 
}
*/
//to send form action to another window.....
function createTarget(form) {
	_target = form.target;
	_colon = _target.indexOf(":");
	if(_colon != -1) {
		form.target = _target.substring(0,_colon);
		form.args = _target.substring(_colon+1);
	} else if(typeof(form.args)=="undefined") {
		form.args = "";
	}
	if(form.args.indexOf("{")!=-1) {
		_args = form.args.split("{");
		form.args = _args[0];
		for(var i = 1; i < _args.length;i++) {
			_args[i] = _args[i].split("}");
			form.args += eval(_args[i][0]) + _args[i][1];
		}
	}
	//LeftPosition = (screen.width) ? (screen.width-form.args[0])/2 : 0;
	//TopPosition = (screen.height) ? (screen.height-form.args[1])/2 : 0;


form.args = form.args.replace(/ /g,"");
form.args = form.args + ", top=/'400/', left=/'400/'"
//form.args = form.args + ", top='" + TopPosition + "', left='" + LeftPosition + "'"
alert(form.args);
_win = window.open('',form.target,form.args);
if(typeof(focus)=="function")
	_win.focus();
return true;
}


//ajax implemetation of alert box controller
/*function CreateXmlHttp()
{
    //Creating object of XMLHTTP in IE
    try
    {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch()
        {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari
    if(!XmlHttp && typeof XMLHttpRequest != "undefined")
    {
        XmlHttp = new XMLHttpRequest();
    }
}*/
//var http = CreateXmlHttp()

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq(action) {
	alert("sndReq");
    http.open('GET', '/includes/app/displayAlertIncl.asp?rnd=' + Math.random()*4 );
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
		alert(response);
        var update = new Array();
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}


function ShouldWeRefresh ()
{
	try
	{
		if (document.refreshForm.needtorefresh.value == 'y') 
		{
		  location.reload()
		} 
		document.refreshForm.needtorefresh.value = 'y' 
	}
		catch (exceptionObject) 
	{ 
	 
	} 

}

/*function OpenEngine(page)
{
	engineWindow = open(page, 'newwindow', config='height=588, width=755, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	if (engineWindow.opener == null) engineWindow.opener = self;
	//var didEngineClose = setInterval("navToQuiz()", 750);
}*/

function OpenEngine(page, player, courseId)
{
	if (player =='audioSlides'){
		engineWindow = open(page, 'newwindow', config='height=588, width=755, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	}
	if (player =='videoSlides'){
		engineWindow = open(page, 'newwindow', config='height=650, width=1024, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
	}
	if (player =='miniPlayer'){
		document.location = '/lectureMiniEngine.asp?courseid=' + courseId
	}
	if (engineWindow.opener == null) engineWindow.opener = self;
	//var didEngineClose = setInterval("navToQuiz()", 750);
}


