// ##### Image Rollover Scripts ##### //
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ##### Form Validation Script - Required Fields ##### //
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// ##### Popup Window Script for Driving Directions ##### //
var win = null;
var wW  = 530;  // popup window width
var wH  = 500;  // popup window height
function get(URL){
	if (window.screen){
		var aW      = screen.availWidth;  // available display area on screen (width)
		var aH      = screen.availHeight; // available display area on screen (height)
		var winTop  = (aH - wH)/2;        // determines top start location of popup window
		var winLeft = (aW - wW)/2;        // determines left start location of popup window
		win = window.open(URL,'map','width='+wW+',height='+wH+',top='+winTop+',left='+winLeft+',scrollbars=yes,resizable=no');
	}
	if (parseInt(navigator.appVersion >= 4)){ win.window.focus(); }
}


/*---------------------------------------------------------------------------
	Pop-up window for larger photographs

	This function opens a new window whose size is determined by that of the
	target image.  The image is dynamically written to the new window with a
	hotspot that closes the new window when an individual clicks on the image
	contained within.  
	It has been tested in IE 5.5 + and NN 6.2 + 
----------------------------------------------------------------------------*/
	  
function getPhoto(Img,W,H){ //receives the target image name, width, and size respectively
	var photoWin 	= null;
	
/*sets the default url for the target image.  To change the
	url, simply replace the "/images/" with the appropriate path (URL)
	Just be sure that the target image exists in the path (URL) specified.*/
	var URL 			= "/preOwned/images/" +Img; 

	var aW 				= screen.availWidth;
	var aH 				= screen.availHeight;
	
	//set the width value for the pop-up window by adding 20 pixels to the target image's width 
	var wW 				= 20 + (parseInt(W));
	
	//set the height value for the pop-up window by adding 40 pixels to the target image's height 			
	var wH 				= 40 + (parseInt(H)); 			
	
	//sets the default top location of the pop-up window
			var winTop 		= 0;												
	//To center the window on the screen, comment out the above line, and uncomment the following line
			//var winTop		= (aH - wH)/2;
	
	//sets the beginning point of the pop-up window (distance from the left)
	//This is currently set to right align the pop-up window.
			//var winLeft 	= aW - (10 + parseInt(wW)); 																				
	//To center the pop-up window on the screen, comment out the above line, and uncomment the following line
			//var winLeft = (aW - wW)/2;
	//To left align the pop-up window, comment out the above lines, and uncomment the following line
			var winLeft = 0;	
	
	
/* Now, we assign the HTML that's to be dynamically written into our pop-up window to a variable
	 It shouldn't be necessary to change any of the code for this variable */
	 	
	var strImage 	= "<html>\r";
			strImage += "<head>\r";
			
			//define a function that resizes the window based upon the target image width and height
			strImage += "<SCR"+"IPT language='JavaScript'> \r";
			strImage += "<!-- \r";
			strImage += "function reSize(){ \r";
			strImage += "if (window.width != "+wW+"){ \r"; 							//checks existing window width
			strImage += " var wW = "+wW+";} \r"; 					 							//sets the window width to the appropriate value
			strImage += "if (window.height != "+wH+"){ \r";							//checks existing window height
			strImage += " var wH = "+wH+";} \r";					 							//sets the window height to the appropraite value
			strImage += "  window.resizeTo(wW,wH); \r";		 							//resizes the window to the new window width & height values (if necessary)
			strImage += "  window.moveTo("+winLeft+","+winTop+"); \r";	//moves the window to the appropriate place on the screen
			strImage += "} \r";
			strImage += "//--> \r";
			strImage += "</scr"+"ipt> \r";
			//end our function
			
			strImage += "</head> \r";
			strImage += "<body bgcolor='#FFFFFF' topmargin='5' leftmargin='5' marginwidth='5' marginheight='5' onLoad='reSize();'> \r";
			strImage += "<p align='center'><a href='javascript:self.close();'> \r";
			strImage += "<img src='"+URL+"' border='0' width='"+W+"' height='"+H+"'> \r";
			strImage += "</a></p> \r";
			strImage += "</body></html> \r";


/* Now that we've finished assigning our new HTML to a variable, it's time to open the pop-up window */				
	photoWin = window.open('','photoWin','width='+wW+',height='+wH+',left='+winLeft+',top='+winTop+',scrollbars=false,resizable=false');
	photoWin.window.focus();
	
	//Write the Image to the New Window & we're done.
	photoWin.document.write(strImage);
	photoWin.document.close();
}
