﻿/*<![CDATA[*/
//#################################################### GENERAL SETTINGS 
//#################################################### GENERRAL SETTINGS
// STUDENT VERSION
// Copyright 2009, David Keane, http://ooChaCha.com
// Version 200911010a General Javascrpt Code
// This notice must stay with this code
// Updates of this code may be available from http://www.ooChaCha.com/code/
 
// DEPENDENCIES:
// div tags named dPageHolder,dPopBoxHolder,dPopBoxInfo
// fnReset() function to reset page sizes (dTorso,dLeft,dMiddle and dRight) for incoming information
// dMiddle default div container
// default.html is home page in site root

var gDefaultHomePageURL = "/default.html";

var bool_dLeftWing = false;
var bool_dRightWing = false;
var bool_dLeftWingLock = false;
var bool_dRightWingLock = false;

var gWinW,gWinH;

var gMinTorsoHeight=300;
var gRightWingWidth=150;

var gTimer01;
var gCount=0;
var gPauseCount=false;
var gPauseTimer02=false;
var gTimer02; //check wings plus

var gAllowTags = "#a#div#ul#li#ol#img#span#table#tr#td#input#object#textarea#select#option#ooTag#";
var gAllowExt=".jpg#.gif#.png#.swf#.flv#.mov#.wmv#.mp3#.htm#.html#.asp#.php#.txt#.xml#.aspx#";

var gErrMsg="";
function fnErrReport(newMsg){
    gErrMsg=gErrMsg + newMsg + "<br />";
}

function fnBid(daID){return document.getElementById(daID);}
function fnBids(daID){return document.getElementById(daID).style;}
function fnScrollTo(disX,disY){window.scrollTo(disX,disY);}

function fnCount(){if(!gPauseCount){gCount++;}} //default 50ms

function fnTimer02(){ //test every 1000ms as default
    if(!gPauseTimer02){
 			fnWings();
    }
}



function fnRegisterNewPageItems(){
    // use arguments to register what? document, div etc
    //fnExternalAnchors();
}
function fnExternalAnchors(){
    // under DocType xhtml 1.1 there is no target=_self,_blank,winName
    // uses DOM method to find a and if rel=external then uses the window.open()method
    var vPH=fnBid('bBody');
    if(vPH){ //test if dPageHolder exists - ie ooChaCha system
        var ls=document.getElementsByTagName('a'); // get all a's in complete document
        for(var i=0;i<ls.length;i++){
            if(ls[i].getAttribute('rel')=='external'){
                //ls[i].className+=ls[i].className?' extlink':'extlink';
                ls[i].title+=' (Opens in new window)';
                ls[i].onclick=function(){window.open(this.href);return false;}
            }
        }
    }else{alert("(73) Oops, there seems to be an error");}
}

function fnJump(){
    var vSuccess=true;
    var argsJump = fnJump.arguments; // url,_self/_blank, page options (escape)
    if(!argsJump[0]){alert("(38) No Page Requested");vSuccess=false;}
    if(!argsJump[1]){argsJump[1]="_self";}
    if(!argsJump[2]){argsJump[2]="";}
    if(vSuccess){window.open(argsJump[0],argsJump[1],argsJump[2]);}
}
function fnDelay(disMS){ //note delays full webpage
    var date1 = new Date();
    var date2 = null;
    do{date2 = new Date();} 
    while(date2-date1 < disMS);
} 
function fnEM(){
    var vSuccess=true;
    var argsEAdd = fnEM.arguments;
    if(!argsEAdd[0]){alert("Oops, there seems to be an error");vSuccess=false;}
    if(!argsEAdd[1]){argsEAdd[1]="";}
    if(vSuccess){
        var argsAns = new Array("to:","ail","m","sub","=","dy","@");
        location.href=""+argsAns[2] + argsAns[1] + argsAns[0] + gEAns + argsAns[6] + gEDom + "?" + argsAns[3]+"ject"  + argsAns[4] + gDom + " " + argsEAdd[0] + "&bo" + argsAns[5] + argsAns[4] + argsEAdd[1] + "";
        }
}

function fnPopHolderOO(){
	var disDisplay="none";
    var argsfnPopHolderOO = fnPopHolderOO.arguments; // none,block,on,off
	if(argsfnPopHolderOO[0]=="on" || argsfnPopHolderOO[0]=="block"){disDisplay="block";}
    fnBids('dPopBoxHolder').display=disDisplay;
}

function fnPopImg(url,daTxt){
    fnBids('dPopBoxHolder').display="block";
    fnBid('dPopBoxInfo').innerHTML="<img src='" + url + "' /><br />" + daTxt + "<br /><br />";
}

function fnPopHTML(daCode){
    fnBids('dPopBoxHolder').display="block";
    fnBid('dPopBoxInfo').innerHTML=daCode;
}

function fnPutHTML(){ //target id, HTML code
    var vSuccess = true;
    var argsPutHTML=fnPutHTML.arguments;
    if(!argsPutHTML[0]){vSuccess=false;}
    if(!argsPutHTML[1]){argsPutHTML[1]="Oops, no HTML found";}
    if(fnBid(argsPutHTML[0]) && vSuccess){
        fnBid(argsPutHTML[0]).innerHTML = argsPutHTML[1];
    }else{
        alert("(79) Oops, no id declared");
    }
 
}

function fnImageSwap(){ //target id, imageURL
       var vSuccess = true;
       var argsFnImageSwap = fnImageSwap.arguments; 
	   if(!fnBid(argsFnImageSwap[0])){vSuccess = false;alert("(87) target id does not exist");}
	   if(vSuccess){document.getElementById(daID).src=daImage;}
    }
	
function fnRegObjects(){ // tag to register
    var vSuccess = true;
	var argsFnRegObjects = fnRegObjects.arguments;
	if(!argsFnRegObjects[0]){vSuccess=false;}
	if(vSuccess){
       var daPattern = "#" + argsFnRegObjects[0].toLowerCase() + "#"
	   if (gAllowTags.match(daPattern)){
	        var daObj = document.getElementsByTagName(argsFnRegObjects[0]);
	        for (var i = 0; i < daObj.length; i++){daObj[i].outerHTML = daObj[i].outerHTML;}
			//alert("x(101) " + argsFnRegObjects[0] + " tag found");
	   }else{alert("(102) Oops, " + argsFnRegObjects[0] + " tag name not allowed");}
	}else{alert("(103) Oops, no tag declared in fnRegObjects");}
}

//var gWinW,gWinH;  
function fnWinWH(){
    	var winWidth = 0, winHeight = 0;
        if(typeof(window.innerWidth ) == 'number' ) {
            //For firefox,safari,opera,netscape and other Non-IE browsers
            winWidth = window.innerWidth;
            winHeight = window.innerHeight;
        } else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            winWidth = document.documentElement.clientWidth;
            winHeight = document.documentElement.clientHeight;
    	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            // Old method, IE 4 compatible
            winWidth = document.body.clientWidth;
            winHeight = document.body.clientHeight;
       }else{winWidth=1024;winHeight=550;}

       gWinW=winWidth;
       gWinH=winHeight;
}

function fnWings(){
	   // Next we measure the width of the window to see if we will show the dRightWing (we don't want horizontal scrolling!!)
	   // We'll show the wings if the window width is larger than the dPageHolder + dRightWing*2
       fnWinWH(); // current window width and height
	   var testWidth=1000 + (gRightWingWidth*2); //ie dPageHolder-width + (dRightWing-width * 2) width
	   if(bool_dRightWing){
		   if(gWinW>=testWidth){
			  document.getElementById('dRightWing').style.display="block";
		   }else{
		      if(bool_dRightWingLock){document.getElementById('dRightWing').style.display="block";}else{document.getElementById('dRightWing').style.display="none";}
		   }
	  }else{document.getElementById('dRightWing').style.display="none";}
	  if(bool_dLeftWing){
		   if(gWinW >= testWidth){
			  document.getElementById('dLeftWing').style.display="block";
		   }else{ 
			  if(bool_dLeftWingLock){document.getElementById('dLeftWing').style.display="block";}else{document.getElementById('dLeftWing').style.display="none";}
		   }
	  }else{document.getElementById('dLeftWing').style.display="none";} 
}

function fnReset(){
       // fnReset needed for older browsers that don't recognise ajax input for div resize
       if(gMinTorsoHeight>=0){ 
           //do nothing
       }else{
           alert("(21)(multithreadajax.js) gMinTorsoHeight should be a number");
           gMinTorsoHeight=300;
       }
    // USED for AJAX in-which dMiddle needs to be reset
	// First set div's to auto, ready to measure div offset height's
	// Assuming dTorso is always the max height  (this is not really true but will be for thisexample) then we measure it's height and apply the measured height to the nested div's so they all have the same height.
        document.getElementById('dTorso').style.height="auto";
        document.getElementById('dLeft').style.height="auto";
        document.getElementById('dMiddle').style.height="auto";
        document.getElementById('dRight').style.height="auto";
    	var maxHt = Math.max(gMinTorsoHeight,parseInt(document.getElementById('dLeft').offsetHeight),parseInt(document.getElementById('dMiddle').offsetHeight),parseInt(document.getElementById('dRight').offsetHeight));
    	document.getElementById('dTorso').style.height=maxHt + "px";
        document.getElementById('dLeft').style.height=maxHt + "px";
        document.getElementById('dMiddle').style.height=maxHt + "px";
        document.getElementById('dRight').style.height=maxHt + "px";
}	

function fnGetFileExtension(){
	var arrAtrGFE=fnGetFileExtension.arguments;
	//alert("83 " + arrAtrGFE.length);
	if(arrAtrGFE.length>=1){
    	var disSplitGFE=arrAtrGFE[0].split("?")[0];

		if(disSplitGFE.length>=6){
    	    disSplitGFE="." + (disSplitGFE.substring(disSplitGFE.length-6,disSplitGFE.length)).split(".")[1];
            if(disSplitGFE.match(/(\.jpg)|(\.gif)|(\.png)|(\.swf)|(\.flv)|(\.mov)|(\.wmv)|(\.mp3)/)!=null){
               alert("(90 : ERROR: You should always have media embedded in a coded page, never raw!!)");
            }else{
               if(disSplitGFE.match(/(\.htm)|(\.html)|(\.asp)|(\.php)|(\.txt)|(\.xml)|(\.aspx)|(\.inc)|(\.oocc)/)!=null){
			      return disSplitGFE;
			   }else{alert("(94) ERROR: File type is not a valid AJAX extension");}
			}
		}else{alert("(96) ERROR: File Name length does not seem correct");}
	}else{alert("(97) ERROR: No file named");}
}


/*]]>*/
