/****************************************************************************/
/*		Following code is used for Tab control in FrmDesignTool.asp			*/
/*																			*/
/*																			*/
/****************************************************************************/
/***** BCIT Student ****
//Allows For second catering tab
function switchOnMenu(tab,contents) {
	switchAllOffMenu();
	document.getElementById(tab).className = 'selectedtab';
	document.getElementById(contents).className = 'selectedcontents';
}
//Allows For second catering tab
function clearTopMenu() {
	topRow = document.getElementById('toprow_menu');
	tabArray = topRow.childNodes;
	for (var i=0; i<(tabArray.length-1); i++) {
		if (tabArray[i].className != 'tabspacer') {
			tabArray[i].className = 'tab';
		}
	}
}
//Allows For second catering tab
function clearContentsMenu() {
	contentsCell = document.getElementById('contentscel2');
	contentsArray = contentsCell.childNodes;
	for (var j=0; j<contentsArray.length; j++) {
		contentsArray[j].className = 'contents';
	}
}
//Allows For second catering tab
function switchAllOffMenu() {
	clearTopMenu();
	clearContentsMenu();
}
/************************/
function FreezeScreen(msg) {
    if (typeof(Page_ClientValidate) == 'function') {
        if (Page_ClientValidate() == false){
        return false;
        }
    }
    scroll(0,0);
    var outerDiv = document.getElementById('FreezeScreen');
    var innerDiv = document.getElementById('FreezeMessage');
    if (outerDiv) outerDiv.className = 'FreezeScreenOn';
    if (innerDiv) innerDiv.innerHTML = msg;
}

function FreezeScreenOff() {
    var outerDiv = document.getElementById('FreezeScreen');
    var innerDiv = document.getElementById('FreezeMessage');
    if (outerDiv) outerDiv.className = 'FreezeScreenOff';
    if (innerDiv) innerDiv.innerHTML = '';
}
        
function switchOn(tab,contents) {
	switchAllOff();
	document.getElementById(tab).className = 'selectedtab';
	document.getElementById(contents).className = 'selectedcontents';
}

function clearTop() {
	topRow = document.getElementById('toprow');
	tabArray = topRow.childNodes;
	for (var i=0; i<tabArray.length; i++) {
		if (tabArray[i].className != 'tabspacer') {
			tabArray[i].className = 'tab';
		}
	}
}

function clearContents() {
	contentsCell = document.getElementById('contentscell');
	contentsArray = contentsCell.childNodes;
	for (var j=0; j<contentsArray.length; j++) {
		contentsArray[j].className = 'contents';
	}
}

function switchAllOff() {
	clearTop();
	clearContents();
}

// Shows the invalid division
function show(div,nest)
{ 	
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='visible';
}

//Hides the div
function hide(div,nest)
{
	GetLayerStyle(div).display="none"	
}

function GetLayer(layername)
{
	GetLayerStyle(div).display="block"
}

function GetLayerStyle(layername)
{
    if(bw.ie4||bw.ie5||bw.ns4) return (bw.ns4) ? FindLayer(layername) : document.all[layername].style;
    else if(bw.ns5) return document.getElementById(layername).style;
}

function FindLayer(layername, obj)
{
   // recursive function to find the layer
    var i=0;
    var perObj = null;
    var tmpObj = (obj) ? obj.document.layers : document.layers;
    for(i=0;i<tmpObj.length;i++)
    {
        if(tmpObj[i].id==layername) return tmpObj[i];
        perObj = FindLayer(layername, tmpObj[i])
         if(perObj) return perObj;
    }
    return false;
}

/****************************************************************************/
/*		Following code is used for Draging Input Controls					*/
/*																			*/
/*																			*/
/****************************************************************************/

function GetDivObject(Div_ID)
{
	/* MSIE, Konqueror, Opera : */
	if (window.document.all)
		return eval("window.document.all."+Div_ID);

	/* Netscape6/Mozilla : */
	if (bw.ns5) //typeof(window.document.getElementById)=="function")
		return window.document.getElementById(Div_ID);

	/* uebrig bleibt Netscape4 : */
	return eval("window.document."+Div_ID);
}


function getDivObj(obj,nest){
	nest=(!nest) ? '':'document.'+nest+'.';									
   	this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;
	return this;
}

wID = ""; 
function winOpen(page, FrmType) {
	var w, h, scrl;
	if(FrmType==0) {
		w = 300;
		h = 250;
		scrl = 'no';
	}else {
		w = 280;
		h = 480;
		scrl = 'no';
	}
	if(isOpen()) wID.close();
	wID = window.open(page, "FormDesign","width="+w+",height="+h+",scrollBars="+scrl+",dependent=yes");
	
	return wID;
}

function isOpen() {
	return (wID && !wID.closed);
}

function winClose(){
	if(isOpen()) wID.close();
}
function setWin(child_win) {
	wID = child_win;
}
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
}
var bFrmDesignEnabled = false;
function setFrmDesignOn() {
	bFrmDesignEnabled = true;
}
function setFrmDesignOff() {
	bFrmDesignEnabled = false;
}
/********************************************************************************
Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/
var oDrag;
//Default browsercheck, added to all scripts!
function checkBrowser(){
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie5=(document.all && this.dom)?1:0;
	this.ie4 = (document.all && !this.dom) ? 1 : 0;
	this.ns5 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;

	
	//Added by Darshit, to resolve Conflict of IE9
	try {
	    if (this.ns5 == 1 && navigator.appName == 'Microsoft Internet Explorer') {
	        this.ns5 = 0;
	    }
	}
	catch (e)
	{ }
	
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
	return this;
}
/********************************************************************************
Remember to set the width and height to the same as the clip values when
you change on the layers. If you are adding a image in one of the layers
do like I have done on divDrag3 (see style), add is as a background-image.
Then the drag will be smoother. Remember to set the the height, width and clip
to the exact same as the size of you image.
********************************************************************************/

/********************************************************************************
Object constructor part.
Setting the objects methods and properties
********************************************************************************/
function dragObj(obj,nest){
	nest=(!nest) ? '':'document.'+nest+'.';									
   	this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;		
	this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;		
	this.x=(bw.ns4 || bw.ns5)? this.css.left:this.css.pixelLeft;
	this.y=(bw.ns4 || bw.ns5)? this.css.top:this.css.pixelTop;			
	this.moveIt=b_moveIt;
	this.drag=false;
	this.clickedX=0; this.clickedY=0;	
	return this;
}
function b_moveIt(x,y){
	this.x=x; this.y=y;
	this.css.left=this.x;
	this.css.top=this.y;
}
function mmover(e){
	var objEl;
	var iContIndex;
	if (typeof bFrmDesignEnabled != 'undefined') {

		if(bFrmDesignEnabled) {
			tp=(bw.ns5 || bw.ns4)?e.target.name:window.event.srcElement.tagName;
			if(tp=="DIV" || bw.ns4 || bw.ns5){
				if(bw.ns4 || bw.ns5) {
					objEl = e.target.id;
				}else{
					objEl = window.event.srcElement.id;
				}
				if (!isBlank(objEl)) {
					if (objEl.length>0) {
						//Add control id to the length of divDrag
						iContIndex = objEl.indexOf("_") + 1;
						num=(bw.ns4 || bw.ns5)?objEl.substr(7+iContIndex):(bw.ie4 || bw.ie5)?objEl.substr(7+iContIndex):0;
//						alert(oDrag[parseInt(num)]);
						if (oDrag[parseInt(num)] != null) {
						    oDrag[parseInt(num)].isOver=true;
						    oDrag[parseInt(num)].css.background="#e6e6fa";
						    oDrag[parseInt(num)].css.cursor="move";
						}
					}
				}
			}
		}
	}
}
function mmout(e){
	var objEl;
	var iContIndex;
	if (typeof bFrmDesignEnabled != 'undefined') {
		if(bFrmDesignEnabled) {
			tp=(bw.ns5 || bw.ns4)?e.target.name:window.event.srcElement.tagName;
			if(tp=="DIV" || bw.ns4 || bw.ns5){
				if(bw.ns4 || bw.ns5) {
					objEl = e.target.id;
				}else{
					objEl = window.event.srcElement.id;
				}
				if (!isBlank(objEl)) {
					if (objEl.length>0) {
						//Add control id to the length of divDrag
						iContIndex = objEl.indexOf("_") + 1;

						num=(bw.ns4)?e.target.id.substr(7+iContIndex):(bw.ie4 || bw.ie5)?window.event.srcElement.id.substr(7+iContIndex):0;
						if(bw.ns5) {
							for(var i=0; i<oDrag.length;i++){
								oDrag[i].isOver=false;
								oDrag[i].css.background=0; //"";//"#FFFFFF";
							}
						} else {
						    //alert(oDrag[parseInt(num)]);
						    if (oDrag[parseInt(num)] != null) {
							    oDrag[parseInt(num)].isOver=false;
							    oDrag[parseInt(num)].css.background=0; //"";//"#FFFFFF";
							}
						}
					}
				}
			}
		}
	}
}

function mup(){
	if (typeof bFrmDesignEnabled != 'undefined') {
		if(bFrmDesignEnabled) {
			for(var i=0; i<oDrag.length;i++){
				if(oDrag[i].isOver) {
					oDrag[i].drag=false;
					//set the position info
					setPosValue(i, oDrag[i].css.left, oDrag[i].css.top);
				}	
			}
		}
	}
}
function mdown(num){
	if (typeof bFrmDesignEnabled != 'undefined') {
		if(bFrmDesignEnabled) {
			x=(bw.ns4 || bw.ns5)?num.pageX:event.x;
			y=(bw.ns4 || bw.ns5)?num.pageY:event.y;
			for(var i=0; i<oDrag.length;i++){
				if(oDrag[i].isOver) {
					oDrag[i].drag=true;
					oDrag[i].clickedX=x-oDrag[i].x;
					oDrag[i].clickedY=y-oDrag[i].y;
					cZIndex++;
					oDrag[i].css.zIndex=cZIndex;
				}
			}
		}
	}
}
function mmove(e){
	if (typeof bFrmDesignEnabled != 'undefined') {
		if(bFrmDesignEnabled) {
			x=(bw.ns4 || bw.ns5)?e.pageX:event.x;
			y=(bw.ns4 || bw.ns5)?e.pageY:event.y;
			for(var i=0; i<oDrag.length;i++){
				if(oDrag[i].drag){
					oDrag[i].moveIt(x-oDrag[i].clickedX,y-oDrag[i].clickedY);
				}
			}
			return false      
		}
	}
}

/********************************************************************************
Set this variable to the zIndex you want it to start at, (if you have several
layers and want it to start on the top, change to somthing higher then the uppermost layer
********************************************************************************/
cZIndex=10;


