var xmlHttp = false;

function postIForm(form_id, form_action)
{
	f = document.getElementById(form_id);
	if( f )
	{
		var rDiv = document.createElement('div');
		rDiv.id = 'remotingDiv';
		rDiv.innerHTML = '<iframe style="display:none;" name="formtarget"></iframe>';
		document.body.appendChild(rDiv);
		f.action = form_action;
		f.target = 'formtarget';
		f.submit();
	}
	else
	{
		alert('Could not locate form');
	}
}

function addToCard(product)
{
	xmlHttp=GetXmlHttpObject("text")
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=URL_BASE+"/index.php"
	url=url+"?op=addToCard"
	url=url+"&prod="+product
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=replyAddToCard
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function replyAddToCard()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.status == 200)
		{
			window.location.href=URL_BASE+"/index.php?op=viewCard";
		}
	}
}

function debug()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.status == 200)
		{	alert(xmlHttp.responseText);
		}
		else
		{	alert(xmlHttp.status);
		}
	}
}

function getXML(xmlHttp)
{
	var xmlDoc = null;
	if (document.implementation && document.implementation.createDocument)
	{	xmlDoc = xmlHttp.responseXML;
	}	
	else if (window.ActiveXObject)
	{
		var testandoAppend = document.createElement('xml');
		testandoAppend.setAttribute('innerHTML',xmlHttp.responseText);
		testandoAppend.setAttribute('id','_formjAjaxRetornoXML');
		document.body.appendChild(testandoAppend);
		document.getElementById('_formjAjaxRetornoXML').innerHTML = xmlHttp.responseText;
		xmlDoc = document.getElementById('_formjAjaxRetornoXML');
		document.body.removeChild(document.getElementById('_formjAjaxRetornoXML'));
	}
	return xmlDoc;
}

function GetXmlHttpObject(object_type)
{ 
object_type = (object_type == null || object_type != "text") ? "xml" : "text";
	
	xmlHttp = false;
	
	if (window.XMLHttpRequest){
		// If IE7, Mozilla, Safari, etc: Use native object
		xmlHttp = new XMLHttpRequest()
	}
	else
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
	 		{
	 			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e2){
				alert("Your browser does not support AJAX");
			}
		}
	}
	
	if (xmlHttp.overrideMimeType && object_type == 'text') 
	{
	  xmlHttp.overrideMimeType('text/plain');
	} 
	else if (xmlHttp.overrideMimeType && object_type == 'xml') 
	{
	  xmlHttp.overrideMimeType('text/xml');
	}

	return xmlHttp;
}


