
// Populates the shipping fields if the customer checks 'Same as billing'
function popFields(){
	
	c_name = document.getElementById('ccname').value;
	c_add1 = document.getElementById('billstreet').value;
	c_add2 = document.getElementById('billstreet2').value;
	c_city = document.getElementById('billcity').value;
	c_state = document.getElementById('billstate').value;
	c_zip = document.getElementById('billzip').value;
	
	document.getElementById('shipname').value = c_name;
	document.getElementById('shipstreet').value = c_add1 ;
	document.getElementById('shipstreet2').value = c_add2; 
	document.getElementById('shipcity').value = c_city ;
	document.getElementById('shipstate').value = c_state;
	document.getElementById('shipzip').value = c_zip ;
	
}

// Validates the checkout form before submitting

function checkFields() {
	if(document.SAMform.bridesname.value == '') {
		alert("Please enter your name");
		return false;
		}
		
	else if(document.SAMform.bridesemail.value == '') {
		alert("Please enter your email address");
		return false;
		}
		
	else if(document.SAMform.bridesphonenumber.value =='') {
		alert("Please enter your phone number");
		return false;
		}
		
	else if(document.SAMform.ccnum.value =='') {
		alert("Please enter your credit card number");
		return false;
		}
		
	else if(document.SAMform.billstreet.value == '') {
		alert("Please enter your street address");
		return false;
		}
		
	else if(document.SAMform.billcity.value =='') {
		alert("Please enter your city");
		return false;
		}
		
	else if(document.SAMform.billzip.value =='') {
		alert("Please enter your zip code");
		return false;
		}
		
	else if(document.SAMform.shipname.value =='') {
		alert("Please enter the name of the person we are shipping to or check Same As Billing");
		return false;
		}
		
	else if(document.SAMform.shipstreet.value == '') {
		alert("Please enter the street address we are shipping to or check Same As Billing");
		return false;
		}
		
	else if(document.SAMform.shipcity.value =='') {
		alert("Please enter the city we are shipping to or check Same As Billing");
		return false;
		}
		
	else if(document.SAMform.shipstate.value =='') {
		alert("Please enter the state we are shipping to or check Same As Billing");
		return false;
		}
		
	else if(document.SAMform.shipzip.value =='') {
		alert("Please enter the zip code we are shipping to or check Same As Billing");
		return false;
		}		
		
	return true;	
				
}

// css light box  //

function OpenLightBox(image_path,iwidth,iheight){

  var browserWidth = 0, browserHeight = 0;   /// this gets the hight and width of the browser window so we can center the light box
  lightBoxLeft = 25;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    browserWidth = window.innerWidth;
    browserHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    browserWidth = document.documentElement.clientWidth;
    browserHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    browserWidth = document.body.clientWidth;
    browserHeight = document.body.clientHeight;
  }

var lightBoxLeft = (browserWidth-iwidth)/2; // center of browser minus half of the light box width

if (window.XMLHttpRequest) {
// IE 7, mozilla, safari, opera 9
ShowIt(image_path,iheight,iwidth,lightBoxLeft);
} else {
// IE6, older browsers
}
  
   
}

function ShowIt(image_path,iheight,iwidth,lightBoxLeft){

   document.getElementById('lightboxcontent').src=image_path;
   
   document.getElementById("fade").style.position="fixed";
   document.getElementById("fade").style.height="100%";
   document.getElementById("fade").style.width="100%";  
   document.getElementById("fade").style.top="0%";
   document.getElementById("fade").style.left="0%";
   document.getElementById("fade").style.backgroundColor="black";
   document.getElementById("fade").style.zIndex="1001";
   document.getElementById("fade").style.MozOpacity="0.5";
   document.getElementById("fade").style.opacity=".50";
   document.getElementById("fade").style.filter="alpha(opacity=50)";
   
   document.getElementById("light").style.position="fixed";
   document.getElementById("light").style.left=lightBoxLeft+"px";
   document.getElementById("light").style.width=(iwidth+3)+"px";
   document.getElementById("light").style.height=(iheight+58)+"px";
   document.getElementById("light").style.top="10%";
   document.getElementById("light").style.backgroundColor="white";
   document.getElementById("light").style.zIndex="2002";
   document.getElementById("light").style.padding="10px";
   document.getElementById("light").style.overflow="auto";
   document.getElementById("light").style.border="20px solid #D2E2AE";
   
   document.getElementById('fade').style.display='block';
   document.getElementById('light').style.display='block';
}

function CloseLightBox(){

   document.getElementById('light').style.display='none';
   document.getElementById('fade').style.display='none';
   document.getElementById('lightboxcontent').src="";
}

// end css light box  //

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}

// Disables the continue button using javascript

function form_disable(buttonID) {
	
	button = document.getElementById(buttonID);
	button.disabled = true;
}	


// Highlights the continue button when the user checks that they agree to a condition

function form_act(buttonID, checkID) {
	
	checkbox = document.getElementById(checkID);
	button = document.getElementById(buttonID);
	getButtonPath = button.src;
	splitIt = getButtonPath.lastIndexOf('/');
	absButtonPath = getButtonPath.substring(0,splitIt);
	
	if(checkbox.checked==true){
		button.src = absButtonPath + '/' + buttonID + '_a.jpg';
		button.disabled=false;
	}
	
	else {
		button.src = absButtonPath + '/' + buttonID + '_b.jpg';
		button.disabled=true;
	}	
	
}	
