// JavaScript Document

var xmlHttp;

function load_totaltemplate(str,limitstart)
{
	document.getElementById('content').innerHTML='<div style="clear:both; padding:310px 0px 0px 0px; height:306px;" align="center"><img src="images/ajax-loader.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="inc/ajaxfunctions.php";
	url=url+"?page=load_total_template&limitstart="+limitstart;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("content").innerHTML=xmlHttp.responseText;
	} 
}
	
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function loadtemplate_bycat(catid,limitstart)
{
	document.getElementById('content').innerHTML='<div style="clear:both; padding:310px 0px 0px 0px; height:306px;" align="center"><img src="images/ajax-loader.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="inc/ajaxfunctions.php";
	url=url+"?page=load_template_bycat&catid="+catid+"&limitstart="+limitstart;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function load_full_template(id,frompage,limitstart,catid)
{
	document.getElementById('content').innerHTML='<div style="clear:both; padding:310px 0px 0px 0px; height:306px;" align="center"><img src="images/ajax-loader.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="inc/ajaxfunctions.php";
	url=url+"?page=load_full_template&id="+id+"&frompage="+frompage+"&limitstart="+limitstart+"&catid="+catid;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function addtocart(productname,cost,tmpid)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="inc/ajaxfunctions.php";
	url=url+"?page=addcart&productname="+productname+"&cost="+cost+"&cost_type=1&tmpid="+tmpid;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		alert("Template added to cart successfully");
		document.getElementById('cart1').innerHTML=xmlHttp.responseText;
		
		show_carttotal();
	} 
}

function addtocart1(productname,cost,tmpid)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="inc/ajaxfunctions.php";
	url=url+"?page=addcart&productname="+productname+"&cost="+cost+"&cost_type=2&tmpid="+tmpid;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		alert("Template added to cart successfully");
		document.getElementById('cart2').innerHTML=xmlHttp.responseText;
		
		show_carttotal();
	} 
}

function show_carttotal()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="inc/ajaxfunctions.php";
	url=url+"?page=show_carttotal";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById('total_cartitem').innerHTML=xmlHttp.responseText;
	} 
}

