function newXMLHttpRequest() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		// Create XMLHttpRequest object in non-Microsoft browsers
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// Create XMLHttpRequest via MS ActiveX
		try {
			// Try to create XMLHttpRequest in later versions
			// of Internet Explorer
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			// Failed to create required ActiveXObject
			try {
				// Try version supported by older versions
				// of Internet Explorer
				xmlreq = new
ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				// Unable to create an XMLHttpRequest with
ActiveX
			}
		}
	}
	return xmlreq;
}

function $() {
    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];

        if (typeof element == 'string')
            element = document.getElementById(element);

        if (arguments.length == 1)
            return element;

        elements.push(element);
    }

    return elements;
}

function changeSignOnAndOff(id) {

	var protocol = location.protocol;
	var host = protocol.concat("//").concat(location.host);
	var url = host.concat("/index.php?dispatch=login_page.view");

	xmlhttp = newXMLHttpRequest();
	var element = document.getElementById(id);
	element.innerHTML = '';
	xmlhttp.open("POST",url);
	xmlhttp.onreadystatechange = function() {
        	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			element.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function addCartList(product_id,amount) {
	var product_id_name = "product_data["+product_id+"][product_id]";
	var amount_name = "product_data["+product_id+"][amount]";

	var productIdInputType = document.createElement("input");
	productIdInputType.type = "hidden";
	productIdInputType.name = product_id_name;
	productIdInputType.value = product_id;
    document.process.appendChild(productIdInputType);

	var amountInputType = document.createElement("input");
	amountInputType.type = "hidden";
	amountInputType.name = amount_name;
	amountInputType.value = amount;
    document.process.appendChild(amountInputType);
	document.process.submit();
}

function addCartListArray(p_id1, p_id2, p_id3, p_id4, amount) {

	var p_Array = new Array(p_id1, p_id2, p_id3, p_id4);

	for (i = 0; i < p_Array.length; i++) {

		if (p_Array[i] != '') {
			var product_id_name = "product_data[" + p_Array[i] + "][product_id]";
			var amount_name = "product_data[" + p_Array[i] + "][amount]";
			
			var productIdInputType = document.createElement("input");
			productIdInputType.type = "hidden";
			productIdInputType.name = product_id_name;
			productIdInputType.value = p_Array[i];
		    document.process.appendChild(productIdInputType);
			
			var amountInputType = document.createElement("input");
			amountInputType.type = "hidden";
			amountInputType.name = amount_name;
			amountInputType.value = amount;
			document.process.appendChild(amountInputType);
		}
	}
	document.process.submit();
}


