// JavaScript Document
function AjaxFunction(cat_id)
{
	
var httpxml;
try
  {
  // Firefox, Opera 8.0+, Safari
  httpxml=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
		  try
   			 		{
   				 httpxml=new ActiveXObject("Msxml2.XMLHTTP");
    				}
  			catch (e)
    				{
    			try
      		{
      		httpxml=new ActiveXObject("Microsoft.XMLHTTP");
     		 }
    			catch (e)
      		{
      		alert("Your browser does not support AJAX!");
      		return false;
      		}
    		}
  }
  
function stateck() 
    {
    if(httpxml.readyState==4)
      {

var myarray=eval(httpxml.responseText);
// Before adding new we must remove previously loaded elements
for(j=document.forms[0].subcat.options.length-1;j>=0;j--)
{
document.forms[0].subcat.remove(j);
}


for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
var splitresult = myarray[i].split("-");
optn.text = splitresult[0];
optn.value = splitresult[1];
document.forms[0].subcat.options.add(optn);

} 
      }
    }
	var url="dd.php";
url=url+"?cat_id="+cat_id;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
  }
  
  
function viewProduct()
{
	with (window.document.frmAddProduct) {
		if (cboCategory.selectedIndex == 0) {
			window.location.href = 'index.php';
		} else {
			window.location.href = 'index.php?view=add&catId=' + cboCategory.options[cboCategory.selectedIndex].value;
		}
	}
}

function viewProduct3(pdId)
{
	
			window.location.href = 'index.php?view=detail&pdId=' +pdId;
	
}
function viewProduct2()
{
	with (window.document.frmListProduct) {
		if (cat.selectedIndex == 0) {
			window.location.href = 'index.php';
		} else if(subcat.selectedIndex < 0)
		{
			window.location.href = 'index.php?chId=' + cat.options[cat.selectedIndex].value + '&catId=';
		}
		
		else {
				
			window.location.href = 'index.php?chId=' + cat.options[cat.selectedIndex].value + '&catId=' + subcat.options[subcat.selectedIndex].value;
			 
		}
	}
}
function viewGallery()
{

	with (window.document.frmListProduct) {
		if (cat.selectedIndex == 0) {
			window.location.href = 'photo_gallery.php';
		}else if (subcat.selectedIndex < 0) {
			window.location.href = 'photo_gallery.php?chId=' + cat.options[cat.selectedIndex].value + '&catId=';
		
		}
		
		  else {
				
			window.location.href = 'photo_gallery.php?chId=' + cat.options[cat.selectedIndex].value + '&catId=' + subcat.options[subcat.selectedIndex].value;
			 
		}
	}
}

function viewProduct4()
{
	with (window.document.frmListProduct) {
		if (cboCategory.selectedIndex == 0) {
			window.location.href = 'photo_gallery.php';
		} else {
			window.location.href = 'photo_gallery.php?catId=' + cboCategory.options[cboCategory.selectedIndex].value;
		}
	}
}
function setDefalutShadeM(shadeId,pdId)
{
	
		window.location.href = 'processProduct.php?action=setdefaultshadeM&shId=' + shadeId +'&pdId='+pdId;
	
}
function setDefalutImageM(pgId,pdId,shadeId)
{
	
		window.location.href = 'processProduct.php?action=setDefalutImageM&pgId='+ pgId+ '&pdId='+pdId +'&shadeId='+shadeId;
	
}
function setDefalutShade(shadeId)
{
	
		window.location.href = 'processProduct.php?action=setdefaultshade&shId=' + shadeId;
	
}
function setDefalutImage(pgid,shadeid)
{
	
		window.location.href = 'processProduct.php?action=setDefalutImage&pgId=' + pgid +'&shadeId='+ shadeid ;
	
}
function deleteShade(shadeId)
{
	if (confirm('Are you sure want to delete this Shade?')) {
		window.location.href = 'processProduct.php?action=deleteShade&shId=' + shadeId;
	}
}
function deleteImageG(productId,shadeid)
{
	if (confirm('Are you sure want to delete this image')) {
		window.location.href = 'processProduct.php?action=deleteImage&pgId=' + productId+'&shadeid='+shadeid;
	}
}
function deleteShadeM(shadeId,pdId)
{
	if (confirm('Are you sure want to delete this Shade?')) {
		window.location.href = 'processProduct.php?action=deleteShadeM&shId=' + shadeId+'&pdId='+pdId;
	}
}
function deleteImageGM(pgId,shadeId,pdId)
{
	if (confirm('Are you sure want to delete this image')) {
		window.location.href = 'processProduct.php?action=deleteImageM&pgId=' + pgId+'&shadeId='+shadeId+'&pdId='+ pdId;
	}
}
function checkAddProductForm()
{
	with (window.document.frmAddProduct) {
		if (cat.selectedIndex == 0) {
			alert('Choose a Chapter');
			cat.focus();
			return;
		} else {
		//alert(subcat.options[subcat.selectedIndex].value);
		 eventid.value = subcat.options[subcat.selectedIndex].value;
		 //alert(eventid.value);
		 submit();
		}
	}
}


function checkAddallProductForm()
{
	
//	var oEditor = FCKeditorAPI.GetInstance('mtx');
    // alert(oEditor.GetXHTML(true));
//	var valuetemp= oEditor.GetXHTML(true);
	//alert(valuetemp);
	with (window.document.frmAddProduct)
	 {
		 if (cboCategory.selectedIndex == 0)
			{
				alert('Choose Product Category  First');
				cboCategory.focus();
				return;
			} 	
		else if (isEmpty(txtName, 'Enter Product name')) {
				return;
				}
		
		 else if (isEmpty(txtcode, 'Enter Product Code')) {
				return;
		 }
		else if (isEmpty(txtPrice, 'Enter Product Price')) {
				return;
		 }  
		 
		else{
			
			
					
			action = 'processProduct.php?action=addallProduct&CatID='+CatID.value;
			submit();
		}
								
  } 
  
  
 
			
}//end of function

function checkmodifyform(pdId)
{
	
	//var oEditor = FCKeditorAPI.GetInstance('mtx');
    // alert(oEditor.GetXHTML(true));
	//var valuetemp= oEditor.GetXHTML(true);
	//alert(valuetemp);
	with (window.document.frmAddProduct)
	 {
		 if (cboCategory.selectedIndex == 0)
			{
				alert('Choose Product Category  First');
				cboCategory.focus();
				return;
			} 	
		else if (isEmpty(txtName, 'Enter Product name')) {
				return;
				}
		
		 else if (isEmpty(txtcode, 'Enter Product Code')) {
				return;
		 }
		 else if (isEmpty(txtPrice, 'Enter Product Price')) {
				return;
		 } 
		 
		else{
			 action='processProduct.php?action=addProductMT&pdId='+pdId;
			 submit();
			
			
			/*		
			location.href = 'processProduct.php?action=addProductMT&pdId='+pdId+'&CatID='+CatID.value+'&txtName='+txtName.value+
			'&txtcode='+txtcode.value+'&mtxoverview='+mtxoverview.value+'&txtPrice='+txtPrice.value+'&txtwt='+txtwt.value
			+'&mtxDescription='+valuetemp;
			;*/
			
			
		}
								
  } 
  
  
 
			
}//end of function

function checkcancelProductForm()
{
	location.href = 'processProduct.php?action=cancelProduct';
}


function addProduct(catId)
{
	window.location.href = 'index.php?view=add&catId=' + catId;
}

function modifyProduct(productId)
{
	
	window.location.href = 'index.php?view=modify&productId=' + productId;
}

function deleteProduct(productId,catid)
{
	if (confirm('Are you sure want to delete this Image?')) {
		window.location.href = 'processProduct.php?action=deleteProduct&productId=' + productId+'&catId='+catid;
	}
}

function deleteImage(productId)
{
	if (confirm('Are you sure want to delete this image')) {
		window.location.href = 'processProduct.php?action=deleteImage&productId=' + productId;
	}
}

function changeOrder(parentId)
{  targetUrl = 'index.php?view=order';
  with (window.document.frmListProduct)
 {
		if (cboCategory.selectedIndex == 0)
		{
			alert('Choose Category First');
			cboCategory.focus();
			return;
		} 
	   if (parentId != 0) 
	   {

		targetUrl += '&catId=' + parentId;
     	}
 }
	   window.location.href = targetUrl;

 }
var shade_statuspost;var parameters=""; //shade_status Info 
var showinpanelpost; //showinpanel Info 
var setDefalutShadepost;
var tempcounter=0;
var tempcounter2=0;
/* Shade Status funtions*/
function changestatusM(shId,shadeId,productId,counter,funtionName){
	var tempName="shadestatus"+counter;
	tempcounter=counter;
	
	var shadestatus =document.getElementById(tempName);
	// alert(shadestatus);
   var url="changeShadeStatusM.php";
     var parameters="shId=" +encodeURI(shId ) + "&shadeId=" +encodeURI(shadeId ) + "&productId="+ encodeURI( productId )+ "&shadestatus="+ encodeURI( shadestatus.value )+ "&counter="+ encodeURI(counter )+"&funtionName="+encodeURI(funtionName)
	 ;
	// alert(url);
	  shade_statuspost=createajax_opac();MakePostRequest_opac(url,parameters,"manageShadeStatus",shade_statuspost);
}
function manageShadeStatus(){
	
  try{
    if(shade_statuspost.readyState == 4)
	{ 
	  if(shade_statuspost.status == 200)
	  {
		     var response =shade_statuspost.responseText.split("|");
		   var tempName2="lock_unlock"+tempcounter;
		//alert(response[0]);
document.getElementById(tempName2).innerHTML = response[0];
		
      }else {alert('There was a problem with the request.');}}
  }catch(e){}
}
/* showinpane funtions*/
function changeshowinpanelM(shId,shadeId,productId,counter,funtionName){
	var tempName="chkshowinpanel"+counter;
	tempcounter2=counter;
	
	if(document.getElementById(tempName).checked)
	{ 
		temp="Yes";
	}
	else{
		temp="No";
	}
	
   var url="changeshowinpaneM.php";
     var parameters="shId=" +encodeURI(shId ) + "&shadeId=" +encodeURI(shadeId ) + "&productId="+ encodeURI( productId )+ "&chkshowinpanel="+ encodeURI( temp ) + "&counter="+ encodeURI(counter )+"&funtionName="+encodeURI(funtionName);
	 
	  showinpanelpost=createajax_opac();MakePostRequest_opac(url,parameters,"manageshowinpanel",showinpanelpost);
}
function manageshowinpanel(){
	
  try{
    if(showinpanelpost.readyState == 4)
	{ 
	  if(showinpanelpost.status == 200)
	  {
		     var response =showinpanelpost.responseText.split("|");
		    // alert(response[0]);
	 var tempName2="showinpanel"+tempcounter2;
		 //  alert(response[0]);
	document.getElementById(tempName2).innerHTML = response[0];
		
      }else {alert('There was a problem with the request.');}}
  }catch(e){}
}

/*Set Defalut shade or image*/
function setDefalutShadeMJ(shId,shadeId,productId,counter,funtionName){
	
	tempcounter2=counter;
	//alert(funtionName);
	
   var url="setDefaultShade.php";
     var parameters="shId=" +encodeURI(shId ) + "&shadeId=" +encodeURI(shadeId ) + "&productId="+ encodeURI( productId ) + "&counter="+ encodeURI(counter )+"&funtionName="+encodeURI(funtionName);
	 
	  setDefalutShadepost=createajax_opac();MakePostRequest_opac(url,parameters,"managesetDefalutShade",setDefalutShadepost);
}
function managesetDefalutShade(){
	
  try{
    if(setDefalutShadepost.readyState == 4)
	{ 
	  if(setDefalutShadepost.status == 200)
	  {
		     var response =setDefalutShadepost.responseText.split("|");
		//alert(response[0]);
	// var tempName2="ShadeId"+tempcounter2;
		//  alert(response[0]);
	//document.getElementById(tempName2).innerHTML = response[0];
		
      }else {alert('There was a problem with the request.');}}
  }catch(e){}
}

var shade_quantitypost;

/*Set Defalut shade or image*/
function modifyquantity(shId,shadeId,productId,counter,funtionName){
	
	tempcounter2=counter;
	 var tempName2="shadeqty"+tempcounter2;
	var qty = document.getElementById(tempName2).value;
	
   var url="setDefaultShade.php";
     var parameters="shId=" +encodeURI(shId ) + "&shadeId=" +encodeURI(shadeId ) + "&productId="+ encodeURI( productId ) + "&counter="+ encodeURI(counter ) + "&funtionName="+encodeURI(funtionName)+ "&qty="+encodeURI(qty);
	// alert(parameters);
	 shade_quantitypost=createajax_opac();MakePostRequest_opac(url,parameters,"managesetmodifyquantity",shade_quantitypost);
}
function managesetmodifyquantity(){
	
  try{
    if(shade_quantitypost.readyState == 4)
	{ 
	  if(shade_quantitypost.status == 200)
	  {
		     var response =shade_quantitypost.responseText.split("|");
			   // alert(response[0]);
	/* var tempName2="shadeqty"+tempcounter2;
		 //  alert(response[0]);
	document.getElementById(tempName2).value = response[0];*/
		
      }else {alert('There was a problem with the request.');}}
  }catch(e){}
}