﻿//------------------------------------------------------------------------------
//
// ADOBE SYSTEMS INCORPORATED
// Copyright 2000-2002 Adobe Systems Incorporated 
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute 
// this file in accordance with the terms of the Adobe license 
// agreement accompanying it. If you have received this file 
// from a source other than Adobe, then your use, modification, 
// or distribution of it requires the prior written permission 
// of Adobe.
//
//------------------------------------------------------------------------------


//----------------------------------------------------
// parse functions:
//
// Description:
//   Called by parseBox() for each custom box.
//   Display error message if box inserted in 
//   incorrect location.
//  Set and create links on the box.

function parseA(box, reason)
{		
	if (!document) {
		// there should always be a document
		// since the custom box is drawn in a document
		return;
	}
	var version = getWMLVersion(document);
		
	box.ctlAhref = (box.element.href) ?
		box.createLink (box.element.href) :
		box.createLink (settings.masterPrefs.emptyReferenceName);		
	if (checkPositionForAnchorAndA(box.element, version) < 0) {
		if (version == "1.1") {
			alert(module.localize("$$$/error1=A must be inside Fieldset, P, Strong, Em, B, I, or U."));	
		}
		else	{
			alert(module.localize("$$$/error2=A must be inside Fieldset, P, Pre, Strong, Em, B, I, or U."));	
		}
	}				
}

function parseAnchor(box, reason)
{
	if (!document) {
		// there should always be a document
		// since the custom box is drawn in a document
		return;
	}
	var version = getWMLVersion(document);
	
	if (checkPositionForAnchorAndA(box.element, version) < 0) {
		if (version == "1.1") {
			alert(module.localize("$$$/error3=Anchor must be inside Fieldset, P, Strong, Em, B, I, or U."));
		}		
		else {
			alert(module.localize("$$$/error4=Anchor must be inside Fieldset, P, Pre, Strong, Em, B, I, or U."));
		}	
	}
}

function parseCard(box,reason)
{
	box.onenterforward = (box.element.onenterforward) ? 
			box.createLink(box.element.onenterforward) :	
			box.createLink(settings.masterPrefs.emptyReferenceName);
	box.onenterbackward = (box.element.onenterbackward) ?
			 box.createLink (box.element.onenterbackward) :
			 box.createLink(settings.masterPrefs.emptyReferenceName);
	box.ontimer = (box.element.ontimer) ?
			box.createLink (box.element.ontimer) :
			box.createLink(settings.masterPrefs.emptyReferenceName);
	// fill in id attribute if undefined
	if (box.element.id == undefined) {
		//		box.element.setAttribute("id", "C" + Math.random().toString().substring(2));
	}
	//check to see if the box is attached to the correct
	//parent element only on drag and drop 
	if (reason == 2 || reason == 3){										
		var errVal = checkPositionForCard(box.element);
		if (errVal == c_parentWrong) {
			alert (module.localize("$$$/error5=Card must be inside the WML deck."));	
		}		
		else if (errVal == c_previousWrong) {
			alert(module.localize("$$$/error6=Card inserted in wrong position."));		
		}					
	}			
}

function parseDo(box, reason)
{
	if (!document) {
		// there should always be a document
		// since the custom box is drawn in a document
		return;
	}
	var version = getWMLVersion(document);
	
	if (reason == 2 || reason == 3) {				
		if (checkPositionForDo(box.element, version) < 0) {
			if (version == "1.1") {
				alert(module.localize("$$$/error7=Do must be inside Card, Fieldset, P, or Template."));	
			}		
			else	{
				alert(module.localize("$$$/error8=Do must be inside Card, Fieldset, P, Pre, or Template."));	
			}	
		}
	}	
}

function parseFieldset(box, reason)
{				
	if (reason == 2 || reason == 3){
		if (checkPositionForFieldset(box.element) < 0) {
			alert(module.localize("$$$/error9=Fieldset must be inside Fieldset or P."));		
		}		
	}
}

function parseGo(box, reason)
{
	box.ctlGoHref = (box.element.href) ?
		box.createLink (box.element.href) :
		box.createLink(settings.masterPrefs.emptyReferenceName);
	if (reason == 2 || reason == 3) {
		var errVal = checkPositionForGoPrevAndRefresh(box.element);
		if (errVal == c_parentWrong) {
			alert(module.localize("$$$/error10=Go must be inside Do, Onevent or Anchor."));		
		}
		else if (errVal < 0) {
			alert(module.localize("$$$/error11=Go inserted in wrong position."));	
		}			
	}
}

function parseImg(box, reason)
{		
	box.ctlImgsrc = (box.element.src) ?
		box.createLink (box.element.src) :
		box.createLink (settings.masterPrefs.emptyReferenceName);
	if (reason == 2 || reason == 3){
		if (checkPositionForImg(box.element) < 0) {
			alert(module.localize("$$$/error12=Image must be inside Fieldset, A, Anchor, P, Em, Strong, B, I, or U."));		
		}
	}
}

function parseInput(box, reason)
{	
	if (!document) {
		// there should always be a document
		// since the custom box is drawn in a document
		return;
	}
	var version = getWMLVersion(document);
	
	if (reason == 2 || reason == 3){
		var errVal = checkPositionForInputAndSelect(box.element, version);
		if (errVal == c_parentWrong) {
			if (version == "1.1") {
				alert(module.localize("$$$/error13=Input must be inside Fieldset, or P."));	
			}	
			else {
				alert(module.localize("$$$/error14=Input must be inside Fieldset, P, or Pre."));		
			}
		}
		else if (errVal < 0) { // should not happen
			alert(module.localize("$$$/error15=Input inserted in wrong position."));			
		}		
	}
}

function parseNoop(box, reason)
{
	if (reason == 2 || reason == 3) {
		var errVal = checkPositionForNoop(box.element);
		if (errVal == c_parentWrong) {
			alert(module.localize("$$$/error16=Noop must be inside Do or Onevent."));	
		}
		else if (errVal < 0) {
			alert(module.localize("$$$/error17=Noop inserted in wrong position."));	
		}
	}
}

function parseOnevent(box, reason)
{
	if (reason == 2 || reason == 3) {		
		var errVal = checkPositionForOnevent(box.element);
		if (errVal == c_parentWrong) {
			alert(module.localize("$$$/error18=Onevent must be inside Card, Template or Option."));	
		}
		else if (errVal < 0) {
			alert(module.localize("$$$/error19=Onevent inserted in wrong position."));
		}
	}
}

			
function parseOption(box, reason)
{				
	if (reason == 2 || reason == 3) {
		if (checkPositionForOption(box.element) < 0) {
			alert(module.localize("$$$/error20=Option must be inside Select or Optgroup."));	
		}
	}			
}

function parseOptiongroup(box, reason)
{				
	if (reason == 2 || reason == 3){
		if (checkPositionForOptgroup(box.element) < 0) {
			alert(module.localize("$$$/error21=Optgroup must be inside Select."));		
		}
	}
}
			
function parsePostfield(box, reason)
{
	if (reason == 2 || reason == 3) {
		if (checkPositionForPostfield(box.element) < 0) {
			alert(module.localize("$$$/error22=Postfield must be inside Go."));	
		}
	}
}

function parsePre(box, reason)
{
	if (!document) {
		// there should always be a document
		// since the custom box is drawn in a document
		return;
	}
	var version = getWMLVersion(document);

	if (reason == 2 || reason == 3) {
		var errVal = checkPositionForPre(box.element, version);
		if (errVal == c_versionWrong) {
			alert(module.localize("$$$/error23=Pre not allowed in WML 1.1 document."));
		}
		else if (errVal == c_parentWrong) {
			alert(module.localize("$$$/error24=Pre must be inside Card."));	
		}	
		else if (errVal < 0) {
			alert(module.localize("$$$/error25=Pre inserted in wrong position."));	
		}		
	}
}

function parsePrev(box, reason)
{
	if (reason == 2 || reason == 3) {
		var errVal = checkPositionForGoPrevAndRefresh(box.element);
		if (errVal == c_parentWrong) {
			alert(module.localize("$$$/error26=Prev must be inside Do, Onevent or Anchor."));		
		}
		else if (errVal < 0) {
			alert(module.localize("$$$/error27=Prev inserted in wrong position."));		
		}									
	}
}

function parseRefresh(box, reason)
{
	if (reason == 2 || reason == 3) {	
		var errVal = checkPositionForGoPrevAndRefresh(box.element);
		if (errVal == c_parentWrong) {
			alert(module.localize("$$$/error28=Refresh must be inside Do, Onevent or Anchor."));		
		}
		else if (errVal < 0) {
			alert(module.localize("$$$/error29=Refresh inserted in wrong position."));	
		}												
	}
}

function parseSelect(box, reason)
{
	if (!document) {
		// there should always be a document
		// since the custom box is drawn in a document
		return;
	}
	var version = getWMLVersion(document);
	
	 if (reason == 2 || reason == 3) {
	 	if (checkPositionForInputAndSelect(box.element, version) < 0) {
	 		if (version == "1.1") {
	 			alert(module.localize("$$$/error30=Select must be inside Fieldset, or P."));	
	 		}
	 		else {
	 			alert(module.localize("$$$/error31=Select must be inside Fieldset, P, or Pre."));	
	 		}
	 	}
	 }	
}
			
function parseSetvar(box, reason)
{
	if (reason == 2 || reason == 3) {
		if (checkPositionForSetvar(box.element) < 0) {
			alert(module.localize("$$$/error32=Setvar must be inside Go, Prev, or Refresh."));	
		}	
	}
}

function parseTemplate(box, reason){			
	box.ctlTemplateOnEnterForward = (box.element.onenterforward) ?
			box.createLink (box.element.onenterforward) :
			box.createLink (settings.masterPrefs.emptyReferenceName);
	box.ctlTemplateOnEnterBackward = (box.element.onenterbackward) ?
			box.createLink (box.element.onenterbackward) :
			box.createLink (settings.masterPrefs.emptyReferenceName);
	box.ctlTemplateOnTimer = (box.element.ontimer) ?
			box.createLink (box.element.ontimer) :
			box.createLink (settings.masterPrefs.emptyReferenceName);
				
	if (reason == 2 || reason == 3) {											
		var i = checkPositionForTemplate(box.element);
		if (i == c_parentWrong) {
			alert (module.localize("$$$/error33=Template must be inside the WML deck."));	
		}
		else if (i == c_previousWrong) {
			alert(module.localize("$$$/error34=Template must be first in the WML deck."));
		}
	}										
}

function parseTimer(box, reason)
{				
	if (reason == 2 || reason == 3){
		var errVal = checkPositionForTimer(box.element);
		if (errVal == c_parentWrong) {
			alert(module.localize("$$$/error35=Timer must be inside Card."));	
		}
		else if (errVal < 0) {
			alert(module.localize("$$$/error36=Timer inserted in wrong position."));
		}
	}
}