var ie = document.all;
var grama = {
	menu : {
		over : function(i) {
			if (i.tagName.toLowerCase() == "div"
					|| i.tagName.toLowerCase() == "a") {
				if (i.className != "") {
					i.className = i.className.split("_over").join("") + "_over";
				}
				grama.menu.over(i.parentNode);
			}
		},
		out : function(i) {
			if (i.tagName.toLowerCase() == "div"
					|| i.tagName.toLowerCase() == "a") {
				if (i.className != "") {
					i.className = i.className.split("_over").join("");
				}
				grama.menu.out(i.parentNode);
			}
		},
		load : function() {
			if ($("menu") == null) {
				return;
			}
			menuItems = $("menu").getElementsByTagName('div');
			for (i = 0; i < menuItems.length; i++) {
				if (menuItems[i].className != "menu_text"
						&& menuItems[i].className != "submenu_text") {
					continue;
				}
				menuItems[i].onmouseover = function(o) {
					source = ie ? event.srcElement : o.target; 
					grama.menu.over(source);
				};
				menuItems[i].onmouseout = function(o) {
					source = ie ? event.srcElement : o.target;
					grama.menu.out(source);
				};
				menuItems[i].onclick = function(o) {
					source = ie ? event.srcElement : o.target;
					if (source.getElementsByTagName('a') != null && source.getElementsByTagName('a')[0] != null) {
						window.location.href = source.getElementsByTagName('a')[0].href;
					}
				}
			}
			menuItems = $("menu").getElementsByTagName('a');
			for (i = 0; i < menuItems.length; i++) {
				menuItems[i].onmouseover = function(o) {
					source = ie ? event.srcElement : o.target;
					grama.menu.over(source);
				};
				menuItems[i].onmouseout = function(o) {
					source = ie ? event.srcElement : o.target;
					grama.menu.out(source);
				};
			}
		}
	},
	button : {
		over : function(o) {
			if (o.tagName.toLowerCase() == "div"
					|| o.tagName.toLowerCase() == "a") {
				if (o.className != "") {
					var classNames = o.className.split(" ");
					var finalClassNames = "";
					for (var j = 0; j < classNames.length; j++) {
						finalClassNames += (j > 0 ? " " : "") + classNames[j].split("_over").join("") + "_over";
					}
					o.className = o.finalClassNames;
				}
				grama.menu.over(o.parentNode);
			}
		},
		out : function(o) {
			if (o.tagName.toLowerCase() == "div"
				|| o.tagName.toLowerCase() == "a") {
				if (o.className != "") {
					var classNames = o.className.split(" ");
					var finalClassNames = "";
					for (var j = 0; j < classNames.length; j++) {
						finalClassNames += (j > 0 ? " " : "") + classNames[j].split("_over").join("");
					}
					o.className = o.finalClassNames;
				}
				grama.menu.over(o.parentNode);
			}
		},
		load : function() {
			buttonItems = document.getElementsByTagName('div');
			for (i = 0; i < buttonItems.length; i++) {
				if (buttonItems[i].className.indexOf("button_text") < 0) {
					continue;
				}
				buttonItems[i].onmouseover = function(o) {
					source = ie ? event.srcElement : o.target;
					grama.menu.over(source);
				};
				buttonItems[i].onmouseout = function(o) {
					source = ie ? event.srcElement : o.target;
					grama.menu.out(source);
				};
				buttonLinkItems = buttonItems[i].getElementsByTagName('a');
				for (k = 0; k < buttonLinkItems.length; k++) {
					buttonLinkItems[k].onmouseover = function(o) {
						source = ie ? event.srcElement : o.target;
						grama.menu.over(source);
					};
					buttonLinkItems[k].onmouseout = function(o) {
						source = ie ? event.srcElement : o.target;
						grama.menu.out(source);
					};
				}
			}
		}
	},
	question : {
		__dragTop: 0,
		__dragRelations: new Array(),
		__dragBasesTargets: new Array(),
		__dragWidth: 0,
		__forceValidate: false,
		addDragAndDrop : function(i, base, target) {
			grama.question.__dragBasesTargets.push({ base: base, target: target });
			new Draggable(base, {
				revert : 'failure',
				onStart: function() {
					$(base).setAttribute("dropped", "");
				},
				onEnd: function() {
					if ($(base).getAttribute("dropped") == "ok") {
						return;
					}
					for(var i= 0;i < grama.question.__dragRelations.length;i++)
					{
						if (grama.question.__dragRelations[i].indexOf(base +"|") == 0) {
							grama.question.__dragRelations[i] = "";
						}
					}
					grama.question.forceValidate();
				}
			});
			Droppables.add(target, {
				accept : 'draggable',
				hoverclass : 'hover',
				onDrop : function(element) {
					element.setAttribute("dropped", "ok");
					for(var i= 0;i < grama.question.__dragRelations.length;i++)
					{
						if (grama.question.__dragRelations[i].indexOf(element.id +"|") == 0) {
							grama.question.__dragRelations[i] = "";
						}
					}
					element.style.top = $(target).offsetTop + 'px';
					element.style.left = $(target).offsetLeft + 'px';
					grama.question.__dragRelations.push(element.id +"|"+ target);
					$(target).highlight();
					grama.question.forceValidate();
				}
			});
			if (grama.question.__dragTop == 0) {
				grama.question.__dragTop = document.getElementsByClassName('dropPlace')[i].offsetTop;
			}
			//$(base).innerHTML.length * 10
			if ($(base).offsetWidth + 6 > grama.question.__dragWidth) {
				grama.question.__dragWidth = $(base).offsetWidth + 6;
			}
			for(var j= 0;j < grama.question.__dragBasesTargets.length;j++)
			{
				$(grama.question.__dragBasesTargets[j].target).style.width = (grama.question.__dragWidth + 6) + "px";
				$(grama.question.__dragBasesTargets[j].base).style.width = grama.question.__dragWidth + "px";
			}
			$(base).style.top = grama.question.__dragTop + 'px';
			$(base).style.left = ($('dropArea').offsetLeft + $('dropArea').offsetWidth + 10) + 'px';
			grama.question.__dragTop += $(base).offsetHeight + 10;
		},
		alignDragAndDrop: function() {
			for(var i= 0; i < grama.question.__dragRelations.length; i++)
			{
				if (grama.question.__dragRelations[i].indexOf("|") > 0) {
					ids = grama.question.__dragRelations[i].split("|");
					$(ids[0]).style.top = $(ids[1]).offsetTop + 'px';
					$(ids[0]).style.left = $(ids[1]).offsetLeft + 'px';
				}
			}
		},
		forceValidate: function () {
			if (grama.question.__forceValidate) {
				grama.question.validate();
			}
		},
		validate: function () {
			grama.question.__forceValidate = true;
			for(var i= 0;i < questions.length;i++)
			{
				if($(questions[i].id) != null && $(questions[i].id).nodeName.toLowerCase() == "input") {
					grama.question.showResult(questions[i].id, $(questions[i].id).value, questions[i].answers, questions[i].correctAnswers);										
				} else if($(questions[i].id).nodeName.toLowerCase() == "div" || $(questions[i].id).nodeName.toLowerCase() == "span") {					
					grama.question.showResult(questions[i].id, grama.question.getAnswer(questions[i].id), questions[i].answers, questions[i].correctAnswers);										
				}
				grama.question.alignDragAndDrop();
			}
			//window.setTimeout("grama.question.alignDragAndDrop();", 100);
		},
		showResult: function (questionId, userAnswer, answers, answersShowCorrect) {			
			for(var i = 0;i < answers.length;i++) {
				if(trim(userAnswer) == trim(answers[i]))
				{
					document.getElementById(questionId + "_answer").className = 'answerCorrect';
					document.getElementById(questionId + "_answer").innerHTML = '<img src="resources/images/question_answer_correct.jpg"/>' + (answersShowCorrect.length > 1 ?  answersShowCorrect.join(', ') : "");
					return;
				}
			}
			document.getElementById(questionId + "_answer").className = 'answerWrong';
			document.getElementById(questionId + "_answer").innerHTML = answersShowCorrect.join(', ');
		},
		getAnswer: function (questionId) {
			var i = 1;
			var qElement = $(questionId);
			var aElement;
			while($("answer" + i)) {
				aElement = $("answer" + i);				
				if(aElement.style.top == qElement.offsetTop +"px"  && aElement.style.left == qElement.offsetLeft + "px") {
					return aElement.innerHTML;
				}
				i++;
			}
			return "";
		},
		__next: "",
		__valid: false,
		setNext: function (next) {
			grama.question.__next = next;
		},
		gotoNext: function () {
			if (!grama.question.__valid) {
				grama.question.validate();
				window.setTimeout('grama.question.__valid = true;', 500);
			} else {
				window.location.href = grama.question.__next;
			}
		},
		clickAnswer: function(span, hiddenId) {
			var hidden = document.getElementById(hiddenId);
			if(hidden.value == "") {
				hidden.value = span.innerHTML;
				span.className = "clickableSel";
			} else {
				hidden.value = "";
				span.className = "clickable";				
			}
		},
		__clickDefaultColor: '#abc837',
		__clickColors : new Array(
				"#bbbb55",
				"#44bbcc",
				"#229933",
				"#778866",
				"#88dddd",
				"#ffdd00",
				"#cc3300",
				"#447799",
				"#777744"
		),
		__clickCurrentStep: 0, // 0 - nenhum selecionado, 1 - seleccionou 1 element, 2 - selecionou o 2 elemento
		__clickLastItemSelectedId: '',
        __clickLastSelectColor: '',
        __clickSelectedRelation: new Array(),
        clickSelectItem: function(elem) {
			if(grama.question.__clickCurrentStep == 0) {
				if(!grama.question.clickRemoveRelation(elem.id)) {					
					grama.question.__clickLastSelectColor = grama.question.clickGetAvailableColor();
					grama.question.__clickLastItemSelectedId = elem.id;
					grama.question.__clickCurrentStep = 1;
					grama.question.clickHighlightElem(elem, grama.question.__clickLastSelectColor);//elem.style.background = _lastSelectColor;												
				}
			} else if(grama.question.__clickCurrentStep == 1) {
				// O mesmo					
				if(grama.question.__clickLastItemSelectedId == elem.id) {   
					grama.question.clickResetElem(grama.question.__clickLastItemSelectedId);
					grama.question.__clickCurrentStep = 0;
					grama.question.clickAddAvailableColor(grama.question.__clickLastSelectColor);
					grama.question.__clickLastItemSelectedId = '';
					grama.question.__clickLastSelectColor = '';
				// Do mesmo Tipo
				} else if(grama.question.__clickLastItemSelectedId.charAt(0) == elem.id.charAt(0)) { 
					grama.question.clickResetElem(grama.question.__clickLastItemSelectedId);
					if(!grama.question.clickRemoveRelation(elem.id)) {
						grama.question.clickHighlightElem(elem, grama.question.__clickLastSelectColor);//elem.style.background = _lastSelectColor;  
					    grama.question.__clickLastItemSelectedId = elem.id;
					}
				} else {
					grama.question.clickRemoveRelation(elem.id);
					grama.question.clickAddSelectedRelation(grama.question.__clickLastItemSelectedId, elem.id);
					grama.question.clickHighlightElem(elem, grama.question.__clickLastSelectColor); //elem.style.background = _lastSelectColor;
					grama.question.__clickLastItemSelectedId = elem.id;
					grama.question.__clickCurrentStep = 2;
				}
			} else {					
				if(grama.question.__clickLastItemSelectedId == elem.id) {
					grama.question.clickResetElem(grama.question.__clickLastItemSelectedId);												
					//Remover rela��o
					grama.question.__clickLastItemSelectedId = grama.question.clickRemoveLastRelation(grama.question.__clickLastItemSelectedId);
					grama.question.__clickCurrentStep = 1;
				} else if(!grama.question.clickRemoveRelation(elem.id)){
					grama.question.__clickLastSelectColor = grama.question.clickGetAvailableColor();
					grama.question.__clickLastItemSelectedId = elem.id;
					grama.question.__clickCurrentStep = 1;
                
					grama.question.clickHighlightElem(elem, grama.question.__clickLastSelectColor);//elem.style.background = _lastSelectColor;
				} else {						
					grama.question.__clickCurrentStep = 0;
					grama.question.__clickLastItemSelectedId = '';
					grama.question.__clickLastSelectColor = '';
				}
			}
		},
		clickResetElem: function (elemId) {
            var startColor = $(elemId).getAttribute('color');   
            if(!startColor || startColor == '') startColor = grama.question.__clickDefaultColor;
            new Effect.Highlight(elemId, { startcolor: startColor, endcolor: grama.question.__clickDefaultColor, restorecolor : grama.question.__clickDefaultColor });                
            $(elemId).setAttribute('color', grama.question.__clickDefaultColor);                
        },
        clickHighlightElem: function (elem, color) {
            var startColor = elem.getAttribute('color');
            if(!startColor || startColor == '') startColor = grama.question.__clickDefaultColor;
            new Effect.Highlight(elem, { startcolor: startColor, endcolor: color, restorecolor : color });
            elem.setAttribute('color', color);
        },
        clickGetAvailableColor: function() {
        	return grama.question.__clickColors.pop();
        },
        clickAddAvailableColor: function (color) {
        	grama.question.__clickColors.push(color);
        },
        clickAddSelectedRelation: function (elem1Id, elem2Id) {
            var questionId;
            var answerId;
            
            if(elem1Id.charAt(0) == 'q') {
                questionId = elem1Id;
            } else {
                answerId = elem1Id;
            }
            
            if(elem2Id.charAt(0) == 'q') {
                questionId = elem2Id;
            } else {
                answerId = elem2Id;
            }
            
            grama.question.__clickSelectedRelation.push({'question': questionId, 'answer' : answerId})
            $(questionId.substring(1)).value = $(answerId).innerHTML;
        },
        clickRemoveLastRelation: function(elemId) {
            var relation = grama.question.__clickSelectedRelation.pop();                
            if(elemId == relation.question) {
            	$(relation.question.substring(1)).value = '';
            	return relation.answer;
            } else {
            	$(relation.question.substring(1)).value = '';
                return relation.question;
            }            
        },
        clickRemoveRelation: function(elemId) {
			var i = 0;				
			for(i = 0; i < grama.question.__clickSelectedRelation.length;i++) {
				if(grama.question.__clickSelectedRelation[i].question == elemId || grama.question.__clickSelectedRelation[i].answer == elemId) {						
					grama.question.clickAddAvailableColor($(grama.question.__clickSelectedRelation[i].question).getAttribute('color'));
					grama.question.clickResetElem(grama.question.__clickSelectedRelation[i].question);
					grama.question.clickResetElem(grama.question.__clickSelectedRelation[i].answer);
					$(grama.question.__clickSelectedRelation[i].question.substring(1)).value = '';
					grama.question.__clickSelectedRelation.splice(i, 1);
					return true;
				}
			}
			
			return false;
		}
	},
	sound: {
		_url: "",
		_isToPlay: false,
		setUrl: function(v) {
			grama.sound._url = v;
		},
		getUrl: function() {
			return grama.sound._url;
		},
		setIsToPlay: function(v) {
			grama.sound._isToPlay = v;
		},
		isToPlay: function () {
			return grama.sound._isToPlay;
		},
		play: function () {
			//new Ajax.Request("soundplayer.cjp.htm?action=play", {method: 'get'});
		},
		stop: function () {
			//new Ajax.Request("soundplayer.cjp.htm?action=stop", {method: 'get'});
		}
	},
	faq: {
		showing: new Array(),
		show: function(id) {
			isVisible = false;
			for (i = 0; i < grama.faq.showing.length; i++) {
				if (grama.faq.showing[i] == id) {
					isVisible = true;
					grama.faq.showing[i] = null;
					break;
				}
			}
			answerId = 'faqAnswer'+ id;
			if (isVisible) {
				$(answerId).hide();
			} else {
				grama.faq.showing.push(id);			
				$(answerId).appear({ duration: 3.0 });
			}
		}
	},
	blog: {
		showing: new Array(),
		show: function(id) {
			isVisible = false;
			for (i = 0; i < grama.blog.showing.length; i++) {
				if (grama.blog.showing[i] == id) {
					isVisible = true;
					grama.blog.showing[i] = null;
					break;
				}
			}
			popupId = 'blogCommentPopup'+ id;
			if (isVisible) {
				$(popupId).hide();
			} else {
				for (i = 0; i < grama.blog.showing.length; i++) {
					if (grama.blog.showing[i] != null) {
						$(grama.blog.showing[i]).hide();
						grama.blog.showing[i] = null;
					}
				}
				grama.blog.showing.push(id);			
				$(popupId).appear({ duration: 3.0 });
				$('blogComment'+ id).src = 'blogarticlecomments.cjp.htm?id='+ id;
			}
		},
		titleOver : function(i) {
			$("blogCommentPopupTitleBTClose" + i).src = $("blogCommentPopupTitleBTClose" + i).src.split(".png").join("_over.png");
		},
		titleOut : function(i) {
			$("blogCommentPopupTitleBTClose" + i).src = $("blogCommentPopupTitleBTClose" + i).src.split("_over.png").join(".png");
		}
	},
	newsletter: {
		submit: function () {
		    err = false;
		    if (! /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($F("newsletter_email"))) {
		        $('newsletter_email_err').style.visibility = 'visible';
		        err = true;
		    } else {
		        $('newsletter_email_err').style.visibility = 'hidden';
		    }
		    if ($F("newsletter_name").trim() == "") {
		        $('newsletter_name_err').style.visibility = 'visible';
		        err = true;
		    } else {
		        $('newsletter_name_err').style.visibility = 'hidden';
		    }
		    if ($F("newsletter_langs") == "") {
		        $('newsletter_langs_err').style.visibility = 'visible';
		        err = true;
		    } else {
		        $('newsletter_langs_err').style.visibility = 'hidden';
		    }
		    if (err) {
		        return;
		    }
		    if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($F("newsletter_email"))) {
		        new Ajax.Request('/gramatica/gramatica/Newsletter.proteu', {method:'post', postBody:'email='+ $F("newsletter_email") + '&name='+ $F("newsletter_name") + '&langs='+ $F("newsletter_langs").substring(1, $F("newsletter_langs").length) + '&add=true', requestHeaders:['Accept', 'application/json'], onSuccess: function(e) {
		            $('newsletter_form').style.visibility = 'hidden';
		            $('newsletter_message').style.visibility = 'visible';
		        }});
		    }

		}
	}
}

window.onresize = function() {

};
window.onload = function() {
	grama.menu.load();
	grama.button.load();
	if ($('page') != null && $('menu') != null) {
		if ($('page').offsetHeight < $('menu').offsetHeight + 150) {
			$('page').style.height = ($('menu').offsetHeight + 150) + 'px';
		}
	}
};

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2008 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function ControlVersion()
{
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}
	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}
function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }  
  document.write(str);
}
function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    
    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function validContactForm() {
    _return = true;
    if (document.forms["frmContact"].elements["contactName"].value == "") {
        document.getElementById("contactNameAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("contactNameAlert").style.visibility = "hidden";
    }
    if (document.forms["frmContact"].elements["contactEmail"].value == "") {
        document.getElementById("contactEmailAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("contactEmailAlert").style.visibility = "hidden";
    }
    if (document.forms["frmContact"].elements["contactComment"].value == "") {
        document.getElementById("contactCommentAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("contactCommentAlert").style.visibility = "hidden";
    }
    if (document.forms["frmContact"].elements["contactEmail"].value != "" &&
        !emailCheck(document.forms["frmContact"].elements["contactEmail"].value)) {
        document.getElementById("contactEmailAlert").style.visibility = "visible";
        _return = false;
    }
    return _return;
}

function validCommentForm() {
    _return = true;
    if (document.forms["frmComment"].elements["commentName"].value == "") {
        document.getElementById("commentNameAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("commentNameAlert").style.visibility = "hidden";
    }
    if (document.forms["frmComment"].elements["commentEmail"].value == "") {
        document.getElementById("commentEmailAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("commentEmailAlert").style.visibility = "hidden";
    }
    if (document.forms["frmComment"].elements["commentTitle"].value == "") {
        document.getElementById("commentTitleAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("commentTitleAlert").style.visibility = "hidden";
    }
    if (document.forms["frmComment"].elements["commentComment"].value == "") {
        document.getElementById("commentCommentAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("commentCommentAlert").style.visibility = "hidden";
    }
    if (document.forms["frmComment"].elements["commentEmail"].value != "" &&
        !emailCheck(document.forms["frmComment"].elements["commentEmail"].value)) {
        document.getElementById("commentEmailAlert").style.visibility = "visible";
        _return = false;
    }
    return _return;
}

<!-- Begin
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->
