//------------------------------------------------------
// image preloader
function preload(images) {
    if (document.images) {
        var i = 0;
        var imageArray = new Array();
        imageArray = images.split(',');
        var imageObj = new Image();
        for(i=0; i<=imageArray.length-1; i++) {
            //document.write('<img src="' + imageArray[i] + '" />');	// Write to page (uncomment to check images)
            imageObj.src=images[i];
        }
    }
}
// usage: write this call on any page using full path to file from doc root
// preload('image1.jpg,image2.jpg,image3.jpg');

//------------------------------------------------------------
// jump to URL for gallery

function JBOT1() {
  iSelectedIndex = document.JBOT1.dest.selectedIndex;
  document.JBOT1.dest.selectedIndex = 0;
  window.open( document.JBOT1.dest.options[iSelectedIndex].value,'_self');
}
//-------------------------------------------------------------
// Add apparel to cart
// NOT USED ***

	function addToCart(product) {
		var buttonObj = document.getElementById('button' + product);
		buttonObj.value = '...loading';
		buttonObj.style.color = 'red';
		var selObj = document.getElementById('size' + product);
		var selIndex = selObj.selectedIndex;
		var size = selObj.options[selIndex].value;
		var qtyObj = document.getElementById('qty' + product);
		var qty = qtyObj.value;
		var URL = 'http://rcdengineering.com/cart/add/p' + product + '_q' + qty + '_a2o' + size + '?destination=cart';  
		window.open(URL,'_self');
	}
	function addToCartCap(product) {
		var buttonObj = document.getElementById('button' + product);
		buttonObj.value = '...loading';
		buttonObj.style.color = 'red';
		var selObj = document.getElementById('size' + product);
		var selIndex = selObj.selectedIndex;
		var size = selObj.options[selIndex].value;
		var qtyObj = document.getElementById('qty' + product);
		var qty = qtyObj.value;
		var URL = 'http://rcdengineering.com/cart/add/p' + product + '_q' + qty + '_a1o' + size + '?destination=cart';  
		window.open(URL,'_self');
	}

//-------------------------------------------------------------------------
// request a catalog form validation

			function validatePage1()
			{
				retVal = true;
				if (validateField('field_8','fieldBox_8','menu',1) == false)
				 retVal=false;	
				if (validateField('field_7','fieldBox_7','text',1) == false)
				 retVal=false;		
				if (validateField('field_6','fieldBox_6','text',1) == false)
				 retVal=false;		
				if (validateField('field_5','fieldBox_5','text',1) == false)
				 retVal=false;		
				if (validateField('field_3','fieldBox_3','text',1) == false)
				 retVal=false;	
				if (validateField('field_2','fieldBox_2','email',1) == false)
				 retVal=false;				 				 	 		 		 	
				if (validateField('field_1','fieldBox_1','text',1) == false)
				 retVal=false;

				if(retVal == false)
				{
					alert('Please correct the errors.  Fields marked with an asterisk (*) are required');
					return false;
				}	
				else
				{	             
                                setTimeout("document.formC.reset()",3000);
                                
								 // downloading...message
								 /*
                                if(document.formC.catalog[0].checked) 
                                {
									ele = document.getElementById('mainMessage');
									ele.style.display = 'block';                                        
			                    }
                                */    
                   return true;             
				}
				
				
             }						
		
//-------------------------------------------------------------------------
// gallery upload form validation

			function validateGalleryUpload()
			{
				retVal = true;		
				if (validateField('userfile','fieldBox_6','text',1) == false)
				 retVal=false;		
				if (validateField('email','fieldBox_3','email',1) == false)
				 retVal=false;	
				if (validateField('name','fieldBox_2','text',1) == false)
				 retVal=false;				 				 	 		 		 	
				if (validateField('title','fieldBox_1','text',1) == false)
				 retVal=false;

				if(retVal == false)
				{
					alert('Please correct the errors.  Fields marked with an asterisk (*) are required');
					return false;
				}				
				document.formGalleryUpload.reset();
                //alert ('Thank you!\n\nYour data has been sent.');						
			}
//-------------------------------------------------------------------------
// contact form validation

			function validateContactForm()
			{
				retVal = true;		
				if (validateField('field_4','fieldBox_4','text',1) == false)
				 retVal=false;		
				if (validateField('field_3','fieldBox_3','text',1) == false)
				 retVal=false;	
				if (validateField('field_2','fieldBox_2','email',1) == false)
				 retVal=false;				 				 	 		 		 	
				if (validateField('field_1','fieldBox_1','text',1) == false)
				 retVal=false;

				if(retVal == false)
				{
					alert('Please correct the errors.  Fields marked with an asterisk (*) are required');
					return false;
				}				
				document.formContact.reset();
                //alert ('Thank you!\n\nYour message has been sent.');						
			}
//----------------------------------------------------------------------
// validation functions
			function validateField(fieldId, fieldBoxId, fieldType, required)
			{
				// fieldBox = document.getElementById(fieldBoxId);
				fieldObj = document.getElementById(fieldId);
				// field type
				if(fieldType == 'text')
				{	
					if(required == 1 && fieldObj.value == '')
					{
						fieldObj.style.backgroundColor = '#FADADD';
						fieldObj.focus();
						return false;					
					}
					else { fieldObj.style.backgroundColor = '#ffffff'; }
				}
				// field type
				else if(fieldType == 'menu')
				{	
					if(required == 1 && fieldObj.selectedIndex == 0)
					{				
						fieldObj.style.backgroundColor = '#FADADD';
						fieldObj.focus();
						return false;					
					}
					else { fieldObj.style.backgroundColor = '#ffffff'; }
				}
				// field type
				else if(fieldType == 'email')
				{	
					if((required == 1 && fieldObj.value=='')  ||  (fieldObj.value!=''  && !validate_email(fieldObj.value)))
					{				
						fieldObj.style.backgroundColor = '#FADADD';
						fieldObj.focus();
						return false;					
					}
					else { fieldObj.style.backgroundColor = '#ffffff'; }
				}
			}

			function validate_email(emailStr)
			{		
				apos=emailStr.indexOf("@");
				dotpos=emailStr.lastIndexOf(".");

				if (apos<1||dotpos-apos<2) 
				{
					return false;
				}
				else
				{
					return true;
				}
			}
//-----------------------------------------------------------------------------


