function importXML(url,returnFunc)
{
	if (window.XMLHttpRequest)
		{
		xmlDoc = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
			{
			try
				{
				xmlDoc=new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e)
				{
				try
					{
					xmlDoc=new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e)
					{
					alert("I`m sorry you need to be running an up to date browser to continue.");
					return;
					}
				}
			}
			else
			{
			alert('I`m sorry you need to be running an up to date browser to continue.');
			return;
			}

	xmlDoc.onreadystatechange = processRequest;
	xmlDoc.open("GET", url+"&rand="+(Math.random()*3), true); 
	xmlDoc.send(null);

	function processRequest()
		{
		if ((undefined!==window.xmlDoc) && xmlDoc.readyState == 4)
			{
			if (xmlDoc.status == 200)
				{
				if((xmlDoc.responseXML) && xmlDoc.responseXML.firstChild)
					{
					return returnFunc(xmlDoc.responseXML.documentElement);
					}
					else
					{
					return returnFunc(xmlDoc);
					}
				}
				else
				{
				alert ( "I`m sorry there has been a problem processing your request." );
				return;
				}
			}
		return 0;
		}
}

function loadIn_txt(area)
{
	document.getElementById(area).innerHTML = " Loading, please wait...";
}

function loadIn_img(area,img)
{
	document.getElementById(area).innerHTML = "<center><img src=\""+img+"\"> Loading, please wait...</center>";
}

function loadIn(area)
{
	document.getElementById(area).innerHTML = "<center><img src=\"../images/loading.gif\"> Loading, please wait...</center>";
}

function disablethis(area)
{
	area.disabled=true;
}

function enablethis(area)
{
	area.disabled=false;
}

function buildpostlist(fn)
{
	var postOptions = "";
	var formnum = fn || '0';
	for(i=0; i<document.forms[formnum].elements.length; i++)
		{
		if(document.forms[formnum].elements[i].type=="checkbox" || document.forms[formnum].elements[i].type=="radio")
			{
			if(document.forms[formnum].elements[i].name && document.forms[formnum].elements[i].checked == true)
				{
				postOptions += "&"+document.forms[formnum].elements[i].name+"="+document.forms[formnum].elements[i].value;
				}
			}
		else if(document.forms[formnum].elements[i].type=="text" || document.forms[formnum].elements[i].type=="textarea" || document.forms[formnum].elements[i].type=="hidden" || document.forms[formnum].elements[i].type=="submit" || document.forms[formnum].elements[i].type=="password")
			{
			if(document.forms[formnum].elements[i].name && document.forms[formnum].elements[i].value)
				{
				postOptions += "&"+document.forms[formnum].elements[i].name+"="+escape(document.forms[formnum].elements[i].value).replace(/\+/g,"%2B");
				}
			}
		else if(document.forms[formnum].elements[i].type=="select-multiple")
			{
			for(smcount=0;smcount<document.forms[formnum].elements[i].length; smcount++)
				{
				if(document.forms[formnum].elements[i].options[smcount].selected)
					{
					postOptions += "&"+document.forms[formnum].elements[i].options[smcount].name+"="+document.forms[formnum].elements[i].options[smcount].value;
					}
				}
			}
		else if(document.forms[formnum].elements[i].type=="select-one")
			{
			if(document.forms[formnum].elements[i].selectedIndex>=0)
				{
				postOptions += "&"+document.forms[formnum].elements[i].name+"="+document.forms[formnum].elements[i].options[document.forms[formnum].elements[i].selectedIndex].value
				}
			}
		}
	return postOptions;
}

function clearTable(tblid,tblrow)
{
	tblc = tblrow || 0;
	if(document.getElementById(tblid).rows.length>1)
		{
		table_total = document.getElementById(tblid).rows.length;
		for(var row=tblc; row<table_total; row++)
			{
			document.getElementById(tblid).deleteRow(tblc);
			}
		}
}

function _GET(value)
{
	var data = document.location.search;
	var array = data.match(/([a-z0-9]+\=[a-z0-9\_\.\%\-\+\@]+)/gi);
	if(array)
		{
		for(var x in array)
			{
			if(array[x].split('=')[0].toLowerCase() == value.toLowerCase())
				{
				return unescape(array[x].split('=')[1]);
				}
			}
		}
	return 0;
}

function addtocart(items,o,v)
{
	var output = o || null;
	var voucher = v || null;
	function parseCartAdd(data)
	{
	if(data.getElementsByTagName("rcode")[0].childNodes[0].nodeValue==0)
		{
		if((output!=null) && document.getElementById(output))
			{
			document.getElementById(output).innerHTML = '<a href="javascript:;" onClick="window.open(\'cart.php\',\'cart\',\'height=500,width=794,resizable=1,scrollbars=1,toolbar=1,location=1\');">'+unescape(data.getElementsByTagName("resp_desc")[0].childNodes[0].nodeValue).replace(/\+/g," ")+'</a>';
			if(voucher != null)
				{
				importXML('api/?uid='+uid+'&key='+key+'&setmodule=cart&request=voucheradd&code='+voucher,nullthis);
				}
			}
		}
		else
		{
		if((output!=null) && document.getElementById(output))
			{
			document.getElementById(output).innerHTML = unescape(data.getElementsByTagName("resp_desc")[0].childNodes[0].nodeValue).replace(/\+/g," ");
			}
		}
	}

	if(document.getElementById(output))
		{
		loadIn_img(output,'images/loading.gif');
		}

	for(i in items)
		{
		importXML('api/?uid='+uid+'&key='+key+'&setmodule=cart&request=cartaddto&itemid='+items[i]+'&quantity=1',parseCartAdd);
		}
}

function nullthis()
{
	return;
}

function prompt_(pQuestion,pTitle,pCallback,pData)
{
	var _title = pTitle || '';
	var _question = pQuestion || '';
	var _callback = pCallback || '';
	var _data = pData || '';

	var promptWin = window.open ("","myPrompt","status=0,width=100,height=100,resizable=1");
	promptWin.moveTo(100,100);
	prompt_html  = '<html><head>';
	if(_title)
		prompt_html += '<title>'+_title+'</title>';

	prompt_html += '</head>';
	prompt_html += '<style type="text/css">body{font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; width:475px;}';
	prompt_html += 'h1{font-family:Verdana, Arial, Helvetica, sans-serif; font-size: 20px;}</style>';
	prompt_html += '<body id="prompt_body">';
	
	if(_title)
		prompt_html += '<h1 width="85em">'+_title+'</h1>';
	
	prompt_html += '<p width="85em">'+_question+'</p>';
	if(_callback)
		prompt_html += '<p><input type="text" size="60" id="prompt_input"></p>';

	prompt_html += '<div>';
	if(_callback)
		{
		prompt_html += '<input type="button" value="Ok" onClick="opener.parent.'+_callback+'(document.getElementById(\'prompt_input\').value';
		if(_data)
			prompt_html += ','+_data;
		prompt_html += '); window.close();"> <input type="button" value="Cancel" onClick="window.close();">';
		}
		else
		prompt_html += '<input type="button" value="Close" onClick="window.close();">';

	prompt_html += '</div></body></html>';
	promptWin.document.write(prompt_html);
	promptWin.resizeTo(540,400);
}
