/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var loadstatustext="<img src='/images/loading.gif' /> Requesting content..."

var jsLength1 = "";
var jsLength2 = "";
var jsTotalHeight1 = "";
var jsTotalHeight2 = "";
var jsTotalWidth = "";
var jsTotalWeight = "";
var jsStageHeight = "";
var jsMotorSpace = "";

var jsWidth1 = "";
var jsWidth2 = "";
var jsLeftAngle = "";
var jsRightAngle = "";
var jsCenterAngle = "";
var jsBridalHeight = "";
var jsStageToMotor = "";
var jsWeightDownRight = "";
var jsWeightDownLeft = "";
var jsWeightTopLeft = "";
var jsWeightTopRight = "";
var jsWeightBridalLeft = "";
var jsWeightBridalRight = "";
var jsFolderID = "";
var jsPointNum = "";

var isOwner = "";

function ajaxpage(url, containerid){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
	return false
	document.getElementById(containerid).innerHTML=loadstatustext
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
}
//document.getElementById(containerid).innerHTML=loadstatustext

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	document.getElementById(containerid).innerHTML=page_request.responseText
}


function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
	var file=arguments[i]
	var fileref=""
	if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function bridle_DoFSCommand(command, args) {
	var bridleObj = isInternetExplorer ? document.all.bridle: document.bridle;
	 if (command == "jsLength1") {
		jsLength1 = args;
	 }
	 if (command == "jsLength2") {
		 jsLength2 = args;
	 }
	 if (command == "jsTotalHeight1") {
		 jsTotalHeight1 = args;
	 }
	 if (command == "jsTotalHeight2") {
		 jsTotalHeight2 = args;
	}
	 if (command == "jsTotalWidth") {
		 jsTotalWidth = args;
	}
	 if (command == "jsTotalWeight") {
		 jsTotalWeight = args;
	}
	 if (command == "jsStageHeight") {
		 jsStageHeight = args;
	}
	 if (command == "jsMotorSpace") {
		 jsMotorSpace = args;
	}
	if (command == "jsWidth1") {
		 jsWidth1 = args;
	}
	if (command == "jsWidth2") {
		 jsWidth2 = args;
	}
	if (command == "jsLeftAngle") {
		 jsLeftAngle = args;
	}
	if (command == "jsRightAngle") {
		 jsRightAngle = args;
	}
	if (command == "jsCenterAngle") {
		 jsCenterAngle = args;
	}
	if (command == "jsBridalHeight") {
		 jsBridalHeight = args;
	}
	if (command == "jsStageToMotor") {
		 jsStageToMotor = args;
	}
	if (command == "jsWeightDownRight") {
		 jsWeightDownRight = args;
	}
	if (command == "jsWeightDownLeft") {
		 jsWeightDownLeft = args;
	}
	if (command == "jsWeightTopLeft") {
		 jsWeightTopLeft = args;
	}
	if (command == "jsWeightTopRight") {
		 jsWeightTopRight = args;
	}
	if (command == "jsWeightBridalLeft") {
		 jsWeightBridalLeft = args;
	}
	if (command == "jsWeightBridalRight") {
		 jsWeightBridalRight = args;
	}
	if (command == "jsFolderID") {
		 jsFolderID = args;
	}
	if (command == "jsPointNum") {
		 jsPointNum = args;
	}
	 if (command == "updatePoint") {
		updatePoint();
	}
	 if (command == "save") {
		saveTitleItem = args;
		saveTitleItem = escape(saveTitleItem);
		if((saveTitleItem == '') || (saveTitleItem == 'undefined')){
			alert('Please enter a title') ;
		}
		else {
			save(saveTitleItem);
		}
	}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub bridle_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call bridle_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

function loadBridleData(length1, length2, totalHeight1, totalHeight2, totalWidth, totalWeight, stageHeight, motorSpace,title,pointnum,isOwner){
	document.getElementById('dynPointTitle').innerHTML='<b>Point:</b> #'+pointnum+' <b>Title:</b> '+title;
	document.getElementById('dynPointTitle').style.display = ""; 

	   window.document.bridle.SetVariable("cLength1", length1);
	   window.document.bridle.SetVariable("cLength2", length2);
	   window.document.bridle.SetVariable("cTotalHeight1", totalHeight1);
	   window.document.bridle.SetVariable("cTotalHeight2", totalHeight2);
	   window.document.bridle.SetVariable("cTotalWidth", totalWidth);
	   window.document.bridle.SetVariable("totalWeight.inputData", totalWeight);
	   window.document.bridle.SetVariable("cStageHeight", stageHeight);
	   window.document.bridle.SetVariable("cMotorSpace", motorSpace);
	   
	   window.document.bridle.SetVariable("pointNum", pointnum);
	   window.document.bridle.SetVariable("ThisTitle", title);
	   window.document.bridle.SetVariable("isOwner", isOwner);
}

function save(saveTitleItem){
	ajaxpage('/savebridle?pointnum='+jsPointNum+'&folder='+jsFolderID+'&title='+saveTitleItem+'&userid='+SessionUserID+'&action=save&a='+jsLength1+'&b='+jsLength2+'&d='+jsTotalHeight1+'&e='+jsTotalHeight2+'&f='+jsTotalWidth+'&g='+jsTotalWeight+'&h='+jsStageHeight+'&j='+jsMotorSpace+'&k='+jsWidth1+'&l='+jsWidth2+'&m='+jsLeftAngle+'&n='+jsRightAngle+'&o='+jsCenterAngle+'&p='+jsBridalHeight+'&q='+jsStageToMotor+'&r='+jsWeightDownRight+'&s='+jsWeightDownLeft+'&t='+jsWeightTopLeft+'&u='+jsWeightTopRight+'&v='+jsWeightBridalLeft+'&w='+jsWeightBridalRight+'&sid='+SessionID, 'saveThisShit')
	window.location.hash = "#save";
	document.getElementById('dynPointTitle').innerHTML='<b>Point:</b> #'+jsPointNum+' <b>Title:</b> '+unescape(saveTitleItem);
	document.getElementById('dynPointTitle').style.display = ""; 
}

function updatePoint(){
	ajaxpage('/savebridle?pointnum='+jsPointNum+'&folder='+jsFolderID+'&userid='+SessionUserID+'&action=updatepoint&a='+jsLength1+'&b='+jsLength2+'&d='+jsTotalHeight1+'&e='+jsTotalHeight2+'&f='+jsTotalWidth+'&g='+jsTotalWeight+'&h='+jsStageHeight+'&j='+jsMotorSpace+'&k='+jsWidth1+'&l='+jsWidth2+'&m='+jsLeftAngle+'&n='+jsRightAngle+'&o='+jsCenterAngle+'&p='+jsBridalHeight+'&q='+jsStageToMotor+'&r='+jsWeightDownRight+'&s='+jsWeightDownLeft+'&t='+jsWeightTopLeft+'&u='+jsWeightTopRight+'&v='+jsWeightBridalLeft+'&w='+jsWeightBridalRight+'&sid='+SessionID, 'saveThisShit')
	window.location.hash = "#save";
}


function cellbg(cellid,cellcolour)
{
	var CellList=cellid.split(',');
	var ColList=cellcolour.split(',');
	if(CellList.length!=ColList.length || CellList.length==0 ||
	ColList.length==0) return false;

	for(n=0;n<CellList.length;n++)
		{
		document.getElementById(CellList[n]).style.backgroundColor=ColList[n];
		}
}

function openFolder(FID, FName){
	document.getElementById('dynFolderTitle').innerHTML="<b>Folder: </b>"+FName;
	document.getElementById('dynFolderTitle').style.display = ""; 
	ajaxpage('/savebridle?action=openfolder&folderid='+FID+'&userid='+SessionUserID+'&sid='+SessionID, 'saveThisShit');
	window.document.bridle.SetVariable("folderID", FID);
	window.document.bridle.SetVariable("folderName", FName);
}

function closeFolder(){
	document.getElementById('dynFolderTitle').innerHTML="";
	document.getElementById('dynFolderTitle').style.display = "none"; 
	document.getElementById('dynPointTitle').innerHTML="";
	document.getElementById('dynPointTitle').style.display = "none"; 
	ajaxpage('/savebridle?userid='+SessionUserID+'&sid='+SessionID, 'saveThisShit');
	window.document.bridle.SetVariable("folderID", '');
	window.document.bridle.SetVariable("folderName", '');
	window.document.bridle.SetVariable("pointNum", 0);
}

function clonePoint(pointID, infid){
	var newPointNum=document.getElementById? document.getElementById('newPointNum') : ""
	var newPointTitle=document.getElementById? document.getElementById('newPointTitle') : ""
	newPointTitle = escape(newPointTitle.value);
	ajaxpage('/savebridle?action=clonepoint&process=yes&infid='+infid+'&pointid='+pointID+'&newpointnum='+newPointNum.value+'&newpointtitle='+newPointTitle+'&userid='+SessionUserID+'&sid='+SessionID, 'saveThisShit')
}
function listenClonePointEnter(e, pointID, infid){
var key=e.keyCode || e.which;
	if (key==13){
	clonePoint(pointID, infid);
	}
}

function editPoint(pointID, infid){
	var newPointNum=document.getElementById? document.getElementById('newPointNum') : ""
	var newPointTitle=document.getElementById? document.getElementById('newPointTitle') : ""
	newPointTitle = escape(newPointTitle.value);
	ajaxpage('/savebridle?action=editpoint&process=yes&infid='+infid+'&pointid='+pointID+'&newpointnum='+newPointNum.value+'&newpointtitle='+newPointTitle+'&userid='+SessionUserID+'&sid='+SessionID, 'saveThisShit')
}
function listenEditPointEnter(e, pointID, infid){
var key=e.keyCode || e.which;
	if (key==13){
	editPoint(pointID, infid);
	}
}

function addNewTitle(){
	var newFolderTitle=document.getElementById? document.getElementById('newFolderTitle') : ""
	newFolderTitle = escape(newFolderTitle.value);
	ajaxpage('/savebridle?action=newfolder&newtitle='+newFolderTitle+'&userid='+SessionUserID+'&sid='+SessionID, 'saveThisShit')
}
function listenNewTitleEnter(e){
var key=e.keyCode || e.which;
	if (key==13){
	addNewTitle();
	}
}

function editFolder(folderID){
	var newFolderTitle=document.getElementById? document.getElementById('newFolderTitle') : ""
	newFolderTitle = escape(newFolderTitle.value);
	ajaxpage('/savebridle?action=editfolder&process=yes&folderid='+folderID+'&newfoldertitle='+newFolderTitle+'&userid='+SessionUserID+'&sid='+SessionID, 'saveThisShit')
}
function listenEditFolderEnter(e, folderID){
var key=e.keyCode || e.which;
	if (key==13){
	editFolder(folderID);
	}
}

function cloneFolder(folderID){
	var cloneFolderTitle=document.getElementById? document.getElementById('cloneFolderTitle') : ""
	cloneFolderTitle = escape(cloneFolderTitle.value);
	ajaxpage('/savebridle?action=clonefolder&process=yes&folderid='+folderID+'&newfoldertitle='+cloneFolderTitle+'&userid='+SessionUserID+'&sid='+SessionID, 'saveThisShit')
}
function listenCloneFolderEnter(e, folderID){
var key=e.keyCode || e.which;
	if (key==13){
	cloneFolder(folderID);
	}
}