
/*
note to peekers:
these methods require htaccess tricks and server-side parsing.
*/
// NAVIGATION
var z = 0;
function swapPage(thismain,thissub,thisdiv,thisprev,thisnext) {
//alert(thismain+' - '+thissub);
	if (thissub)
		RedirectLocation(thismain+'_'+thissub);
	else
		RedirectLocation(thismain);
		thisProduct = thissub;
		z = 1;
		if (thismain != 'product') {
			document.getElementById('previous').innerHTML='&nbsp;';
			document.getElementById('next').innerHTML='&nbsp;';
		}
	//alert(url+'/ajax_body.cgi?main='+thismain+'&sub='+thissub+' - '+thisdiv+' - '+thismain+' - '+thissub);
	getFile(url+'/ajax_body.cgi?main='+thismain+'&sub='+thissub,thisdiv,thismain,thissub);
}
function swapGal(thismain,thissub,thisStart,thisdiv) {
	RedirectLocation(thismain+'_'+thissub+'_'+thisStart);
	getFile(url+'/ajax_body.cgi?main='+thismain+'&sub='+thissub+'&start='+thisStart,thisdiv);
}
function swapDetail(sub,detail) {
	document.getElementById('big_image').src = 'http://www.blossompod.com/blossomp3/IMAGES/' + detail + '_b.jpg';
	getFile(url+'/ajax_details.cgi?sub='+sub+'&detail='+detail,'details');
}

// AJAX
var xmlhttp = '';
var async = false;
function getFile(pURL,thisDiv,thismain,thissub) {
	whichDiv = thisDiv;
	whichUrl = pURL;
	xmlhttp = getHTTPObject();
	if (xmlhttp) {
		xmlhttp.open("GET", pURL, async);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200) {
					if (thismain == 'product') {
						if ((whichDiv == 'eval')&&(thissub != '')) {
							eval(xmlhttp.responseText);
						} else {
							document.getElementById(whichDiv).innerHTML=xmlhttp.responseText;
							if (z == 1) {
								getFile(url+'/ajax_nav.cgi?sub='+thissub,'eval',thismain,thissub);
								z += 1;
							}
						}
					} else if (thisDiv == 'details') {
						eval(xmlhttp.responseText);
					} else {					
						document.getElementById(whichDiv).innerHTML=xmlhttp.responseText; //.replace(/[\r\n]/g,'')
					}
				}
			}
		}
		xmlhttp.send(null);
	}
}
function getHTTPObject() {
	xmlhttp = false;
	if(window.XMLHttpRequest) {
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}
		async = true;
		xmlhttp = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlhttp = false;
			}
		}
	} else if (window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

// BACK/FORWARD BUTTON
function CheckForHash() {
	if (document.location.hash != thisPage) {
		var HashLocationName = document.location.hash;
		if (HashLocationName != ('#'+thisPage)) {
			HashLocationName = HashLocationName.replace("#","");
			var pageArray = HashLocationName.split('_');
			if (whichUrl) {
				getFile(url+'/ajax_body.cgi?main='+pageArray[0]+'&sub='+pageArray[1]+'&start='+pageArray[2],'mainDiv',pageArray[0],pageArray[1]);
			}
			thisPage = HashLocationName;
		}
	}
}

// CONTACT FORM
function contactForm() {
	var async = true;
	with (document.contactform) {
		var contactUrl = url+'/contact.cgi?name='+name.value+'&email='+email.value+'&message='+message.value;
	}
	xmlhttp = getHTTPObject();
	if (xmlhttp) {
		xmlhttp.open("GET", contactUrl, async);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					if (xmlhttp.responseText) {
						if ((xmlhttp.responseText == 'n')||(xmlhttp.responseText == 'e')||(xmlhttp.responseText == 'm')) {
							document.getElementById('n').style.backgroundColor='#e1e1e1';
							document.getElementById('e').style.backgroundColor='#e1e1e1';
							document.getElementById('m').style.backgroundColor='#e1e1e1';
							document.getElementById(xmlhttp.responseText).focus();
							document.getElementById(xmlhttp.responseText).style.backgroundColor='#ffff99';
							document.getElementById('confirm').innerHTML = '<font color="#FF0033">All fields are required!!!</font>';
						} else {
							with (document.contactform) {
								name.value = ''; email.value = ''; message.value = '';
							}
							document.getElementById('confirm').innerHTML = 'Message received!!! Thank you.';
						}
					} else {
						alert("Submission Error!! [1]");
					}
				} else {
					alert("Submission Error!! [2]");
				}
			} 
		}		
		xmlhttp.send(null);
	}
}
