var vibraWindow = "";
function closeVibraWindow() {
	try {
		vibraWindow.close();
	} catch(e) {}
}

function checkout() {
	closeVibraWindow();
	vibraWindow = window.open("http://www.vibrashop.com/shop.slrp?Status=1","Vibrashop","");
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function addtobasket(refcode) {
	// define the main variable
	var AlbumID = "";
	
	// If was pass an argument through the function, then that
	// is the AlbumID
	
	if (refcode) {
		AlbumID = refcode;
	} else if (document.getElementById("f")) {
		// There is a FORM (id = f)
		radioObj = document.getElementById("f").sizechoice;
		var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked) {
				radioData = radioObj.value;
				newArray = radioData.split("#");
				AlbumID = newArray[0];
			} else {
				AlbumID = "";
			}
		for (var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				radioData = radioObj[i].value;
				newArray = radioData.split("#");
				AlbumID = newArray[0];				
			}
		}
	}
	// We should have our AlbumID by now.
	// Unless the user didn't choose a size.
	if (AlbumID == "") {
		alert("Please choose a size!");
		return false;
	} else {
		// EVERYTHING IS GOOD
		// ADD TO THE BASKET
		closeVibraWindow();
		vibraWindow = window.open("http://www.vibrashop.com/shoppingcard.slrp?AlbumID=" + AlbumID,"Vibrashop","width=300,height=200");
		window.setTimeout("closeVibraWindow()", 1000);
		window.focus();
		
		// SET A COOKIE SO WE KNOW THE BASKET IS NOT EMPTY
		document.cookie ='mewinbasket=true;  path=/'
		
		// SHOW THE 'CHECK OUT' BUTTON
		document.getElementById("checkout").style.display = 'block';
		return false;
	}
}


function updateOption() {
	radioObj = document.getElementById("f").sizechoice;
	var radioLength = radioObj.length;
	for (var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				radioData = radioObj[i].value;
				newArray = radioData.split("#");
				whichOption = newArray[1];				
			}
		}
	//alert (whichOption);
	// HIDE ALL
	for (x=1; x < 12; x++) {
		if (document.getElementById("option" + x)) {
			document.getElementById("option" + x).style.display = "none";
		}
	}
	document.getElementById(whichOption).style.display = "block";
}


function popup(URL) {
	newwindow=window.open(URL,'sizechart','height=300,width=450,top=15,left=15, scrollbars=yes');
	newwindow.focus();
}

function insertFlash(url, w, h, bg) {
	myHTML = ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + w + '" height="' + h + '" align="middle">');
	myHTML += ('<param name="allowScriptAccess" value="sameDomain" />');
	myHTML += ('<param name="movie" value="' + url + '" />');
	myHTML += ('<param name="bgcolor" value="' + bg + '" />');
	myHTML += ('<param name="quality" value="high" />');
	myHTML += ('<embed src="' + url + '" quality="high" bgcolor="' + bg + '" width="' + w + '" height="' + h + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" align="middle"  pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	myHTML += ('</object>');
	document.write(myHTML);
}

// DO STUFF ONLOAD
window.onload=function(){
	showCheckOut = readCookie('mewinbasket');
 	if (showCheckOut == "true") {
		document.getElementById("checkout").style.display = 'block';
	}
}
