// jQuery goes in here
$(document).ready(function() {
	if ( $('#dr_StudentHeroRegistration').length>0 ) {
		/* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */
		function echeck(str) {
			var at="@";
			var dot=".";
			var lat=str.indexOf(at);
			var lstr=str.length;
			var ldot=str.indexOf(dot);
			if (str.indexOf(at)==-1){ alert("Invalid E-mail Address"); return false; }
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Invalid E-mail Address"); return false; }
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("Invalid E-mail Address"); return false;}
			if (str.indexOf(at,(lat+1))!=-1){ alert("Invalid E-mail Address"); return false; }
			if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Invalid E-mail Address"); return false; }
			if (str.indexOf(dot,(lat+2))==-1){ alert("Invalid E-mail Address"); return false; }
			if (str.indexOf(" ")!=-1){ alert("Invalid E-mail Address"); return false; }
			return true; 
		}
		function showdiv(id) {
			//safe function to show an element with a specified id
			if (document.getElementById) { // DOM3 = IE5, NS6
				if (document.getElementById(id).style.display == 'block') {
					document.getElementById(id).style.display = 'none';
				}
				else {
					document.getElementById(id).style.display = 'block';
				}
			}
			else {
				if (document.layers) { // Netscape 4
					document.id.display = 'block';
				}
				else { // IE 4
					document.all.id.style.display = 'block';
				}
			}
		}
	}
	$('#winprodgrp img').removeAttr('alt').attr('alt','Windows 7');
	if ( $('#dr_ProductDetails').length>0 ) {
		$('#relatedProductLink').click(function (e) {
			e.preventDefault();
			$('#dr_relatedProductsContainer').modal({position: ["30%","40%"]}); });
	}
	if ( $('#dr_CustomerServiceOrderSearch').length>0 ) {	
		$('#dr_CustomerServiceOrderSearch #dr_trackingNumber').remove();
	}
	$('select#state option:contains("Not Applicable")').remove();
	$('#dr_ExtendedDownloadServiceOffer').css({'font-weight':'bold'});
	$('.dr_lineItemDetails a').css({'font-weight':'bold'});
	$('#optIn').attr('checked','checked');
	if ( $('#dr_CheckoutPayment').length>0 ) {
		// Conditionally enforcing Puerto Rico as Country selection
		function dropdown(){
			if($('select[name="state"]').val()=="PR"){
		      		$('select[name="country"]').val($('select[name="state"]').val())
		     	}
		  	}
		$('select[name="state"]').bind('change', dropdown);
		$('select[name="state"]').bind('focus', dropdown);
		$('select[name="state"]').bind('blur', dropdown);
		//$(document).bind('load', function(){alert('hi')});
		dropdown();
		//hide save addressBook dropdown
		$('div#addressBook').hide();
		$('#addressBook #selectAddr option[selected=selected]').removeAttr('selected');
		$('div#addressBook select#selectAddr option:last').attr('selected','selected');
	}
	if ( $('#dr_previous').length>0 ) {  
		$('#dr_previous').text('previous page').click(function (e) {
			e.preventDefault();
			history.go(-1);
		});
	}
	if ( $('#dr_StoreLink').length>0 ) {  
		$('#dr_StoreLink').change(function(e) {
			e.preventDefault();
			window.location.href=this.options[this.selectedIndex].value;
		});
	}
	//IE7 hack
	var ie7Browser = (/MSIE (7)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (ie7Browser) {
		$('ol').css('margin-left','2em');
		$('ul').css('margin-left','1.5em');
	}
	// PNG Fix (jQuery.com)
	var ie6lowerBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (ie6lowerBrowser) {
	 // get all pngs on page
	 $('img[src$=.png]').each(function() {
		 if (!this.complete) {
			 this.onload = function() { fixPng(this) };
		 } else {
			 fixPng(this);
		 }
	 });
	}
}); // document ready ends here
