// minmax.js: make IE5+/Win support CSS min/max-width/height
// version 1.0, 08-Aug-2003
// written by Andrew Clover <and@doxdesk.com>, use freely

/*@cc_on
@if (@_win32 && @_jscript_version>4 && @_jscript_version<5.8)

var minmax_elements;

minmax_props= new Array(
  new Array('min-width', 'minWidth'),
  new Array('max-width', 'maxWidth'),
  new Array('min-height','minHeight'),
  new Array('max-height','maxHeight')
);

// Binding. Called on all new elements. If <body>, initialise; check all
// elements for minmax properties

function minmax_bind(el) {
  var i, em, ms;
  var st= el.style, cs= el.currentStyle;

  if (minmax_elements==window.undefined) {
    // initialise when body element has turned up, but only on IE
    if (!document.body || !document.body.currentStyle) return;
    minmax_elements= new Array();
    window.attachEvent('onresize', minmax_delayout);
    // make font size listener
    em= document.createElement('div');
    em.setAttribute('id', 'minmax_em');
    em.style.position= 'absolute'; em.style.visibility= 'hidden';
    em.style.fontSize= 'xx-large'; em.style.height= '5em';
    em.style.top='-5em'; em.style.left= '0';
    if (em.style.setExpression) {
      em.style.setExpression('width', 'minmax_checkFont()');
      document.body.insertBefore(em, document.body.firstChild);
    }
  }

  // transform hyphenated properties the browser has not caught to camelCase
  for (i= minmax_props.length; i-->0;)
    if (cs[minmax_props[i][0]])
      st[minmax_props[i][1]]= cs[minmax_props[i][0]];
  // add element with properties to list, store optimal size values
  for (i= minmax_props.length; i-->0;) {
    ms= cs[minmax_props[i][1]];
    if (ms && ms!='auto' && ms!='none' && ms!='0' && ms!='') {
      st.minmaxWidth= cs.width; st.minmaxHeight= cs.height;
      minmax_elements[minmax_elements.length]= el;
      // will need a layout later
      minmax_delayout();
      break;
  } }
}

// check for font size changes

var minmax_fontsize= 0;
function minmax_checkFont() {
  var fs= document.getElementById('minmax_em').offsetHeight;
  if (minmax_fontsize!=fs && minmax_fontsize!=0)
    minmax_delayout();
  minmax_fontsize= fs;
  return '5em';
}

// Layout. Called after window and font size-change. Go through elements we
// picked out earlier and set their size to the minimum, maximum and optimum,
// choosing whichever is appropriate

// Request re-layout at next available moment
var minmax_delaying= false;
function minmax_delayout() {
  if (minmax_delaying) return;
  minmax_delaying= true;
  window.setTimeout(minmax_layout, 0);
}

function minmax_stopdelaying() {
  minmax_delaying= false;
}

function minmax_layout() {
  window.setTimeout(minmax_stopdelaying, 100);
  var i, el, st, cs, optimal, inrange;
  for (i= minmax_elements.length; i-->0;) {
    el= minmax_elements[i]; st= el.style; cs= el.currentStyle;

    // horizontal size bounding
    st.width= st.minmaxWidth; optimal= el.offsetWidth;
    inrange= true;
    if (inrange && cs.minWidth && cs.minWidth!='0' && cs.minWidth!='auto' && cs.minWidth!='') {
      st.width= cs.minWidth;
      inrange= (el.offsetWidth<optimal);
    }
    if (inrange && cs.maxWidth && cs.maxWidth!='none' && cs.maxWidth!='auto' && cs.maxWidth!='') {
      st.width= cs.maxWidth;
      inrange= (el.offsetWidth>optimal);
    }
    if (inrange) st.width= st.minmaxWidth;

    // vertical size bounding
    st.height= st.minmaxHeight; optimal= el.offsetHeight;
    inrange= true;
    if (inrange && cs.minHeight && cs.minHeight!='0' && cs.minHeight!='auto' && cs.minHeight!='') {
      st.height= cs.minHeight;
      inrange= (el.offsetHeight<optimal);
    }
    if (inrange && cs.maxHeight && cs.maxHeight!='none' && cs.maxHeight!='auto' && cs.maxHeight!='') {
      st.height= cs.maxHeight;
      inrange= (el.offsetHeight>optimal);
    }
    if (inrange) st.height= st.minmaxHeight;
  }
}

// Scanning. Check document every so often until it has finished loading. Do
// nothing until <body> arrives, then call main init. Pass any new elements
// found on each scan to be bound   

var minmax_SCANDELAY= 500;

function minmax_scan() {
  var el;
  for (var i= 0; i<document.all.length; i++) {
    el= document.all[i];
    if (!el.minmax_bound) {
      el.minmax_bound= true;
      minmax_bind(el);
  } }
}

var minmax_scanner;
function minmax_stop() {
  window.clearInterval(minmax_scanner);
  minmax_scan();
}

minmax_scan();
minmax_scanner= window.setInterval(minmax_scan, minmax_SCANDELAY);
window.attachEvent('onload', minmax_stop);

@end @*/

/*

FREESTYLE MENUS v1.0 RC (c) 2001-2009 Angus Turnbull, http://www.twinhelix.com
Altering this notice or redistributing this file is prohibited.

*/

var isDOM=document.getElementById?1:0,isIE=document.all?1:0,isNS4=navigator.appName=='Netscape'&&!isDOM?1:0,isOp=self.opera?1:0,isDyn=isDOM||isIE||isNS4;function getRef(i,p){p=!p?document:p.navigator?p.document:p;return isIE?p.all[i]:isDOM?(p.getElementById?p:p.ownerDocument).getElementById(i):isNS4?p.layers[i]:null};function getSty(i,p){var r=getRef(i,p);return r?isNS4?r:r.style:null};if(!self.LayerObj)var LayerObj=new Function('i','p','this.ref=getRef(i,p);this.sty=getSty(i,p);return this');function getLyr(i,p){return new LayerObj(i,p)};function LyrFn(n,f){LayerObj.prototype[n]=new Function('var a=arguments,p=a[0],px=isNS4||isOp?0:"px";with(this){'+f+'}')};LyrFn('x','if(!isNaN(p))sty.left=p+px;else return parseInt(sty.left)');LyrFn('y','if(!isNaN(p))sty.top=p+px;else return parseInt(sty.top)');if(typeof addEvent!='function'){var addEvent=function(o,t,f,l){var d='addEventListener',n='on'+t;if(o[d]&&!l)return o[d](t,f,false);if(!o._evts)o._evts={};if(!o._evts[t]){o._evts[t]={};if(o[n])addEvent(o,t,o[n],l);o[n]=new Function('e','var r=true,o=this,a=o._evts["'+t+'"],i;for(i in a){o._f=a[i];if(o._f._i)r=o._f(e||window.event)!=false&&r}o._f=null;return r')}if(!f._i)f._i=addEvent._i++;o._evts[t][f._i]=f;if(t!='unload')addEvent(window,'unload',function(){removeEvent(o,t,f,l)})};addEvent._i=1;var removeEvent=function(o,t,f,l){var d='removeEventListener';if(o[d]&&!l)return o[d](t,f,false);if(o._evts&&o._evts[t]&&f._i)delete o._evts[t][f._i]}}var addReadyEvent=function(f){var a=addReadyEvent,n=null;addEvent(a,'ready',f);if(!a.r){a.r=function(){clearInterval(t);if(a.r)a.onready();a.r=null};addEvent(document,'DOMContentLoaded',a.r);addEvent(window,'load',a.r);var t=setInterval(function(){if(/complete|loaded/.test(document.readyState)){if(!n)a.r();else try{n.doScroll('left');n=null;a.r()}catch(e){}}},50)}};function FSMenu(myName,nested,cssProp,cssVis,cssHid){this.myName=myName;this.nested=nested;this.cssProp=cssProp;this.cssVis=cssVis;this.cssHid=cssHid;this.cssLitClass='highlighted';this.menus=nested?{}:{root:new FSMenuNode('root',true,this)};this.menuToShow=[];this.mtsTimer=null;this.showDelay=0;this.switchDelay=125;this.hideDelay=500;this.showOnClick=0;this.hideOnClick=true;this.animInSpeed=0.2;this.animOutSpeed=0.2;this.animations=[]};FSMenu.prototype.show=function(mN){with(this){menuToShow.length=arguments.length;for(var i=0;i<arguments.length;i++)menuToShow[i]=arguments[i];clearTimeout(mtsTimer);if(!nested)mtsTimer=setTimeout(myName+'.menus.root.over()',10)}};FSMenu.prototype.hide=function(mN){with(this){clearTimeout(mtsTimer);if(menus[mN])menus[mN].out()}};FSMenu.prototype.hideAll=function(){with(this){for(var m in menus)if(menus[m].visible&&!menus[m].isRoot)menus[m].hide(true)}};function FSMenuNode(id,isRoot,obj){this.id=id;this.isRoot=isRoot;this.obj=obj;this.lyr=this.child=this.par=this.timer=this.visible=null;this.args=[];var node=this;this.over=function(evt){with(node)with(obj){if(isNS4&&evt&&lyr.ref)lyr.ref.routeEvent(evt);clearTimeout(timer);clearTimeout(mtsTimer);if(!isRoot&&!visible)node.show();if(menuToShow.length){var a=menuToShow,m=a[0];if(!menus[m]||!menus[m].lyr.ref)menus[m]=new FSMenuNode(m,false,obj);var c=menus[m];if(c==node){menuToShow.length=0;return}clearTimeout(c.timer);if(c!=child&&c.lyr.ref){c.args.length=a.length;for(var i=0;i<a.length;i++)c.args[i]=a[i];var delay=child?switchDelay:showDelay;c.timer=setTimeout('with('+myName+'){menus["'+c.id+'"].par=menus["'+node.id+'"];menus["'+c.id+'"].show()}',delay?delay:1)}menuToShow.length=0}if(!nested&&par)par.over()}};this.out=function(evt){with(node)with(obj){if(isNS4&&evt&&lyr&&lyr.ref)lyr.ref.routeEvent(evt);clearTimeout(timer);if(!isRoot&&hideDelay>=0){timer=setTimeout(myName+'.menus["'+id+'"].hide()',hideDelay);if(!nested&&par)par.out()}}};if(id!='root')with(this)with(lyr=getLyr(id))if(ref){if(isNS4)ref.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT);addEvent(ref,'mouseover',this.over);addEvent(ref,'mouseout',this.out);if(obj.nested){addEvent(ref,'focus',this.over,1);addEvent(ref,'click',this.over);addEvent(ref,'blur',this.out,1)}}};FSMenuNode.prototype.show=function(forced){with(this)with(obj){if(!lyr||!lyr.ref)return;if(par){if(par.child&&par.child!=this)par.child.hide();par.child=this}var offR=args[1],offX=args[2],offY=args[3],lX=0,lY=0,doX=''+offX!='undefined',doY=''+offY!='undefined';if(self.page&&offR&&(doX||doY)){with(page.elmPos(offR,par.lyr?par.lyr.ref:0))lX=x,lY=y;if(doX)lyr.x(lX+eval(offX));if(doY)lyr.y(lY+eval(offY))}if(offR)lightParent(offR,1);visible=1;if(obj.onshow)obj.onshow(id);lyr.ref.parentNode.style.zIndex='2';setVis(1,forced)}};FSMenuNode.prototype.hide=function(forced){with(this)with(obj){if(!lyr||!lyr.ref||!visible)return;if(isNS4&&self.isMouseIn&&isMouseIn(lyr.ref))return show();if(args[1])lightParent(args[1],0);if(child)child.hide();if(par&&par.child==this)par.child=null;if(lyr){visible=0;if(obj.onhide)obj.onhide(id);lyr.ref.parentNode.style.zIndex='1';setVis(0,forced)}}};FSMenuNode.prototype.lightParent=function(elm,lit){with(this)with(obj){if(!cssLitClass||isNS4)return;if(lit)elm.className+=(elm.className?' ':'')+cssLitClass;else elm.className=elm.className.replace(new RegExp('(\\s*'+cssLitClass+')+$'),'')}};FSMenuNode.prototype.setVis=function(sh,forced){with(this)with(obj){if(lyr.forced&&!forced)return;lyr.forced=forced;lyr.timer=lyr.timer||0;lyr.counter=lyr.counter||0;with(lyr){clearTimeout(timer);var speed=sh?animInSpeed:animOutSpeed;if(!counter)sty[cssProp]=sh?cssVis:cssHid;if(isDOM&&(speed<1))for(var a=0;a<animations.length;a++)animations[a](ref,counter,sh);if(isDOM&&(sh?counter<1:counter>0))timer=setTimeout(myName+'.menus["'+id+'"].setVis('+sh+','+(forced||0)+')',50);else lyr.forced=false;counter=counter+speed*(sh?1:-1);if(counter<0.001)counter=0;if(counter>0.999)counter=1}}};FSMenu.animSwipeDown=function(ref,counter,show){var elm=ref.firstChild.style?ref.firstChild:ref.firstChild.nextSibling,isOldIE=/MSIE\s(5|6|7)\./.test(navigator.userAgent);if(!elm)return;if(show&&(counter==0)){if(!elm._fsm_marg)elm._fsm_marg={'top':elm.style.marginTop};ref._fsm_height=ref.offsetHeight}if(counter==1||(counter<0.01&&!show)){ref.style.overflow='visible';elm.style.marginTop=elm._fsm_marg.top;if(isOldIE)ref.style.height=''}else{var cP=Math.pow(Math.sin(Math.PI*counter/2),0.75);ref.style.overflow='hidden';if(isOldIE)ref.style.height=(ref._fsm_height*cP)+'px';else elm.style.marginTop=(0-ref._fsm_height*(1-cP))+'px'}};FSMenu.animFade=function(ref,counter,show){if(typeof ref.filters=='unknown')return;var f=ref.filters,done=(show?counter==1:counter<0.01),a=/MSIE\s(4|5)/.test(navigator.userAgent)?'alpha':'DXImageTransform.Microsoft.Alpha';if(f){if(!done&&ref.style.filter.indexOf(a)==-1)ref.style.filter+=' '+(a=='alpha'?a:'progid:'+a)+'(opacity='+(counter*100)+')';else if(f.length&&f[a]){if(done)f[a].enabled=false;else{f[a].opacity=(counter*100);f[a].enabled=true}}}else ref.style.opacity=ref.style.MozOpacity=counter*0.999};FSMenu.animClipDown=function(ref,counter,show){var cP=Math.pow(Math.sin(Math.PI*counter/2),0.75);ref.style.clip=(counter==1?((window.opera||navigator.userAgent.indexOf('KHTML')>-1)?'':'rect(auto,auto,auto,auto)'):'rect(0,'+ref.offsetWidth+'px,'+(ref.offsetHeight*cP)+'px,0px)')};FSMenu.prototype.activateMenu=function(id,subInd){with(this){if(!isDOM||!document.documentElement)return;var fsmFB=getRef('fsmenu-fallback');if(fsmFB){fsmFB.rel='alternate stylesheet';fsmFB.disabled=true}var a,ul,li,parUL,mRoot=getRef(id),nodes;if(!FSMenu._count)FSMenu._count=1;var evtProp=navigator.userAgent.indexOf('Safari')>-1||isOp?'safRtnVal':'returnValue';var lists=mRoot.getElementsByTagName('ul');for(var i=0;i<lists.length;i++){li=ul=lists[i];while(li){if(li.nodeName.toLowerCase()=='li')break;li=li.parentNode}if(!li)continue;parUL=li;while(parUL){if(parUL.nodeName.toLowerCase()=='ul')break;parUL=parUL.parentNode}a=li.getElementsByTagName('a');if(!a)continue;a=a.item(0);var menuID;if(ul.id)menuID=ul.id;else{menuID=myName+'-id-'+FSMenu._count++;ul.setAttribute('id',menuID)}if(menus[menuID]&&menus[menuID].lyr.ref==ul)continue;menus[menuID]=new FSMenuNode(menuID,false,this);var rootItem=(li.parentNode==mRoot)?1:0;var eShow=new Function('with('+myName+'){var m=menus["'+menuID+'"],pM=menus["'+parUL.id+'"];if(!showOnClick||(showOnClick==1&&!'+rootItem+')||((showOnClick<=2)&&((pM&&pM.child)||(m&&m.visible))))show("'+menuID+'",this)}');var eHide=new Function('e','if(e.'+evtProp+'!=false)'+myName+'.hide("'+menuID+'")');addEvent(a,'mouseover',eShow);addEvent(a,'mouseout',eHide);addEvent(a,'focus',eShow);addEvent(a,'blur',eHide);addEvent(a,'click',new Function('e','var s='+myName+'.showOnClick,m='+myName+'.menus["'+menuID+'"];if(!((s==1&&'+rootItem+')||s>=2))return;'+myName+'[m&&m.visible?"hide":"show"]("'+menuID+'",this);if(e.cancelable&&e.preventDefault)e.preventDefault();e.'+evtProp+'=false;return false'));if(subInd)a.insertBefore(subInd.cloneNode(true),a.firstChild)}var aNodes=mRoot.getElementsByTagName('a');for(var i=0;i<aNodes.length;i++){addEvent(aNodes[i],'focus',new Function('e','var node=this.parentNode;while(node){if(node.onfocus)node.onfocus(e);node=node.parentNode}'));addEvent(aNodes[i],'blur',new Function('e','var node=this.parentNode;while(node){if(node.onblur)node.onblur(e);node=node.parentNode}'))}if(hideOnClick)addEvent(mRoot,'click',new Function('e','if(e.'+evtProp+'!=false)'+myName+'.hideAll()'));menus[id]=new FSMenuNode(id,true,this)}};var page={win:self,minW:0,minH:0,MS:isIE&&!isOp,db:document.compatMode&&document.compatMode.indexOf('CSS')>-1?'documentElement':'body'};page.elmPos=function(e,p){var x=0,y=0,w=p?p:this.win;e=e?(e.substr?(isNS4?w.document.anchors[e]:getRef(e,w)):e):p;if(isNS4){if(e&&(e!=p)){x=e.x;y=e.y};if(p){x+=p.pageX;y+=p.pageY}}if(e&&this.MS&&navigator.platform.indexOf('Mac')>-1&&e.tagName=='A'){e.onfocus=new Function('with(event){self.tmpX=clientX-offsetX;self.tmpY=clientY-offsetY}');e.focus();x=tmpX;y=tmpY;e.blur()}else while(e){x+=e.offsetLeft;y+=e.offsetTop;e=e.offsetParent}return{x:x,y:y}};if(isNS4){var fsmMouseX,fsmMouseY,fsmOR=self.onresize,nsWinW=innerWidth,nsWinH=innerHeight;document.fsmMM=document.onmousemove;self.onresize=function(){if(fsmOR)fsmOR();if(nsWinW!=innerWidth||nsWinH!=innerHeight)location.reload()};document.captureEvents(Event.MOUSEMOVE);document.onmousemove=function(e){fsmMouseX=e.pageX;fsmMouseY=e.pageY;return document.fsmMM?document.fsmMM(e):document.routeEvent(e)};function isMouseIn(sty){with(sty)return((fsmMouseX>left)&&(fsmMouseX<left+clip.width)&&(fsmMouseY>top)&&(fsmMouseY<top+clip.height))}}

//	function LightEm()
//	{
//		setTimeout(LightUpCategoryImages, 700);
//	}
//	function LightUpCategoryImages()
//	{
//		<%
//		i = 0.0
//		if IsDefined("ProductCategories"):
//			for pc in ProductCategories:
//			%>
//				new Effect.Appear('ProductCategoryImageContainer_${pc.ProductCategoryId}',{delay:${i},from:0.0,to:1.0} );
//			<%
//			i = i + .10
//			end
//		end%>
//	}

	var theWindow = null;
	var theWindowOpen = false;
	var curPageHeight = 0;
	var curPageWidth = 0;
	var curPageX = 0;
	var curPageY = 0;
	
	//handle all scroll events
	if ("onmousewheel" in document)
	{
		document.onmousewheel = ScrollDetected;
	}
	if (window.addEventListener)
	{
		window.addEventListener("DOMMouseScroll", ScrollDetected, false);
		window.addEventListener("scroll", ScrollDetected, false);
		window.addEventListener("mousemove", ScrollDetected, true);
	}
	else if (document.addEventListener) // Opera 7+
	{
		document.addEventListener("scroll", ScrollDetected, false);
	}
	else if (document.all && document.compatMode && document.compatMode == "CSS1Compat")
	{
		if ("onscroll" in self)
		{	
			window.onscroll = ScrollDetected;
		}
	}
	
	function ScrollDetected()
	{
		if (theWindowOpen)
		{
			getPageDimensions();
			getScroll();
			
			var nTop = curPageY - curPageHeight;
			if(nTop < 0)
				nTop = 0;
				
			var nHeight = curPageHeight * 2;
			$('lightwindow_overlay').setStyle(
				{
					left: 0,
					top: nTop + 'px',
					width: curPageWidth + 'px',
					height: nHeight + 'px'
				});
			
		}
	}
	
	function getPageDimensions()
	{
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) 
		{
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} 
		else if (document.body.scrollHeight > document.body.offsetHeight)
		{
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} 
		else 
		{
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) 
		{
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} 
		else if (document.documentElement && document.documentElement.clientHeight) 
		{
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} 
		else if (document.body) 
		{
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	

		//if (yScroll < windowHeight)
		//{
			curPageHeight = windowHeight;
		//} 
		//else 
		//{
		//	curPageHeight = yScroll;
		//}

		//if (xScroll < windowWidth)
		//{
			curPageWidth = windowWidth;
		//} 
		//else 
		//{
		//	curPageWidth = xScroll;
		//}
	}
	
	function getScroll()
	{
		if ( typeof(window.pageYOffset) == 'number') 
		{
        	curPageX = window.pageXOffset;
        	curPageY = window.pageYOffset;
      	} 
      	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) 
      	{
	       	curPageX = document.body.scrollLeft;
        	curPageY = document.body.scrollTop;
		} 
		else if (document.documentElement) 
		{
        	curPageX = document.documentElement.scrollLeft;
        	curPageY = document.documentElement.scrollTop;
      	}
	}

	function ShowLightbox(link)
	{	
		if(!theWindowOpen)
		{
			theWindowOpen = true;
			
			if(!theWindow)
				theWindow = new lightwindow();
				
			theWindow.activateWindow(
			{
				href: link,
				title: '',
				type: 'page'
			});
			
			ScrollDetected();
		}
	}

	function ShowLightboxIframe(link)
	{
		if(!theWindowOpen)
		{
			theWindowOpen = true;	
		
			if(!theWindow)
				theWindow = new lightwindow();
				
			theWindow.activateWindow(
			{
				href: link,
				title: '',
				type: 'external'
			});	
			
			ScrollDetected();
		}
	}
	
	function SimplexityTradeWindow_ValidateAndSubmit(area)
	{
		//alert("HI");
		var valid = new Validation('form1', {onSubmit:false});
		var result = valid.validate();
		
		if(result == true)
		{
			//alert("good");
			
			//new Ajax.Updater('AppraisalValue', '/' + area + '/Cart/BeginAppraisal-UpdatePrice.rails', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)});
			
			//valid.reset();
			//$('AcceptButtonImage').show();
			
			new Ajax.Updater('AppraisalValue', '/' + area + '/Cart/BeginAppraisal-SimplexityTradeWindow_UpdatePrice.rails', {parameters:$('form1').serialize(),onComplete:function(){ new Effect.Appear('submitContainer');new Effect.Highlight('AppraisalValue'); setTimeout("$('AcceptButtonImage').focus()",1000)  } });

			
		}
		else
		{
			//alert("bad");
			//$('acceptButtonImage').hide();
			ResetTheElements();
		}
		
		return false;
	}
	
	function ValidateAndSubmit(area)
	{
		//alert("HI");
		var valid = new Validation('form1', {onSubmit:false});
		var result = valid.validate();
		
		if(result == true)
		{
			//alert("good");
			
			//new Ajax.Updater('AppraisalValue', '/' + area + '/Cart/BeginAppraisal-UpdatePrice.rails', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)});
			
			//valid.reset();
			//$('AcceptButtonImage').show();
			
			new Ajax.Updater('AppraisalValue', '/' + area + '/Cart/BeginAppraisal-UpdatePrice.rails', {parameters:$('form1').serialize(),onComplete:function(){ new Effect.Appear('submitContainer');new Effect.Highlight('AppraisalValue'); setTimeout("$('AcceptButtonImage').focus()",1000)  } });

			
		}
		else
		{
			//alert("bad");
			//$('acceptButtonImage').hide();
			ResetTheElements();
		}
		
		return false;
	}
	
	function ValidateShippingAndSubmit()
	{
		var valid = new Validation('form1', {useTitles : true});

	    
		var result = valid.validate();
		
		if(result == true)
		{
			$('form1').submit();
		}
		else
		{
			//$('AgreeToTermsText').className = 'validation-failed';
			
			 new Effect.Highlight('AgreeToTermsText', {duration:2.0});
			 new Effect.Highlight('AgreeToTermsText2', {duration:2.0});
			
			$('errors').update('Please Complete All Fields.');
			$('errors').className = 'visible';
			$('errors').addClassName('validation-failed');
		}
		
		return false;
	}	
	
	function ValidateWireFlyEmailAndSubmit()
	{
		var valid = new Validation('form1', {useTitles : true});

	    
		var result = valid.validate();
		
		if(result == true)
		{
			$('form1').submit();
		}
		else
		{
			//$('AgreeToTermsText').className = 'validation-failed';
			
			$('errors').update('Please Complete All Fields.');
			$('errors').className = 'visible';
			$('errors').addClassName('validation-failed');
		}
		
		return false;
	}	
	
	function getViewport(){
		var viewportwidth;
		var viewportheight;
		var ret = new Array();
	
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
		if (typeof window.innerWidth != 'undefined')
		{
			viewportwidth = window.innerWidth,
			viewportheight = window.innerHeight
		}
	
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
		else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
		{
			viewportwidth = document.documentElement.clientWidth,
			viewportheight = document.documentElement.clientHeight
		}
		
		// older versions of IE
		
		else
		{
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}
		ret[0] = viewportwidth;
		ret[1] = viewportheight;
		return ret;
	}
		
	function ResetTheElements()
	{
		new Effect.Fade('submitContainer',{duration:0.4});
		$('AppraisalValue').update('--');
		
		return false;
	}
	
	function ValidateComponentSets(el)
	{
		// Find and set the parents.
		var idOfSelectedItem = $F(el);
		var objectSelectedItem = $(idOfSelectedItem);
		var objectSelectedItemClassSplitArray = $A(objectSelectedItem.classNames())[0];
		var parentIdOfSelectedItem = objectSelectedItemClassSplitArray.split('-')[1];

		// Find all SELECT OPTION items with a VALUE of idOfSelectedItem and select it.
		//console.log($(parentIdOfSelectedItem));
		if($(parentIdOfSelectedItem) != null) {
			$(parentIdOfSelectedItem).selected = true;	
		}
		
		// Find and switch the set for children of set parent.  In the loop of each
		// SELECT element that has the parentSet-[id], find the other SELECT elements
		// with the same modelComponentTypeId-[componentTypeId] as the current.  Hide it,
		// and show the current.

		var childSets = $$('.parentSet-' + parentIdOfSelectedItem + '');
		//console.log(childSets);

		// Hide all of the SELECT elements with the same modelComponentTypeId-[]
		childSets.each(function(s) {
				// Get this SELECT elements current modelComponentTypeId
				var parent_classNamesArray = $A(s.classNames());
				var sibling_componentTypeName = parent_classNamesArray[0];
				//console.log(sibling_componentTypeName);

				// Find the modelComponentTypeId-[] siblings.
				var siblings = $$('.' + sibling_componentTypeName + '');
				//console.log(siblings);
				
				// Hide the siblings.
				siblings.each(function(c) {
						//console.log(c);
						c.hide();
					}
				);
				
				// Show the correct one, with .parentSet-[parentIdOfSelectedItem].
				var correctSet = $$('.parentSet-' + parentIdOfSelectedItem + '').each(function(i) {
						i.show();
					}
				);
				
				// Reset the selectedIndex on all HIDDEN siblings.
				siblings.each(function(c) {
						if(!$(c).visible())
						{
							$(c).selectedIndex = 0;
						}
					}
				);
			}
		);
		
		// Find and switch the set for children of selected item.  In the loop of each
		// SELECT element that has the parentSet-[id], find the other SELECT elements
		// with the same modelComponentTypeId-[componentTypeId] as the current.  Hide it,
		// and show the current.
		var childSets = $$('.parentSet-' + idOfSelectedItem + '');
		//console.log(childSets);

		// Hide all of the SELECT elements with the same modelComponentTypeId-[]
		childSets.each(function(s) {
				// Get this SELECT elements current modelComponentTypeId
				var parent_classNamesArray = $A(s.classNames());
				var sibling_componentTypeName = parent_classNamesArray[0];
				//console.log(sibling_componentTypeName);

				// Find the modelComponentTypeId-[] siblings.
				var siblings = $$('.' + sibling_componentTypeName + '');
				//console.log(siblings);
				
				// Hide the siblings.
				siblings.each(function(c) {
						//console.log(c);
						c.hide();
					}
				);
				
				// Show the correct one, with .parentSet-[parentIdOfSelectedItem].
				var correctSet = $$('.parentSet-' + idOfSelectedItem + '').each(function(i) {
						i.show();
					}
				);
				
				// Reset the selectedIndex on all HIDDEN siblings.
				siblings.each(function(c) {
						if(!$(c).visible())
						{
							$(c).selectedIndex = 0;
						}
					}
				);
			}
		);
	}
	
	function UpdateCondition(conditionId, area, idToUpdate, updateMessage)
	{
		$('ConditionStars').className = 'rating star_' + conditionId;
		$('Condition').value = conditionId;
		$('Condition_DisplayName').value = updateMessage;
		UpdateConditionDescription(idToUpdate, updateMessage);

		//new Effect.Fade('SubmitContainer',{duration:0.1});
		
		ValidateAndSubmit(area);
		
		//var t=setTimeout("$('AcceptButtonImage').focus()",1000);
		//$('AcceptButtonImage').AddClassName('visible');
	}
	
	function SimplexityTradeWindow_UpdateCondition(conditionId, area, idToUpdate, updateMessage)
	{
		$('ConditionStars').className = 'rating star_' + conditionId;
		$('Condition').value = conditionId;
		$('Condition_DisplayName').value = updateMessage;
		UpdateConditionDescription(idToUpdate, updateMessage);

		//new Effect.Fade('SubmitContainer',{duration:0.1});
		
		SimplexityTradeWindow_ValidateAndSubmit(area);
		
		//var t=setTimeout("$('AcceptButtonImage').focus()",1000);
		//$('AcceptButtonImage').AddClassName('visible');
	}
	
	function UpdateConditionDescription(theElementId, message)
	{
		//new Effect.Fade(theElementId,{duration:0.3});
		$(theElementId).update(message);
		//new Effect.Appear(theElementId,{duration:0.3});
	}
	
	function ResetSelectedDescription(theElementId)
	{
		UpdateConditionDescription(theElementId, $('Condition_DisplayName').value);
	}
	
	
	function ShowModelPopupNew(imagePath, modelName, width, height)
	{
		var day = new Date();
		var id = day.getTime();
		var ww = width;
		var wh = height + 125;
		var params = 'width=' + ww + ',height=' + wh + ',menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no';
		var msg = '<html><head><title>' + modelName + '</title></head><body style="margin: 0; padding: 0;"><div style="margin: 0; padding: 0;" align="center"><img style="margin: 0; padding: 0;" height="' + height + 'px" width="' + width + 'px" src="' + imagePath + '" alt="' + modelName + '" />\n' +
				  '<hr style="margin: 0; padding: 0;" width="100%" /><form><input style="margin: 0; padding: 0;" type="button" onClick="javascript:window.close()" value="Close Window"></form></div></body></html>\n';
		
		var win = window.open('', id, params);
		win.document.write(msg);
		win.document.close();
	}
	function ShowModelPopup(modelId, modelName, width, height)
	{
		var day = new Date();
		var id = day.getTime();
		var ww = width;
		var wh = height + 125;
		var params = 'width=' + ww + ',height=' + wh + ',menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no';
		var imgSrc = '/showModelThumb/Show.rails?modelId=' + modelId + '&h=' + height + '&w=' + width;
		var msg = '<html><head><title>' + modelName + '</title></head><body style="margin: 0; padding: 0;"><div style="margin: 0; padding: 0;" align="center"><img style="margin: 0; padding: 0;" src="' + imgSrc + '" alt="' + modelName + '" />\n' +
				  '<hr style="margin: 0; padding: 0;" width="100%" /><form><input style="margin: 0; padding: 0;" type="button" onClick="javascript:window.close()" value="Close Window"></form></div></body></html>\n';
		
		var win = window.open('', id, params);
		win.document.write(msg);
		win.document.close();
	}
	
	function ShowTutorialPopup(url)
	{
		var day = new Date();
		var id = day.getTime();
		var params = 'width=775,height=715,menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no';
		window.open(url, id, params);
	}
	
	function renewSession()
	{
		$("renewSession").src = "/renewSession.aspx?par=" + Math.random();
		//alert("Session Is New Again!");
	}	

	function page_loaded(evt)
	{
	  //Event.observe('my_menu', 'mouseover', menus, false)
	  window.setInterval("renewSession()", 240000);
	}
	
	Event.observe(window, 'load', page_loaded, false);
	
	newimage0 = new Image();
	newimage0.src = "/Content/images/lightwindow/black-80.png";
	newimage1 = new Image();
	newimage1.src = "/Content/images/lightwindow/black.png";
	newimage2 = new Image();
	newimage2.src = "/Content/images/lightwindow/ajax-loading.gif";
	newimage3 = new Image();
	newimage3.src = "/Content/images/cexchange/star_rating/star-matrix2.jpg";
	newimage4 = new Image();
	newimage4.src = "/Content/images/cexchange/body/grdButtonAccept.gif";
	newimage5 = new Image();
	newimage5.src = "/Content/images/cexchange/body/grdButtonAccept_1.gif";
	newimage6 = new Image();
	newimage6.src = "/Content/images/cexchange/body/grdButtonCalc.gif";
	newimage7 = new Image();
	newimage7.src = "/Content/images/cexchange/body/grdButtonCalc_1.gif";

var listMenu = new FSMenu('listMenu', true, 'display', 'block', 'none');

listMenu.animations[listMenu.animations.length] = FSMenu.animFade;
listMenu.animations[listMenu.animations.length] = FSMenu.animSwipeDown;

var arrow = null;
if (document.createElement && document.documentElement)
{
	arrow = document.createElement('span');
	arrow.appendChild(document.createTextNode(''));
	arrow.className = 'subind';
}

addEvent(window, 'load', new Function('listMenu.activateMenu("listMenuRoot", arrow)'));

