var submitCount=0;

function checkFields() {
	if (submitCount == 0) {
		if (document.RegForm.Email.value == "") {
			if (document.RegForm.PartnerOffers.checked) {
				alert("To receive selected SoundSpectrum partner offers, please enter your e-mail address. Otherwise, uncheck the checkbox and click on the \"Download\" button to proceed with your download.");
				return false;
			}
		}
		submitCount++;
		return true; 
	} else {
		alert("To begin additional downloads, you must force-reload this page by clicking on the \"Refresh\" button of your web browser.");
		return false;
	}
}


function checkMultipleSubmits(alertMsg) {
    if (submitCount == 0) {
        submitCount++;
        return true;
    } else {
        alert(alertMsg);
        return false;
    }
}


function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


function rollSetup() {
 /** string added to "on" state images */
 var post = "_o";

 /** fetch the image tag array from the DOM */
 var imgTags = document.getElementsByTagName("img");

 /** loop through the images for find appropriate preloads */
 for (i=0; i < imgTags.length; i++) {
  /** make sure there is a source defined */
  if (imgTags[i].src != '') {
   /** make sure the image tag has a class */
   tmpClass = imgTags[i].className;
   if (tmpClass) {
    /** match the image rollover class */  
    if (tmpClass.match("rollover")) {
     /** store the image source to the 'imgOut' attribute */    
     imgTags[i].imgOut = new Image();
     imgTags[i].imgOut.src = imgTags[i].src;
	
     /** pull apart the source string */
     srcLength = imgTags[i].src.length;

     srcName = imgTags[i].src.substr(0, srcLength-4);
     srcExt = imgTags[i].src.substr(srcLength-4, srcLength);

     /** store the image source to the 'imgOver' attribute */
     imgTags[i].imgOver = new Image();
     imgTags[i].imgOver.src = srcName + post + srcExt;

     /** set up the 'onmouseover' and 'onmouseout' event handlers */     
     imgTags[i].onmouseover = function() {
      this.src = this.imgOver.src;
     }
     imgTags[i].onmouseout = function() {
      this.src = this.imgOut.src;
     }
    }
   }
  }
 }
}


function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}


addEvent(window,'load',rollSetup,false);

// from http://www.sitepoint.com/article/take-command-ajax
var http_request = false;
function makeRequest(url) {
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	http_request.open('GET', url, false);
	http_request.send(null);
} 


function OnGiftEmailDeliverySelected(selected) {
	document.forms[0].Email.disabled = !selected;
	document.forms[0].month.disabled = !selected;
	document.forms[0].day.disabled = !selected;
	document.forms[0].year.disabled = !selected;
	
	document.forms[0].ShippingType.disabled = selected;
	document.forms[0].Address1.disabled = selected;
	document.forms[0].Address2.disabled = selected;
	document.forms[0].City.disabled = selected;
	document.forms[0].State.disabled = selected;
	document.forms[0].Zip.disabled = selected;
	document.forms[0].Country.disabled = selected;
	document.forms[0].lmonth.disabled = selected;
	document.forms[0].lday.disabled = selected;
	document.forms[0].lyear.disabled = selected;
	document.forms[0].Wrapped.disabled = selected;
}
