var sld = 0;
var path = new Array();

// LIST OF SLIDES
path[0] = "images/store_slides.jpg";
path[1] = "images/store_slides_bedding.jpg";
path[2] = "images/store_slides_bathrobe.jpg";
path[3] = "images/store_slides_towels.jpg";
path[4] = "images/store_slides_lather.jpg";
path[5] = "images/store_slides_access.jpg";
path[6] = "images/store_slides_sink.jpg";
path[7] = "images/store_slides_shea.jpg";

function swapImage()
{
   var ss = document.getElementById('slideshow');
   ss.src = path[sld];
   sld++;
   if(sld >= path.length)
     sld = 0;
   setTimeout("swapImage()",1500);
}

function sendContact(id)
{
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var parameters='name=' + name + '&' + 'email=' + email;
	postRequest('mail_list.php', parameters, emailDone, id)
	
//		$check_mail = mail($hold_email[$x], $email_subject,$email_body, $headers);
}

function fillFromForm(fo)
{
	var i;
	var getstr = '';
	var E = fo.getElementsByTagName("input");		// Elements
	var S = fo.getElementsByTagName("select");		// Random selects
	var T = fo.getElementsByTagName("textarea");	// Textareas
//	window.alert("Elements " + E.length + " Text " + T.length);
	for (i=0; i < S.length; i++)
	{
		var el = S[i].name + "=" + S[i].options[S[i].selectedIndex].value + "&";
		getstr += el;
	}
	for (i=0; i < E.length; i++) 
	{
		if (E[i].type == "text") 
			getstr += E[i].name + "=" + E[i].value + "&";
			
		else if (E[i].type == "checkbox") 
		{
			if (E[i].checked) 
				getstr += E[i].name + "=" + E[i].value + "&";
			else 
				getstr += E[i].name + "=&";
		}
		else if (E[i].type == "radio") 
		{
			if (E[i].checked) 
				getstr += E.name + "=" + E[i].value + "&";
		}
		else if(E[i].type == "hidden")
			getstr += E[i].name + "=" + E[i].value + "&";
	}
	// Textareas
	for (i=0; i < T.length; i++) 
	{
		getstr += T[i].name + "=" + T[i].value + "&";
	}
	return getstr;
}

function createXMLHttpRequest() 
{
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }

function postRequest(url, parameters, action, id)
{
	var http_request = createXMLHttpRequest();
	if(!http_request)
		window.alert("Could not createXMLHttpRequest");
	http_request.onreadystatechange = function() {requestDone(http_request, action, id);}
//	window.alert("Filling Models 2" + url + " " + parameters);
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	var answer = http_request.send(parameters);
//	window.alert('send: ' + answer);
}

function getRequest(url, parameters, action, id) 
{
	var http_request = createXMLHttpRequest();
	if (!http_request) 
		window.alert('Cannot create XMLHTTP instance');
	else
	{
		http_request.onreadystatechange = function() {requestDone(http_request, action, id);}
		http_request.open('GET', url + '?' + parameters, true);
		var answer = http_request.send('');
//		window.alert('send: ' + answer);
	}
}

function requestDone(hreq, action, id)
{
//	window.alert(hreq.status + ',' + hreq.responseText + ',' + hreq.readyState);
//	window.alert(hreq.readyState + 'requestDone' + hreq + ' ' + action + ' ' + id);
	if (hreq.readyState == 4) 
	{
		if (hreq.status == 200)
		{
//			window.alert('success!');
			action(hreq.responseText, id);
		}
		else 
			alert('There was a problem with the request: ' + hreq.status + hreq.responseText);
	}
}

function showError(msg)
{
	document.getElementById('error_msg').innerHTML = msg;
}

function emailDone(response, id)
{
	document.getElementById(id).innerHTML = "<div class='form_cover2'><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thank you for adding your<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name to our mailing list.</div>";
}