 /* AJAX Major Functions
    Author: GC Web Studio - Gustavo Campos me@guscampos.com
  */		
  						
			function windowsLoaderAdd(func) {
				windowsLoader[windowsLoader.length] = func;
			}
			function windowsLoadFunc() {
				for(i=0;i<windowsLoader.length;i++) {
					eval(windowsLoader[i]);
				}
			}
			function loadFunc() {
				window.onload = windowsLoadFunc;
			}
			windowsLoader = new Array();
			
			
			//events
			Event.addBehavior({				
				'a#quotesLoc1:click': function() { dom.quotesSetCity('Las Vegas, NV');},
				'a#quotesLoc2:click': function() { dom.quotesSetCity('New York, NY');},
				'a#quotesLoc3:click': function() { dom.quotesSetCity('Phoenix, AZ');},
				'a#quotesClose:click': function() { dom.quotesClose()}
			});
			//ajax events
			Ajax.Responders.register({
				 onCreate: function(){ $('loader').update('<img src="/images/loading.gif" border="0" alt="loading..." title="loading..." />')},
				 onComplete: function(){ $('loader').update('')  }
			});	
			
			dom = {  			  
			  currPanel : 1,
			  nextPanel : 1,			  
			  panelTimer : null,
			  panelDelay : 6,
			  panelSpeed : 10, 
			  panelButtons : true,
			  panelTotal : 0,
			  blackOut: function(){
				//set blackout div width and height
				var winWidth = document.documentElement.offsetWidth;
				var winHeight = document.documentElement.scrollHeight;
				$('blackout').style.display = 'block';
				$('blackout').style.height = winHeight + 'px';
				$('blackout').style.width = winWidth + 'px';
			  },
			
			  playVideo: function(){
				if(navigator.userAgent.indexOf('Safari') != -1) {
					$('movieSm').hide();
				}				
				this.blackOut();
				$('blackout').style.display = 'block';
				$('movie').style.display = 'block';								
				$('VideoFlash').Gotoframe(1);
			  },
			  
			  stopVideo: function() {
				  if($('movieSm')) {
					  if(navigator.appName.indexOf("Microsoft") != -1) {
						$('SmVideo').stopIt();
					  } else {
						document['SmVideo'].stopIt();  
					  }
				  }
			  },
			  
			  //Fade in/out scroller by Gustavo Campos - www.gcwebstudio.com
			  //requires prototype.js
			  //if no prototype is found, change $('panel-' + w) to document.getElementById('panel-' + w);
			  //free for everyone to use
			  
			  fadeIn: function(w,m) {
				  
				   var c;				   
				   var opacity = 0;
				   var timer = 0;
				   var speed = Math.round(500/100);
				   c = $('panel-' + w);
				   if(dom.panelButtons) {
					   b = $('panel-button-' + w);
				   }
				   
				   $('panel-' + dom.currPanel).hide();
				   if(dom.panelButtons) {
				       $('panel-button-' + dom.currPanel).removeClassName('ison');
				   }
				   c.style.opacity = opacity; 
				   c.style.MozOpacity = opacity; 
				   c.style.KhtmlOpacity = opacity; 
				   c.style.filter = "alpha(opacity="+opacity+")"; 
				   c.show();
				   if(dom.panelButtons) {
					   b.addClassName('ison');
				   }
				  			   
				   for(i=0;i<=100;i++) {
					   setTimeout("dom.showIt("+i+","+w+")",(timer*speed));
					   timer++;
				   }
				  
				  dom.currPanel = w;				  
				  if(m == 1) {
					  clearInterval(dom.panelTimer);
					  dom.initFades();
				  }
				 
			  },
			
			  showIt : function(o,w) {	
			    var c;
				c = $('panel-' + w);
				c.style.opacity = (o / 100); 
				c.style.MozOpacity = (o / 100); 
				c.style.KhtmlOpacity = (o / 100); 
				c.style.filter = "alpha(opacity=" + o + ")"; 
			  },
			  
			  rotateFades: function() {
				var total = dom.panelTotal;
				if(total == 1) { return false; }
				if(dom.nextPanel == total) {
					dom.nextPanel = 1;
				} else {
					dom.nextPanel = dom.currPanel + 1;
				}
				dom.fadeIn(dom.nextPanel,2);
			
			  },
			  
			  initFades: function() {
				  dom.panelTimer = setInterval("dom.rotateFades()",(dom.panelDelay*1000));
			  },
			  
			 // NEWSLETTER
			 registerNewsletter:function() {
					if($('form_newsletter').email.value == '') { alert('Please enter a valid email'); return false;}
					if($('form_newsletter').state.value == '') { alert('Please select a state'); return false;}
					var formVals = Form.serialize($('form_newsletter'));
					new Ajax.Request('/js/ajax/newsletter.php?action=newsletter&'+formVals, 
						{   method: 'post',
						
							onSuccess: function(transport) {   
								  
								 var output = transport.responseText || 'Error 1';	
								 alert(output);
								 $('form_newsletter').email.value = '';
								  
							},
								
							onLoading: function() {
								
							},
							
							onLoaded: function() {
								var output = transport.responseText || '0';	 							
								
							},
							onFailure: function() { alert('Error'); } 
						}
					 ); 
				},
				
				unregisterNewsletter:function() {
					if($('form_newsletter').email.value == '') { alert('Please enter a valid email'); return false;}
					if(!window.confirm('Are you sure you want to opt out of our newsletter?')) { 
						$('form_newsletter').email.value = '';
						return false; 
					}
					var formVals = Form.serialize($('form_newsletter'));
					new Ajax.Request('/js/ajax/newsletter.php?action=unsubscribe&'+formVals, 
						{   method: 'post',
						
							onSuccess: function(transport) {   
								  
								 var output = transport.responseText || 'Error 1';	
								 alert(output);	
								 $('form_newsletter').email.value = '';
								  
							},
								
							onLoading: function() {
								
							},
							
							onLoaded: function() {
								var output = transport.responseText || '0';	 							
								
							},
							onFailure: function() { alert('Error'); } 
						}
					 ); 
				},
				
				/* 4wall.com Quotes 
				 * Shoppint cart type quotes (AJAX)
				 */
				inc:0,
				quotesAtStep : 0,
				quotesInterval:null,
				quotesIntervalDone:false,
				quotesGetAvailableWinProps:function() {
					var aw = 0, ah = 0;
					if( typeof( window.innerWidth ) == 'number' ) {
						aw = window.innerWidth;
						ah = window.innerHeight;
					} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
						aw = document.documentElement.clientWidth;
						ah = document.documentElement.clientHeight;
					} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
						aw = document.body.clientWidth;
						ah = document.body.clientHeight;
					}
					return[aw,ah];
				},
				
				quotesBegin:function() {
					
					//start by positioning the first screen
					//get body size
					var aw,ah,ad;
					ad = dom.quotesGetAvailableWinProps();
					aw = ad[0];
					ah = ad[1];
					//get quotes div dimensions
					var quoteDivHeight, quoteDivWidth, quoteDivDimensions;
					quoteDivDimensions = $('quotes').getDimensions();
					quoteDivWidth = quoteDivDimensions.width;
					quoteDivHeight = quoteDivDimensions.height;
					
					//get scrolled pos
					var scTop = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
					var scLeft = document.documentElement.scrollLeft || document.body.scrollLeft || window.pageXOffset;
					scTop = !scTop ? 0 : scTop; //undefined means IE didnt find it, but it will when scrolled
					scLeft = !scLeft ? 0 : scLeft; //same here			
					
					//establish position
					var quoteDivX, quoteDivY;
					quoteDivX = ((aw-quoteDivWidth)/2)+scLeft;
					quoteDivY = ((ah-quoteDivHeight)/2)+scTop;

					dom.blackOut();					
					$('quotes').setStyle({left:quoteDivX+'px',top:quoteDivY+'px'});
					$('quotes').show();

				},
				
				quotesStep1:function() {
					new Ajax.Updater({success:'quotesContainer',failure:'quotesContainer'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'step1'}},{evalScripts:true},{evalJS:true}); 
					
					
				},
				quotesSetCity:function(city) {
					new Ajax.Updater({success:'quotesContainer',failure:'quotesContainer'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'step2',theCity:city}},{evalScripts:true},{evalJS:true}); 
					dom.quotesAtStep = 2;
					
					
				},
				quotesSetType:function(type) {
					new Ajax.Updater({success:'quotesContainer',failure:'quotesContainer'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'step3',quoteType:type}},{evalScripts:true},{evalJS:true});
					dom.quotesAtStep = 3;
					
				},
				
				quotesSetBuildType:function(type) {
					$('quotesContainer').update('<img src="/images/loading.gif" border="0" alt="loading..." title="loading..." />');
					dom.quotesInterval = setInterval(function() { dom.quotesExpandWindow(type,'expand') },10);
					
				},
				quotesRentalsByFilter:function() {
					var cid = $('category').value;
					var mid = $('manufacturer').value;
					new Ajax.Updater({success:'rentalsEntries',failure:'rentalsEntries'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'rentalsByFilter',category:cid,manufacturer:mid}},{evalScripts:true},{evalJS:true}); 
					
				},
				quotesRentalsByFilterUser:function() {
					new Ajax.Updater({success:'rentalsEntries',failure:'rentalsEntries'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'rentalsByFilter',user:'sess'}},{evalScripts:true},{evalJS:true}); 
					
				},
				quotesRentalsSetQuantity:function(n,id) {
					new Ajax.Updater({success:'quotesLoader'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'rentalsSetQty',qty:n,rental:id}},{evalScripts:true},{evalJS:true}); 
					
				},
				quotesRentalsPrepare:function() {
					new Ajax.Request('/index.php', 
									 { method: 'post',
									   parameters: 'action=ajax.quotes&func=rentalsPrepare&comments='+$('comments').value,
									   onSuccess: function(t) {
										   if(t.responseText <= 0) {
										   	 alert('Error, please select at least one item from our inventory');
											 return false;
										   } else {
											   $('quotesContainer').update(t.responseText);
										   }
									   }									   
									 });
					
				},
				quotesExpandWindow:function(type,way) {
					var ww, wh, exh = 680, ch = 0, aw, ah, ad;
					ad = dom.quotesGetAvailableWinProps();
					aw = ad[0];
					ah = ad[1];
					//get scrolled pos
					var scTop = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
					var scLeft = document.documentElement.scrollLeft || document.body.scrollLeft || window.pageXOffset;
					scTop = !scTop ? 0 : scTop; //undefined means IE didnt find it, but it will when scrolled
					scLeft = !scLeft ? 0 : scLeft; //same here	
					var quoteDivX, quoteDivY;
					ww = $('quotes').getWidth();
					wh = $('quotes').getHeight();
					var nX, nY;
					var speed = Math.round(500/100);
					//start expanding	
					if(wh < exh) {
						dom.inc++;
						nX = ((aw-ww)/2)+scLeft;
						nY = ((ah-(ch+wh))/2)+scTop;
						$('quotes').setStyle({left:nX+'px',top:nY+'px'});
						ch = Math.round((exh - wh)/speed);
						$('quotes').setStyle({height:(ch+wh+dom.inc)+'px'});	
						$('quotesContainer').setStyle({height:(ch+wh+dom.inc)+'px'});						
						
					} else {
						clearInterval(dom.quotesInterval);							
						new Ajax.Updater({success:'quotesContainer',failure:'quotesContainer'},'/index.php',
										 {parameters: {action:'ajax.quotes', func:'step4',buildType:type}},{evalScripts:true},{evalJS:true}); 
						return true;						 
					}			
					
				},
				
				quotesCollapseWindow:function() {
					var ww, wh, exh = 215, ch, aw, ah, ad;
					ad = dom.quotesGetAvailableWinProps();
					aw = ad[0];
					ah = ad[1];
					//get scrolled pos
					var scTop = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
					var scLeft = document.documentElement.scrollLeft || document.body.scrollLeft || window.pageXOffset;
					scTop = !scTop ? 0 : scTop; //undefined means IE didnt find it, but it will when scrolled
					scLeft = !scLeft ? 0 : scLeft; //same here	
					var quoteDivX, quoteDivY;
					ww = $('quotes').getWidth();
					wh = $('quotes').getHeight();
					var nX, nY;
					var speed = Math.round(500/100);
					//start expanding	
					if(wh == exh) { clearInterval(dom.quotesInterval);	}
					if(wh > exh) {
						ch = Math.round((wh)/speed);
						$('quotes').setStyle({height:wh-ch+'px'});	
						$('quotesContainer').setStyle({height:wh-ch+'px'});
						nX = ((aw-ww)/2)+scLeft;
						nY = ((ah-(ch+wh))/2)+scTop;
						$('quotes').setStyle({left:nX+'px',top:nY+'px'});
					} else {
						clearInterval(dom.quotesInterval);						
						return true;						 
					}			
					
				},
				
				quotesInit:function() {
					dom.quotesBegin();
					switch(dom.quotesAtStep) {						

						case 2:
						dom.quotesSetCity();
						break;
						
						case 3:
						dom.quotesSetType();
						break;
						
						default:
						dom.quotesStep1();
							
					}
				},
				
				quotesUploadListRefresh:function() {
					new Ajax.Updater({success:'uploadedFiles',failure:'uploadedFiles'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'uploadListRefresh'}},{evalScripts:true},{evalJS:true}); 
				},
				
				quotesUploadDeleteFile:function(f) {
					new Ajax.Updater({success:'uploadedFiles',failure:'uploadedFiles'},'/index.php',
									 {parameters: {action:'ajax.quotes', func:'uploadDeleteFile',file:f}},{evalScripts:true},{evalJS:true}); 
					
				},
				
				quotesSubmit:function(type) {
					new Ajax.Request('/index.php', 
									 { method: 'post',
									   parameters: 'action=ajax.quotes&func=quotesSubmit&type='+type+'&'+$('quotesInfoForm').serialize(),
									   onSuccess: function(t) {
										   if(t.responseText == 1 || t.responseText == true) {		
										     $('quotesContainer').update('<img src="/images/loading.gif" border="0" alt="loading..." title="loading..." />');
										   	 new Ajax.Updater({success:'quotesContainer',failure:'quotesContainer'},'/index.php',
											 {parameters: {action:'ajax.quotes', func:'quotesThanks'}}); 
											 dom.quotesInterval = setInterval(function() { dom.quotesCollapseWindow() },10);
											 dom.quotesAtStep = 0;
										   } else {
											  alert(t.responseText);
										   }
									   } 
									 });
					
				},
				
				quotesClose:function() {
						$('quotes').hide();
						$('blackout').hide();	
				}
				
			}
			
			
			