// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject();
// retrieves the XMLHttpRequest object


function createXmlHttpRequestObject(){
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// if running Internet Explorer
	if(window.ActiveXObject){
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {
			xmlHttp = false;
		}
	
	// if running Mozilla or other browsers
	} else {
		try {
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) {
			xmlHttp = false;
		}
	}
	// return the created object or display an error message



	if (!xmlHttp){
		alert("Error creating the XMLHttpRequest object.");
	} else {
		return xmlHttp;
	}
	// make asynchronous HTTP request using the XMLHttpRequest object
	
}

function ChangeSizes(){
// proceed only if the xmlHttp object isn't busy
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		document.getElementById("sizebox").innerHTML = '<i>loading...</i>';
		var item_id = encodeURIComponent(document.getElementById("item_id").value);
		var x = document.getElementById("ColorA");
		var color_id = encodeURIComponent(x.options[x.selectedIndex].value);
		document.getElementById("Color").value = x.options[x.selectedIndex].text;
		// execute the quickstart.php page from the server
		//alert("record.php?name=" + name + "&focusvar=" + focusvar);
		//document.getElementById("divMessage").innerHTML = '<i>' + "Opening Connection..." + '</i>';
		xmlHttp.open("GET", "ajax_getsizes.php?colorid=" + color_id + "&itemid=" + item_id, true);
		// define the method to handle server responses
		xmlHttp.onreadystatechange = handleServerResponse;
		// make the server request
		xmlHttp.send(null);
		document.getElementById("submit").disabled = false;
	} else {
		// if the connection is busy, try again after one second
		setTimeout('ChangeSizes()', 1000);
	}
// executed automatically when a message is received from the server
}
function handleServerResponse(){
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4){
	// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200){
			
			helloMessage = xmlHttp.responseText;
			document.getElementById("sizebox").innerHTML = '<i>' + helloMessage + '</i>';
		// a HTTP status different than 200 signals an error
		} else {
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}



function StoreGraphic(pagepop){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		//document.getElementById(filldiv).innerHTML = '<i>loading...</i>';
		xmlHttp.open("GET", pagepop, true);
		xmlHttp.onreadystatechange = handleStandard;
		xmlHttp.send(null);
		if(pagepop == 'pop_slideshow.php'){
			auto();
		}
	} else {
		setTimeout('StoreGraphic(pagepop)', 1000);
	}
}
function handleStandard(filldiv){
	if (xmlHttp.readyState == 4){
		if (xmlHttp.status == 200){
			helloMessage = xmlHttp.responseText;
			document.getElementById('store_large').innerHTML = helloMessage;
			document.getElementById('store_large').style.visibility = 'visible';
		} else {
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}

function setflashtotext(){
	document.getElementById('flashcontent').innerHTML = 'Bodylove is more than a brand of clothing. Bodylove is a new way of thinking. Through beautifully crafted Bodylove t-shirts, you can find your inner and outer beauty.  Each t-shirt infuses healing and empowering mantras to nurture the heart and soul of every body.<br><br>To be free. To live fully. To love ourselves and our bodies. To know our passions. To Bodylove.';
	document.getElementById('footerflash').innerHTML = '<p class="text_01">Divine Sizing: Scrumptious | Marvelous | Luscious | Extra Luscious</p>';
}
function setflashtoflash(){
	var so = new SWFObject("media/swf/bodylove2.swf", "mymovie", "459", "393", "8", "#336699");
   so.write("flashcontent");
   var fo = new SWFObject("media/swf/scrollsize.swf", "mymovie", "700", "125", "8", "#ffffff");
   fo.write("footerflash");
}
function clearBLpopup(){
	document.getElementById('store_large').innerHTML = '';
	document.getElementById('store_large').style.visibility = 'hidden';	
}

function MailingListPOST(){
// proceed only if the xmlHttp object isn't busy
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		//document.getElementById("sizebox").innerHTML = '<i>loading...</i>';
		var first_name = encodeURIComponent(document.getElementById("first_name").value);
		var last_name = encodeURIComponent(document.getElementById("last_name").value);
		var gender = encodeURIComponent(document.getElementById("gender").value);
		var email = encodeURIComponent(document.getElementById("email").value);
		var parameters = "first_name=" + first_name + "&last_name=" + last_name + "&gender=" + gender + "&email=" + email;
		// execute the quickstart.php page from the server
		//alert("record.php?name=" + name + "&focusvar=" + focusvar);
		//document.getElementById("divMessage").innerHTML = '<i>' + "Opening Connection..." + '</i>';
		xmlHttp.open("POST", "pop_mailinglist_final.php", true);
		xmlHttp.onreadystatechange = handleMLPResponse;
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", parameters.length);
        xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	} else {
		// if the connection is busy, try again after one second
		setTimeout('MailingListPOST()', 1000);
	}
// executed automatically when a message is received from the server
}
function handleMLPResponse(){
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4){
	// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200){
			
			helloMessage = xmlHttp.responseText;
			document.getElementById("store_large").innerHTML = helloMessage;
		// a HTTP status different than 200 signals an error
		} else {
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}



function TellAFriendPOST(){
// proceed only if the xmlHttp object isn't busy
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		//document.getElementById("sizebox").innerHTML = '<i>loading...</i>';
		var friend_name = encodeURIComponent(document.getElementById("friend_name").value);
		var your_name = encodeURIComponent(document.getElementById("your_name").value);
		if(friend_name == '' || your_name == ''){
			alert('Please fill out all fields!');
			return 0;
		}
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
		if(!document.getElementById("your_email").value.match(re)){
			alert('Your email address is in an invalid format!');
			return 0;
		}
		if(!document.getElementById("friend_email").value.match(re)){
			alert('Your friend\'s email address is in an invalid format!');
			return 0;
		}
		var your_email = encodeURIComponent(document.getElementById("your_email").value);
		var friend_email = encodeURIComponent(document.getElementById("friend_email").value);
		var parameters = "your_name=" + your_name + "&friend_name=" + friend_name + "&your_email=" + your_email + "&friend_email=" + friend_email;
		// execute the quickstart.php page from the server
		//alert("record.php?name=" + name + "&focusvar=" + focusvar);
		//document.getElementById("divMessage").innerHTML = '<i>' + "Opening Connection..." + '</i>';
		xmlHttp.open("POST", "pop_tellafriend_final.php", true);
		xmlHttp.onreadystatechange = handleTAFPResponse;
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", parameters.length);
        xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	} else {
		// if the connection is busy, try again after one second
		setTimeout('TellAFriendPOST()', 1000);
	}
// executed automatically when a message is received from the server
}
function handleTAFPResponse(){
	// move forward only if the transaction has completed
	if (xmlHttp.readyState == 4){
	// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200){
			
			helloMessage = xmlHttp.responseText;
			document.getElementById("store_large").innerHTML = helloMessage;
		// a HTTP status different than 200 signals an error
		} else {
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}