﻿// JavaScript Document

// BOI, followed by one or more digits, followed by EOI.
 var reInteger = /^\d+$/
 
//Validation for integer
function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}


// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function getHTTPObject(){
		var ro;
		if (window.XMLHttpRequest)     // Object of the current windows
{ 
       	ro = new XMLHttpRequest();     // Firefox, Safari, ...
} 
else 
if (window.ActiveXObject)   // ActiveX version
{
       ro = new ActiveXObject("Microsoft.XMLHTTP");    // Internet Explorer 
} 
return ro;
}

var http = getHTTPObject(); // We create the HTTP Object

var isWorking = false;
function addToToteBag(id, g_root_path, g_lang,offer)
{
	if (!isInteger(document.getElementById('int_quantity_'+id).value))
	{
		alert('Please enter valid quantity');
	}
	else
	{
		url = g_root_path + "_navi_shopping_cart.cfm?lang=" + g_lang + "&action=addtocart&no="+Math.random() +"&int_product_id=" + id + "&int_quantity=" +document.getElementById('int_quantity_'+id).value+"&specialoffer=" +offer;		
		if (!isWorking && http ) 
		{
			http.open("GET", url, true);
			http.onreadystatechange = handleObjectiveResponse;
			isWorking = true;
			http.send(null);
		}
	}
	return false;
}

function handleObjectiveResponse() {

	if (http.readyState == 4) 
	{
		// Use the XML DOM to unpack the data 
		txtDocument = http.responseText; 
		var content;
		content = txtDocument.replace('<META NAME="ColdFusionMXEdition" CONTENT="ColdFusion DevNet Edition - Not for Production Use.">','');
		//document.getElementById("success").innerHTML = 'カートに入れました';
		document.getElementById("navi-cart").innerHTML = content;
		
		isWorking = false;
	}
}