// JavaScript Document

/////////////////////////////////////////////////////////////////////////////////////////////////

var ImageSpanId;

function deleteImage(tbl,colname,imageid,toempty,spanId){

	ImageSpanId = spanId;

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/php_functions.php",delImgResp,"cmd=dimg&tbl="+tbl+"&colname="+colname+"&imgid="+imageid+"&toempty="+toempty+"&spanId="+spanId); 

	document.getElementById(ImageSpanId).innerHTML = "deleting...";

}

function delImgResp(){

	if(httpRequest.readyState == 4){

		//alert(httpRequest.responseText);

		document.getElementById(ImageSpanId).innerHTML = httpRequest.responseText;

	}

}

///////////////////////////////////////////////////////////////////////////////////////////////

var result = false;

var img = new Image;

var img2 = new Image;



img.src = root+"admin/images/waits2.gif"

img2.src = root+"admin/images/plswait.gif"



/************************************************************************************/

function checkProductCode(val,product_id){

	document.getElementById('pcode_span').innerHTML = '<img src = "'+root+'admin/images/waits2.gif">';

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/php_functions.php",displayProductCode,"cmd=chk_pcode&code="+val+"&product_id="+product_id); 

}



function displayProductCode(){

	if(httpRequest.readyState == 4){

		if(httpRequest.responseText == "true"){

			document.getElementById('pcode_span').innerHTML = "<span class=\"success\">Product code available</span>";

			result = true;

		}else{

			document.getElementById('pcode_span').innerHTML = '<span class="error">'+httpRequest.responseText+'</span>';

			result = false;

		}

	}

}

var PRODUCT_NAME_CORRECT = false;

function checkProductName(val,product_id){

	document.getElementById('pname_span').innerHTML = '<img src = "'+root+'admin/images/waits2.gif">';

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/php_functions.php",displayProductName,"cmd=chk_pname&name="+val+"&product_id="+product_id); 

}



function displayProductName(){

	if(httpRequest.readyState == 4){

		if(httpRequest.responseText == "true"){

			document.getElementById('pname_span').innerHTML = "<span class=\"success\">Product name available</span>";

			PRODUCT_NAME_CORRECT = true;

		}else{

			document.getElementById('pname_span').innerHTML = '<span class="error">'+httpRequest.responseText+'</span>';

			PRODUCT_NAME_CORRECT = false;

		}

	}

}

/****************************************************************************************************/

//if edit is on the parent id is now attribute id

var TO_REFRESH;

function addNewAttribute(parent_id,edit,ct_id){
	TO_REFRESH = ct_id;
	var strTitle = "Add New Attribute";
	var firstHeading = 'Add Attribute';
	var buttonVal = "Add";

	var prnt = document.getElementById("new_attribute_div");
	//hide any message that has been displayed before i.e: add an attribute first
	var elm = document.getElementById("att_msg");
	if(elm) elm.style.display = "none";

	if(edit){
		if(!parent_id){ alert("Please select an attribute to edit or add values first"); return false;}
		strTitle = "Edit Attribute";
		firstHeading = 'Edit Attribute';
		buttonVal = 'Update';
		getAttributeDetails(parent_id,strTitle,firstHeading,buttonVal,ct_id);
	}else{
		prnt.innerHTML = returnPanelStr(parent_id,strTitle,firstHeading,buttonVal);

	}

	prnt.style.display="block";

}



function returnPanelStr(parent_id,strTitle,firstHeading,buttonVal,xml,ct_id){

	if(xml){

		var rootnode = xml.getElementsByTagName('response').item(0);

		//alert(xml.getElementsByTagName("attribute_value")[0].firstChild.data)

		var items = rootnode.getElementsByTagName("attribute");

		if(!items[0]){alert("Please add attribute values first");removeNewAttributeFrame(); return false;}

		var attribute_name = items[0].getAttribute("name");

		var attrib_id =  items[0].getAttribute("id");

		var item;

		var a_value;

		var a_id;

		var a_order;

		

	}

	var str = '<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" id="mainTbl"><tr><td align="center" class="headingblue"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="background-color:#ffffff;" colspan="4" align"right"><div style="float:left"><div style="float:left">'+strTitle+'</div><div align="right" style="float:right;"><a href="javascript:void(0);" onClick="removeNewAttributeFrame()"><img src="'+root+'admin/images/close.jpg" border="0" /></a></div></td></tr><tr><td colspan="4" align="left" class="headTD">'+firstHeading+'</td></tr><tr><td align="left" class="txtBodyBold" colspan="2">Attribute Name:</td><td colspan="2" align="left" class="txtBodyBold"><input type="text" name="attribute_name" id="attribute_name" value="'+(attribute_name?attribute_name:'')+'" /></td></tr><tr><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td></tr><tr><td colspan="4" align="left" class="tdBlueBg">Attribute Values</td></tr>';

	if(xml){

		for (var i = 0 ; i < items.length ; i++) {

			// get one item after another

			 item = items[i];

			// now we have the item object, time to get the contents

			// get the name of the item

			 a_value = item.getElementsByTagName("attribute_value")[0].firstChild.nodeValue;

			 a_id = item.getElementsByTagName("attribute_value_id")[0].firstChild.nodeValue;

			 a_order = item.getElementsByTagName("attribute_value_order")[0].firstChild.nodeValue;

			// get the quantity

			str += '<tr><td align="left" class="txtBodyBold" width="24%">Value '+(i+1)+'</td><td align="left" class="txtBodyBold" width="22%"><input type="text" name="attribute_value'+i+'" id="attribute_value'+i+'" value="'+a_value+'" /></td><td align="left" class="txtBodyBold" width="9%">Order</td><td align="left" class="txtBodyBold" width="45%"><input type="text" name="attribute_order'+i+'" id="attribute_order'+i+'" value="'+a_order+'" /><a href="javascript:void();" onclick="deleteAttributeValues('+a_id+',\''+ct_id+'\')" ><img src="'+root+'admin/images/delete.jpg" border="0"></a><input type="hidden" name="attribute_value_id_'+i+'" name="attribute_value_id_'+i+'" value="'+a_id+'" ></td></tr>';

		}

	}else{

		for(var i=1; i<=5; i++){

		str += '<tr><td align="left" class="txtBodyBold" width="24%">Value '+i+'</td><td align="left" class="txtBodyBold" width="22%"><input type="text" name="attribute_value'+i+'" id="attribute_value'+i+'" /></td><td align="left" class="txtBodyBold" width="9%">Order</td><td align="left" class="txtBodyBold" width="45%"><input type="text" name="attribute_order'+i+'" id="attribute_order'+i+'" value="'+i+'" /></td></tr>';

		}

	}

	str += '<tr><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td></tr><tr class="txtBodyBold"><td align="left">&nbsp;</td><td align="left" colspan="3"><input type="hidden" name="parent_id" id="parent_id" value = "'+(parent_id?parent_id:0)+'"><input name="'+(xml?'editAttribute':'addAttribute')+'" type="submit" class="buttons" id="'+(xml?'editAttribute':'addAttribute')+'" value="'+buttonVal+'" />&nbsp;<input name="button2" type="button" class="buttons" id="button2" value="Close" onClick="removeNewAttributeFrame();" />'+(xml?('&nbsp;<input name="button2" type="button" class="buttons" id="button2" value=\'Delete with Values\' onClick="deleteFullAttribute('+attrib_id+');" /><input type="hidden" name="attribute_id" value="'+attrib_id+'"><input type="hidden" name="count" value="'+(xml?items.length:0)+'">'):'')+'<input type="hidden" name="cmd" value="'+buttonVal+'"></td></tr></table></td></tr></table>';

	return str;

}

function removeNewAttributeFrame(ref){

	

	var prnt = document.getElementById("new_attribute_div");

	prnt.innerHTML = "";

	prnt.style.display = "none";



	if(ref){

		var loc = window.location.href;

		window.location = loc;

	}

}

var STR_TITLE;

var FIRST_HEADING;

var BUTTON_VAL;

var ATTRIBUTE;

var CID;

function getAttributeDetails(parent_id,strTitle,firstHeading,buttonVal,ct_id){

	CID = ct_id;

	STR_TITLE = strTitle;

	FIRST_HEADING = firstHeading;

	BUTTON_VAL = buttonVal;

	ATTRIBUTE = parent_id;

	var prnt = document.getElementById("new_attribute_div");

		prnt.innerHTML = '<img src="'+root+'admin/images/plswait.gif">';

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/attributes.php",putAttributeDetails,"cmd=detail&attribute_id="+parent_id); 

}

function putAttributeDetails(strTitle){

	 if(httpRequest.readyState == 4){

		 var str = returnPanelStr(ATTRIBUTE, STR_TITLE, FIRST_HEADING, BUTTON_VAL, httpRequest.responseXML,CID);

		var prnt = document.getElementById("new_attribute_div");

		prnt.innerHTML = str;

		//var response = httpRequest.responseXML;

		//var user_id = response.getElementsByTagName("user_id")[0].firstChild.data;

		//var email = response.getElementsByTagName("email")[0].firstChild.data;

	}

}

var NewCtrl;

function deleteAttributeValues(a_id,ct_id){

	NewCtrl = ct_id;

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/attributes.php",deleteAttributeValuesResponse,"cmd=delete_vals&attribute_id="+a_id);

}

function deleteAttributeValuesResponse(){

	if(httpRequest.readyState == 4){

		removeNewAttributeFrame();

		addNewAttribute(ATTRIBUTE,'edit');

		setTimeout('getAttributeValues('+ATTRIBUTE+','+NewCtrl+')',3000);

	}

}



function deleteFullAttribute(attribute_id){

	var res = confirm("This attribute and all values associated with this will be deleted \n do you want to continue?");

	if(!res) return false;

	var prnt = document.getElementById("new_attribute_div");

		prnt.innerHTML = '<img src="'+root+'admin/images/plswait.gif">';

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/attributes.php",deleteFullAttributeResponse,"cmd=delFull&attribute_id="+attribute_id); 

}

function deleteFullAttributeResponse(strTitle){

	 if(httpRequest.readyState == 4){

		var prnt = document.getElementById("new_attribute_div");

		prnt.innerHTML = httpRequest.responseText;

		//var response = httpRequest.responseXML;

		//var user_id = response.getElementsByTagName("user_id")[0].firstChild.data;

		//var email = response.getElementsByTagName("email")[0].firstChild.data;

		showParentAttributeDetails(0,'m_attribute_name','m_attribute_id');

	}

}





//////////////////////////////////////////////////////////////////////////////////////////////////////////

var PARENT_ID = 0;

var ATTRIBUTE_ID;

var MAIN_DIV;

///////////////////////////////

function showParentAttributeDetails(attribute_id,cb_ctrl_name,cb_ctrl_id){

	ATTRIBUTE_ID = attribute_id;

	PARENT_ID = attribute_id;

	VPARENT_ID = attribute_id;

	CALL_BACK_CTRL_NAME = cb_ctrl_name;

	CALL_BACK_CTRL_ID = cb_ctrl_id;

	getParentAttributes(ATTRIBUTE_ID);

}

//CREATE SPAN FOR SUB ATTRIBUTES AND DIV FOR VALUES

function getParentAttributes(){
	httpRequest = createXMLHttpRequest();
	sendRequest("POST",root+"admin/ajax/attributes.php",putParentAttributes,"cmd=parents&attribute_id="+ATTRIBUTE_ID); 
}

function putParentAttributes(){
	if(httpRequest.readyState == 4){
		var span = document.getElementById("div_"+ATTRIBUTE_ID);
		span.innerHTML = httpRequest.responseText;
		document.getElementById('div_0').innerHTML += '<a href="javascript:void(0);" onClick="addNewAttribute(\'0\');"><img src="'+root+'admin/images/add.jpg" border="0" title="Add new attribute" alt="Add new attribute"></a>&nbsp;';
		if(TO_REFRESH){
			PARENT_ID = 0;
			CTRL_ID = 0;
			divs = document.getElementsByTagName("div");
			var matched = matchdDiv("div_0_");
			while(matched){
				prnt = divs[matched].parentNode;
				prnt.removeChild(divs[matched]);
				matched = matchdDiv("div_0_");
			}
			getAttributeValues(ATTRIBUTE_ID,0);
		}	
	}
}

//ASSIGNING THE PARENT ATTRIBUTE VALUES



function assignParentAttributeValues(attribute_id,attribute_name){

	document.getElementById(CALL_BACK_CTRL_NAME).value = attribute_name;

	document.getElementById(CALL_BACK_CTRL_ID).value = attribute_id;

	var span = document.getElementById("st_attribute_"+ATTRIBUTE_ID);

	span.innerHTML = "";

	span.style.display = "none";

	PARENT_ID = 0;

	CTRL_ID = 0;

	getAttributeValues(attribute_id,0);

	

}

//////////////////////////////////////////////////////////////////////////

function inArray(arr,val){

	var exists = false;

	for(var i=0; i<arr.length; i++){

		if(arr[i] == val){

			exists = true;

			break;

		}

	}

	return exists;

}

//GETTING SUB ATTRIBUTES

var TEMP_PARENT = "0";

var CTRL_ID ;



function getAttributeValues(attribute_id,ctrl_id)
{
	if(!attribute_id) return false;
	CTRL_ID = ctrl_id;
	ATTRIBUTE_ID = attribute_id;
	divs = document.getElementsByTagName("div");
	var matched = matchdDiv("div_"+CTRL_ID+"_");
	while(matched){
		prnt = divs[matched].parentNode;
		prnt.removeChild(divs[matched]);
		matched = matchdDiv("div_"+CTRL_ID+"_");
	}
	PARENT_ID = CTRL_ID;
	httpRequest = createXMLHttpRequest();
	sendRequest("POST",root+"admin/ajax/attributes.php",putAttributeValues,"cmd=vals&attribute_id="+ATTRIBUTE_ID+"&ctrl_id="+ctrl_id); 
}


function matchdDiv(ctr_id){

	divs = document.getElementsByTagName("div");

	var found = false;

	for(var k=0; k<divs.length; k++){

		if(divs[k].id.match(ctr_id)){

			found = k;

			break;

		}

	}

	if(found){  return k;}

	return false;

}

/******************************************************************************/

function putAttributeValues(){
	if(httpRequest.readyState == 4){
		//alert(httpRequest.responseText);
		var main_div = document.getElementById("div_"+CTRL_ID);
		if(!main_div){ // alert("div_"+CTRL_ID+ " Ka parent nahin mila ");
			return false;
		}
		var divs = main_div.getElementsByTagName("div");
		for(var i=0; i<divs.length; i++){
			if(divs[i].id.match("val_")){
				prnt = divs[i].parentNode;
				prnt.removeChild(divs[i]);
			}
		}
		var divs = main_div.getElementsByTagName("a");
		for(var i=0; i<divs.length; i++){
			if(divs[i].id.match("href_")){
				prnt = divs[i].parentNode;
				prnt.removeChild(divs[i]);
			}
		}
		var hrf = document.createElement("a");
		main_div.appendChild(hrf);
		hrf.innerHTML = '<img src="'+root+'admin/images/edit.jpg" border="0">';
		hrf.setAttribute("href",'javascript:void(0);');
		hrf.setAttribute("id","href_"+PARENT_ID+"_"+ATTRIBUTE_ID);
		var resp = httpRequest.responseText;
		//alert(resp);
		resp = resp.split("^");
		hrf.onclick = function (){
			addNewAttribute(resp[1],'edit',resp[2]);
		}
		//	var txtNode = document.createTextNode(String.fromCharCode(160));
		//	main_div.appendChild(txtNode);
		var div = document.createElement("div");
		div.setAttribute("id","val_"+PARENT_ID+"_"+ATTRIBUTE_ID);
			main_div.appendChild(div);
		div.innerHTML = resp[0]+'<a href="javascript:void(0);" onclick="addMoreAttributeValues('+ATTRIBUTE_ID+',\''+resp[3]+'\',\''+resp[2]+'\');"><img src="'+root+'admin/images/add.jpg" border="0" alt="Add more values" title="Add more values"></a>';
		//#if(PARENT_ID == 0)
		if(PARENT_ID == 0)
		getSubAttributes(ATTRIBUTE_ID);
	}
}



function getSubAttributes(attribute_id){
	if(!attribute_id) return false;
	ATTRIBUTE_ID = attribute_id;
	httpRequest = createXMLHttpRequest();
	//alert("url: "+"cmd=sub_attributes&attribute_id="+ATTRIBUTE_ID+"&parent_id="+PARENT_ID);
	sendRequest("POST",root+"admin/ajax/attributes.php",putSubAttributes,"cmd=sub_attributes&attribute_id="+ATTRIBUTE_ID+"&parent_id="+PARENT_ID); 
}

function putSubAttributes(){
	if(httpRequest.readyState == 4){
		//alert(CTRL_ID);
		var main_div = document.getElementById("div_"+CTRL_ID);
		if(!main_div){ //alert("div_"+CTRL_ID+ " Ka parent nahin mila "); 
			return false;}
		main_div = main_div.parentNode;
		if(TO_REFRESH){
			var matched = matchdDiv("div_"+CTRL_ID+"_");
			while(matched){
				prnt = divs[matched].parentNode;
				prnt.removeChild(divs[matched]);
				matched = matchdDiv("div_"+CTRL_ID+"_");
			}
		}

		//alert(PARENT_ID);
		div = document.createElement("div");

		div.setAttribute("id","div_"+CTRL_ID+"_"+ATTRIBUTE_ID);

		div.setAttribute("style","float:left");

		main_div.appendChild(div);

		div.innerHTML = httpRequest.responseText+'<a href="javascript:void(0);" onClick="addNewAttribute('+ATTRIBUTE_ID+',\'\',\''+CTRL_ID+'\');"><img src="'+root+'admin/images/add.jpg" border="0" title="Add new sub attribute" alt="Add new sub attribute"></a>&nbsp;';

		PARENT_ID = CTRL_ID+"_"+ATTRIBUTE_ID;

	}

}

/****************************************************************************************/



function addMoreAttributeValues(attribute_id,attribute_name,ctrlId){

	TO_REFRESH = ctrlId;

	var str = '<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center" id="mainTbl"><tr><td align="center" class="headingblue"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="background-color:#ffffff;" colspan="4" align"right"><div style="float:left"><div style="float:left">Add More Attribute Values</div><div align="right" style="float:right;"><a href="javascript:void(0);" onClick="removeNewAttributeFrame()"><img src="'+root+'admin/images/close.jpg" border="0" /></a></div></td></tr><tr><td colspan="4" align="left" class="headTD">Add Attribute</td></tr><tr><td width="40%" align="left" class="txtBodyBold">Attribute Name:</td><td width="23%" align="left" class="txtBodyBold"><input type="text" name="attribute_name" id="attribute_name" readonly value="'+attribute_name+'" /></td><td width="6%" align="left" class="txtBodyBold">&nbsp;</td><td width="31%" align="left" class="txtBodyBold">&nbsp;</td></tr><tr><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td></tr><tr><td colspan="4" align="left" class="tdBlueBg">Attribute Values</td></tr>';

	for(var i=1; i<=5; i++){

	str += '<tr><td align="left" class="txtBodyBold">Value '+i+'</td><td align="left" class="txtBodyBold"><input type="text" name="attribute_value'+i+'" id="attribute_value'+i+'" /></td><td align="left" class="txtBodyBold">Order</td><td align="left" class="txtBodyBold"><input type="text" name="attribute_order'+i+'" id="attribute_order'+i+'" value="'+i+'" /></td></tr>';

	}

	str += '<tr><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td><td align="left" class="txtBodyBold">&nbsp;</td></tr><tr class="txtBodyBold"><td align="left">&nbsp;</td><td align="left"><input type="hidden" name="parent_id" id="parent_id" value = "'+(attribute_id?attribute_id:0)+'"><input name="addMoreAttributeValues" type="submit" class="buttons" id="addMoreAttributeValues" value="Add" /> <input name="button2" type="button" class="buttons" id="button2" value="Close" onClick="removeNewAttributeFrame();" /></td><td align="left">&nbsp;</td><td align="left"><input type="hidden" name="cmd" value="addMoreValues"></td></tr></table></td></tr></table>';

	var prnt = document.getElementById("new_attribute_div");

	prnt.innerHTML = str;

	prnt.style.display = "block";

}



/**********************************************************************************************************/

/**********************************************************************************************************/

/**********************************************************************************************************/

var CALL_BACK_RESP_CTL;

var CMD;

function postByAjax(frm,callback){

	CALL_BACK_RESP_CTL = callback;

	var url = getFormElements(frm);

	var tmp = url.split("&");

	var cmd = (tmp[tmp.length-2]);

	cmd = cmd.split("=");

	CMD = cmd[1];

		httpRequest = createXMLHttpRequest();

		sendRequest("POST",root+"admin/ajax/attributes.php",postByAjaxResponse,url); 

}

function postByAjaxResponse(){

	if(httpRequest.readyState == 4){

		var elm = document.getElementById(CALL_BACK_RESP_CTL);

		var resp = httpRequest.responseText;

		resp = resp.split("^");

		var aid = resp[0];

		var resp = resp[1];

		elm.innerHTML = resp;

		switch(CMD){

			case 'Add':

				if(resp){

					if(aid == 0){

						showParentAttributeDetails(0,'m_attribute_name','m_attribute_id');

					}else{

						PARENT_ID = CTRL_ID = TO_REFRESH;

						getSubAttributes(aid);

					}

				}else{

					elm.innerHTML = httpRequest.responseText;

				}

			break;

			

			case  'Update':

				if(resp){

					if(TO_REFRESH == 0){

						showParentAttributeDetails(0,'m_attribute_name','m_attribute_id');

					}else{

						var temp = TO_REFRESH;

						var tmp = new Array();

						tmp = temp.split("_");

						var pr = tmp[tmp.length-1];

						tmp = tmp.removeIndex(tmp.length-1);

						tmp = tmp.join("_");

						if(tmp == 0){

							showParentAttributeDetails(0,'m_attribute_name','m_attribute_id');

						}else{

							//alert(tmp+" >> "+pr);

							PARENT_ID = CTRL_ID = tmp;

							getSubAttributes(pr);

						}

					}

				}else{

					elm.innerHTML = httpRequest.responseText;

				}

			break;

			

			case  'addMoreValues':

				if(resp){

						getAttributeValues(aid,TO_REFRESH)

				}else{

					elm.innerHTML = httpRequest.responseText;

				}

			break;

		}

	}

}

/***************************************************************************************************************/

/*										Other Functions 													   */

/***************************************************************************************************************/

var CTRL_ID;

function deleteBestSeller(product_id){

	if(!confirm("Are you sure to delete this product from bestseller products"))return false;

	CTRL_ID = 'bs_tr_'+product_id;

	var elm = document.getElementById("bs_msg");

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/php_functions.php",delbsresponse,"cmd=delbs&product_id="+product_id);

	elm.innerHTML = '<img src="'+root+'admin/images/waits2.gif"> deleting...';

}

function delbsresponse(){

	if(httpRequest.readyState == 4){

		var elm = document.getElementById(CTRL_ID);

		prnt = elm.parentNode;

		prnt.removeChild(elm);

		document.getElementById("bs_msg").innerHTML = "Product deleted from best sellers ";

	}

}



function deleteFeatured(product_id){

	if(!confirm("Are you sure to delete this product from featured products"))return false;

	CTRL_ID = 'fp_tr_'+product_id;

	var elm = document.getElementById("fp_msg");

	httpRequest = createXMLHttpRequest();

	sendRequest("POST",root+"admin/ajax/php_functions.php",deleteFeaturedResp,"cmd=delfp&product_id="+product_id);

	elm.innerHTML = '<img src="'+root+'admin/images/waits2.gif"> deleting...';

}

function deleteFeaturedResp(){

	if(httpRequest.readyState == 4){

		var elm = document.getElementById(CTRL_ID);

		prnt = elm.parentNode;

		prnt.removeChild(elm);

		document.getElementById("fp_msg").innerHTML = "Product deleted from featured products ";

	}

}

	function getAttValues(attid)
	{	//alert('dsfdsfd');
		if(attid > 0){
			httpRequest = createXMLHttpRequest();
			sendRequest("POST",root+"admin/ajax/attributes.php",displayAttributeValues,"cmd=attval&attid="+attid); 	
		}
	}
	
	function displayAttributeValues()
	{
		if(httpRequest.readyState == 4){
			document.getElementById("att_values").innerHTML = httpRequest.responseText;
		}
	}
	
	function getSubAttValues(subattid)
	{
		if(subattid > 0){
			httpRequest = createXMLHttpRequest();
			sendRequest("POST",root+"admin/ajax/attributes.php",displaySubAttValues,"cmd=subattval&subattid="+subattid); 	
		}
	}
	
	function displaySubAttValues()
	{
		if(httpRequest.readyState == 4){
			document.getElementById("subatt_values").innerHTML = httpRequest.responseText;
		}
	}
    
	function getMakeValues(typeId)
	{	//alert(typeId);

		if(typeId > 0){
			//alert(typeId);
			var s = 'make';
			//alert(s);
			httpRequest = createXMLHttpRequest();
			sendRequest("POST",root+"admin/ajax/carmodels1.php",displayMakeValues,
						"id="+typeId+"&type="+s); 	
		}
	}
		
		
		
		function displayMakeValues()
	{
		if(httpRequest.readyState == 4){
			document.getElementById("makeValues").innerHTML = httpRequest.responseText;
		}
	}
	
		
		
		
		function getModelValues(makeId)
	{	//alert(makeId);
		if(makeId > 0){
			var s = 'model';
			httpRequest = createXMLHttpRequest();
			sendRequest("POST",root+"admin/ajax/carmodels1.php",displayModelValues,
						"id="+makeId+"&type="+s); 	
		}
	}
	function displayModelValues()
	{
		
		if(httpRequest.readyState == 4){
			document.getElementById("modelValues").innerHTML = httpRequest.responseText;
		}
	}
	
	function getBodyType(modelId)
	{	//alert(makeId);
		if(modelId > 0){
			var s = 'bodyType';
			httpRequest = createXMLHttpRequest();
			sendRequest("POST",root+"admin/ajax/carmodels1.php",displayBodyTypeValues,
						"id="+modelId+"&type="+s); 	
		}
	}
	function displayBodyTypeValues()
	{
		if(httpRequest.readyState == 4){
			document.getElementById("bodyTypeValues").innerHTML = httpRequest.responseText;
		}
	}
	function getYears(modelId)
	{	//alert(modelId);
		if(modelId > 0){
			var s = 'year';
			httpRequest = createXMLHttpRequest();
			sendRequest("POST",root+"admin/ajax/carmodels1.php",displayYearValues,
						"id="+modelId+"&type="+s); 	
		}
	}
	function displayYearValues()
	{
		if(httpRequest.readyState == 4){
			document.getElementById("yearValues").innerHTML = httpRequest.responseText;
		}
	}