function createRequestObject()
{
	var xmlhttp = false;
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
 	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		}
		catch (E)
		{
			xmlhttp = false;
		}
 	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}




//------------- display product details on  cart.php --------------//
var items;
function populatePrdetails(prid)
{

/* Clearing the contents of the bookDetailsPanel DIV */
	document.getElementById('cartprdetails').innerHTML = '';
/* Only if the authorName holds a value */
	if(prid)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=prdetails&prid=" + prid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				response = request.responseText;
			/* Populating the DIV with the response received */
				document.getElementById('cartprdetails').innerHTML = response;
       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('cartprdetails').innerHTML = '';


}

/* --------------------------------------------------------- */



function populatewishlist(prid)
{


/* Clearing the contents of the bookDetailsPanel DIV */
	document.getElementById('wishdetails').innerHTML = '';
/* Only if the authorName holds a value */
	if(prid)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=wishdetails&wid=" + prid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				dt = request.responseText;
                dt=dt.split("|||");
				response =dt[0];
            	items=Number(dt[1]);
			/* Populating the DIV with the response received */
				document.getElementById('wishdetails').innerHTML = response;
       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('wishdetails').innerHTML = '';


}

function populatestdkit(prid)
{

	purchid=prid.split("::");

/* Clearing the contents of the bookDetailsPanel DIV */
	document.getElementById('cartprdetails').innerHTML = '';
/* Only if the authorName holds a value */
	if(purchid[0])
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

		if(purchid[1]=="")pdid="&op=sdetails&sdid=" + purchid[0];else pdid="&op=sdetailspurchase&sdid=" + purchid[0]+"&purchaseid="+purchid[1];
	/* Opening a request */

		request.open("GET", "process.php?process=ajaxcontent"+pdid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				dt = request.responseText;
                dt=dt.split("|||");
				response =dt[0];

            	items=Number(dt[1]);
			/* Populating the DIV with the response received */
				document.getElementById('cartprdetails').innerHTML = response;
       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('cartprdetails').innerHTML = '';


}


function populatemodiedkit(prid){

/* Clearing the contents of the bookDetailsPanel DIV */
	document.getElementById('cartprdetails').innerHTML = '';
/* Only if the authorName holds a value */
	if(prid)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=modified&mid=" + prid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				dt = request.responseText;
                dt=dt.split("|");
				response =dt[0];
            	items=Number(dt[1]);
			/* Populating the DIV with the response received */
				document.getElementById('cartprdetails').innerHTML = response;
       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('cartprdetails').innerHTML = '';



}


	//---------- funciton for set numerical value in two place after decimal ------//

    function setPricedecimalAj(priceval){

        priceval=Number(priceval).toFixed(2);

        return priceval;

    }

    //----------------------------------------------------------------------------//



//--------function to change the price of the product and the total sum of the kits product------//

function changeprice(qty,unitprice,index,discount){
//alert("quantity="+qty+",unitprice="+unitprice+",index="+index+",descount="+discount);

	q=qty.split("=");
	quantity=Number(q[0]);
	//alert(q[0]+" ,"+q[1]);
	ref=eval("document.getElementById('price_"+index+"')");
	//alert(ref.value);
	var price=parseFloat(quantity*Number(unitprice));
	//alert(price);
	var totprice = parseFloat(price - (price * (discount/100)));
	ref.value=setPricedecimalAj(totprice);
	sum=0;

    for(i=1;i<items+1;i++){
		//myref=eval("document.price.price_"+i);
 		myref=eval("document.getElementById('price_"+i+"')");

 		sum+=Number(myref.value);

	}

	//document.price.total.value=sum;
	document.getElementById('tprice').value=setPricedecimalAj(sum);

}



	//---------------- change / modify price in modify kit ----------//

	function chgprbyselModifiyKit(sizeval,quantityval,priceindex){

    	var sizedt="";
        sizedt=sizeval.split(":::");
        eval("document.getElementById('saleprice_"+sizedt[2]+"')").value=sizedt[0];
        if(Number(sizedt[3].length)>7){
        	var prdt1=sizedt[3].split("::");
        	document.getElementById(prdt1[0]+'_'+sizedt[2]).src=prdt1[1];
        }
        changeprice(quantityval,sizedt[0],priceindex,0);


    }

    //---------------------------------------------------------------//


/* function for display credit card form on checkout page*/


function showccdiv(paytype)
{

	document.getElementById('ccdetails').innerHTML = '';
/* Only if the authorName holds a value */


	if(paytype)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=showccdiv&paytype=" + paytype);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				response = request.responseText;
			/* Populating the DIV with the response received */
				document.getElementById('ccdetails').innerHTML = response;

				//alert(response);

       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('ccdetails').innerHTML = '';


}

/* ------------------------------------------------------------*/






/* ----------------- display order product on click ORDER ID -------------- */

function dispOrdPr(ordid)
{

	document.getElementById('disorddt').innerHTML = '';
/* Only if the authorName holds a value */


	if(ordid)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=showordpr&ordid=" + ordid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				response = request.responseText;
			/* Populating the DIV with the response received */
				document.getElementById('disorddt').innerHTML = response;

				//alert(response);

       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('disorddt').innerHTML = '';


}

/* --------------------------------------------------------------------------- */










/* ----------------- display order product clicking on single product or kit -------------- */

function dispOrdPrDtbyPurchase(prchid)
{

	document.getElementById('dispordDtProduct').innerHTML = '';
/* Only if the authorName holds a value */


	if(prchid)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=showordPurc&prchid=" + prchid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				response = request.responseText;
			/* Populating the DIV with the response received */
				document.getElementById('dispordDtProduct').innerHTML = response;

				//alert(prchid);

       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('dispordDtProduct').innerHTML = '';


}

/* --------------------------------------------------------------------------- */





//function to change the price of the product and the total sum of the kits product//

function changepricekit(qty,unitprice,index,discount){

q=qty.split("=");
quantity=Number(q[0]);
//alert("quantity="+quantity+",unitprice="+unitprice+",index="+index+",discoutn="+discount);
ref=eval("document.getElementById('price_"+index+"')");
//alert(items);
var price=parseFloat(quantity*Number(unitprice));
//alert(price);
var totprice = parseFloat(price - (price * (discount/100)));
ref.value=setPricedecimalAj(totprice);
sum=0;
for(i=1;i<items+1;i++){
 myref=eval("document.getElementById('price_"+i+"')");
 sum+=Number(myref.value);
}
//document.patternlist.total.value=sum;
document.getElementById('tprice').value=setPricedecimalAj(sum);
}


//function to change the price while selecting the replacement product//
function swapid(qty,qty1,unitprice,discount,unitprice1,discount1,index,mybool){
//alert("quantity="+qty+"quantity1="+qty1+",unitprice="+unitprice+",discount="+discount+",unitprice1="+unitprice1+",discount1="+discount1+",index="+index+",mybool="+mybool);

val=qty1.split("=");

myval=qty.split("=");



if(mybool=="true" || mybool==true){
		myref=eval("document.getElementById('quantity1_"+myval[1]+"')");

		ref=eval("document.getElementById('quantity_"+val[1]+"')");

        myref.disabled=false;
		ref.disabled=true;

		changepricekit(qty,unitprice,index,discount);

}
else if(mybool=="false" || mybool==false){


		if(myval[1]==null)return true;

		ref=eval("document.getElementById('quantity_"+val[1]+"')");

		ref.disabled=false;

	 	changepricekit(qty1,unitprice1,index,discount1);
}





}


function chkHideUn(quantval,chk){


	chkhide=eval("document.getElementById('"+quantval+"')");

	if(chk==true){
		chkhide.disabled=false;
        toggleBoxProd('repproddiv',1);
	}else{
		chkhide.disabled=true;
	}

}



//------------ function run on size dropdown ----------//

	function setproductsize(prsize,index,sizetype){

    	var prdt="";
        prdt=prsize.split(":::");
        
        

        if(Number(sizetype)==0){

            eval("document.getElementById('unitprice_"+prdt[2]+"')").value=prdt[0];

        	changeprice(eval("document.getElementById('quantity_"+prdt[2]+"')").value,prdt[0],index,'0');

        }

        if(Number(sizetype)==1){

            eval("document.getElementById('unitprice1_"+prdt[2]+"')").value=prdt[0];

        	changeprice(eval("document.getElementById('quantity1_"+prdt[2]+"')").value,prdt[0],index,'0');

        }
        
        if(Number(prdt[3].length)>7){
        	var prdt1=prdt[3].split("::");
        	document.getElementById(prdt1[0]+'_'+prdt[2]).src=prdt1[1];
        	document.getElementById(prdt1[0]+'1_'+prdt[2]).src=prdt1[1];
        }



    }





//--------------------------- function for check coupon validity -----------------------//

function chkvalidCpn(prid)
{

/* Clearing the contents of the bookDetailsPanel DIV */
	document.getElementById('cpnvalidstatus').innerHTML = '';
/* Only if the authorName holds a value */
	if(prid)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=cpnvalid&cpnval=" + prid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				dt = request.responseText;
                dt=dt.split("|||");
				response =dt[0];
            	items=Number(dt[1]);
			/* Populating the DIV with the response received */
				document.getElementById('cpnvalidstatus').innerHTML = response;
				document.frmstep2.couponcode.value="";
       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		alert("Please Fill Coupon Code.");


}

//------------------------------------------------------------------------------------------//

function changestandardproduct(prid)
{

/* Clearing the contents of the bookDetailsPanel DIV */
	document.getElementById('cartprdetails').innerHTML = '';
/* Only if the authorName holds a value */
	if(prid)
    {
	/* Setup an XMLHttpRequest*/
	    var request = createRequestObject();

	/* Opening a request */
		request.open("GET", "process.php?process=ajaxcontent&op=changestdkit&sdid=" + prid);

	/* Defining an event handler.*/
		request.onreadystatechange = function()
		{
   			if(request.readyState == 4)
	       	{
			/* Holding the response received in a memory variable */
				dt = request.responseText;
                dt=dt.split("|||");
				response =dt[0];
            	items=Number(dt[1]);
			/* Populating the DIV with the response received */
				document.getElementById('cartprdetails').innerHTML = response;
       		}
	   	};

	/* Sending the asynchronous request. */
		request.send(null);
	}
	else
	/* Clearing the contents of the bookNamePanel DIV */
		document.getElementById('cartprdetails').innerHTML = '';


}

function toggleBoxProd(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}