var win = "";

function Popup(mypage, myname, w, h, scroll, r)
{	
	if (myname == "" || win.closed || win.name == undefined)
	{
	  var winl = (screen.width - w) / 2;
	  var wint = (screen.height - h) / 2;
	  winprops = 'height=' + h + ',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+r
	  win = window.open(mypage, myname, winprops);
	  if (window.focus) {win.window.focus();}
	} 
	else
	{
	  if (window.focus) {win.window.focus();}
	}
}

function borderMe(obj, w)
{
	if (w == 0)
	{
		obj.border = 0;
		obj.hspace = 2;
		obj.vspace = 2;
	}
	else
	{
		obj.border = 1;
		obj.hspace = 1;
		obj.vspace = 1;
	}
}
function redirect(weburl)
{
	var path = window.location.pathname;
	var newLocation = window.location.host;
	var p = location.protocol;
	path = path.substring(0, path.lastIndexOf("/"));		
	newLocation = p + "//" + newLocation + path + "/" + weburl;	
	window.location.href = newLocation;
}

var suf1 = "co.";
var suf2 = "uk";
var dmn = "clickschool"; 

function pnteml(emlname,caption) {
  if (caption==undefined) {
   caption = emlname; 
  }
  mailstring= "<a href='javascript:emlaunch(\"" + emlname + "\");' title='Contact Address'>"+ caption +"</a>";
  document.write(mailstring);
}

function emlaunch(emlname) {
  var thsads = "ma" + "i" + "lto:" + emlname + "@" + dmn + "." + suf1 + suf2;
  document.location=thsads;
}

function toggleSelection(formName)
{	
	//checkboxes-select/deselete all
	var i = 0;
	var frm = eval("document." + formName);
	var total = frm.totalRows.value;

	isOn = true;
	if(frm.cb0.checked) isOn = false;	

	for (i = 0; i < total; i++)
	{						
		x = eval("document." + formName + ".cb" + i);
		x.checked = isOn;
	}
}

function ajaxObject(url, callbackFunction) {
  var that=this;      
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }

  this.update = function(passData,postMethod) { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() {  
        if (that.AJAX.readyState==4) {             
          that.updating=false;                
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
        var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}

function isEnter(e, obj)
{
	var kk=e.charCode? e.charCode : e.keyCode
	if(kk==13) return true;
}

function getIds(formName)
{
	//return selected Ids from any objRecordset
	var param = "";
	if(formName==undefined)
	{
		// can't find formName
	}
	else
	{
		var ids = formName.elements["id[]"];	
		var id = 0;		
		if(!ids.length)
		{
			//if only 1 element then it's not treated as array...weird.
			if(eval("document." + formName.name + ".cb0").checked) param = formName.elements["id[]"].value;
		}
		else
		{
			for(i=0;i<ids.length;i++)
			{
				
				id = ids[i].value;
				cb = eval("document." + formName.name + ".cb" + i);
				if(cb.checked) param = param + id + "¬";		
			}
		}	
		if(param=="") alert("Select something first...");
	}
	return param;
}


function tutorialLink(id, text)
{
	document.write("<P><A href='#' onclick='tutorialShow(\"" + id + "\")'><IMG src='_images/tutor2.gif' height='42' width='41' border='0' align='center'>TUTORIAL: " + text + "</A></P>");
}

function tutorialShow(tName)
{
	 var winl = (screen.width - 800) / 2;
	 var wint = (screen.height - 500) / 2;
	  
	tutorial = window.open('', 'tutorial', 'height=500,width=800,top=' + wint + ',left=' + winl);
	var c = tutorial.document;
	c.write("<HTML><HEAD><STYLE>BODY{margin:0px}</STYLE><TITLE>Click School Tutorials</TITLE></HEAD><BODY>");
	c.write('<embed width="800" height="500" src="i.php?i=pages/1226/tutorialsImg.swf&website=pages/1226/&tutorialName='+tName+'" quality="high" pluginspace="http://www.adobe.com/go/getflashplayer" align="middle" play="true" loop="true" scale="noscale" wmode="window" devicefont="false" bgcolor="#FFFFFF" name="tutorialsImg" menu="false" allowFullScreen="true" allowScriptAccess="sameDomain" salign="lt" type="application/x-shockwave-flash"></embed>');
	c.write('</BODY></HTML>');
	c.close();
}

function mp3Show(fName, fldr)
{	
	var q = '<embed width="165" height="37" src="playerMP3.swf?website=' +fldr + '&file='+fName+'.mp3" quality="high" pluginspace="http://www.adobe.com/go/getflashplayer" align="middle" play="true" loop="true" scale="noscale" wmode="window" devicefont="false" bgcolor="#FFFFFF" name="playerMP3" menu="false" allowFullScreen="true" allowScriptAccess="sameDomain" salign="lt" type="application/x-shockwave-flash"></embed>';	
	document.write(q);
}

function flvShow(pList, fldr)
{
	var q = '<embed width="698" height="286" src="playerFLV.swf?website=' +fldr + '&pList='+pList+'" quality="high" pluginspace="http://www.adobe.com/go/getflashplayer" align="middle" play="true" loop="true" scale="noscale" wmode="window" devicefont="false" bgcolor="#FFFFFF" name="playerFLV" menu="false" allowFullScreen="true" allowScriptAccess="sameDomain" salign="lt" type="application/x-shockwave-flash"></embed>';	
	document.write(q);
}

function swfShowPopup(fName, fldr, w, h)
{
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2; 

	swfWindow = window.open('', 'tutorial', 'height='+h+',width='+w+',top=' + t + ',left=' + l);
	var c = swfWindow.document;
	//c.write("<HTML><HEAD><STYLE>BODY{margin:0px}</STYLE><TITLE>Click School</TITLE></HEAD><BODY>");	
	c.write('<embed width="100%" height="100%" src="i.php?i='+fldr+fName+'&website='+fldr+'" quality="high" pluginspace="http://www.adobe.com/go/getflashplayer" align="middle" play="true" loop="true" scale="exactfit" wmode="window" devicefont="false" bgcolor="#FFFFFF" name="tutorialsImg" menu="false" allowFullScreen="true" allowScriptAccess="sameDomain" salign="lt" type="application/x-shockwave-flash"></embed>');	
	//c.write('</BODY></HTML>');
	c.close();	
}

function basename (path, suffix) {
    // example 1: basename('/www/site/home.htm', '.htm');
    // returns 1: 'home' 
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function urlGet(weburl)
{
	var path = window.location.pathname;
	var newLocation = window.location.host;
	var p = location.protocol;
	path = path.substring(0, path.lastIndexOf("/"));	
	return p + "//" + newLocation + path + "/" + weburl;
}

function redirect(weburl)
{	
	window.location.href =  urlGet(weburl);
}

function focusSet(objId)
{
	var obj = document.getElementById(objId);
	if(obj!=null)
	{
		obj.focus();
	}
}
