// JavaScript Document

$(document).ready(function() {
	$("[id^='attrib']").change(function() {getServerText()});				   
});

function getServerText() {
	var myurl = 'js/ajax.php';
	myRand = parseInt(Math.random()*99999999999999);
	var x = 0;
	var props = "";
	var attribute = "";
	var attribute1 = "";
	var attribute2 = "";
	var attribute3 = "";
	var attribute4 = "";
	var attribute5 = "";
	var attribute6 = "";
	var total_length = 0;
	var exists = eval(Boolean(document.cart_quantity));
	if (exists) {
		products_id = document.cart_quantity.products_id.value;
		
			
		if (eval(Boolean(document.getElementById('attrib-1-1')))) {
		var attribute = "&attribute="+document.getElementById('attrib-1-1').value;
		total_length += 1;
		}		
		if (eval(Boolean(document.getElementById('attrib-1')))) {
			var attribute1 = "&attribute1="+document.getElementById('attrib-1').value;
			total_length += 1;
		}
		if (eval(Boolean(document.getElementById('attrib-2')))) {
			var attribute2 = "&attribute2="+document.getElementById('attrib-2').value;
			total_length += 1;
		}
		if (eval(Boolean(document.getElementById('attrib-3')))) {
			var attribute3 = "&attribute3="+document.getElementById('attrib-3').value;
			total_length += 1;
		}
		if (eval(Boolean(document.getElementById('attrib-4')))) {
			var attribute4 = "&attribute4="+document.getElementById('attrib-4').value;
			total_length += 1;
		}
		if (eval(Boolean(document.getElementById('attrib-5')))) {
			var attribute5 = "&attribute5="+document.getElementById('attrib-5').value;
			total_length += 1;
		}
		if (eval(Boolean(document.getElementById('attrib-6')))) {
			var attribute6 = "&attribute6="+document.getElementById('attrib-6').value;
			total_length += 1;
		}
		
		
		var modurl = myurl+"?rand="+myRand+"&products_id="+products_id+attribute+attribute1+attribute2+attribute3+attribute4+attribute5+attribute6;
		modurl += "&length="+total_length;
		$('#myPageElement').html("Updating..."); 
		$.post(
			 modurl,
			 function(data) {
				$('#myPageElement').html(data); 
			 }
		);
		
	}
	
}


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=550,left = 246,top = 100');");
}

			function PopupPic(sPicURL) { 
				window.open("popup.htm?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");
			}
		
