// JavaScript Document


// Function to Edit category
function edit_cat(cat_id) {
	document.getElementById('mainDiv').style.display="block";
	pop_box=document.getElementById('popup');
	pop_box.style.display="block";
	strURL="edit-category.php?cat_id="+cat_id;
	req(pop_box, strURL);
}
function del_cat(cat_id) {
	var r=confirm("Are you Sure? you want to delete this category?");
	if(r==true) {
		window.location="cat.delete.php?cat_id="+cat_id;
	}
	else {
		return false;	
	}
}

function delStoreLogo(store_id) {
	document.getElementById('mainDiv').style.display="block";
	pop_box=document.getElementById('popup');
	pop_box.style.display="block";
	strURL="editStoreLogo.php?store_id="+store_id;
	req(pop_box, strURL);
}

function delCouponLogo(coupon_id) { 
	document.getElementById('mainDiv').style.display="block";
	pop_box=document.getElementById('popup');
	pop_box.style.display="block";
	strURL="editCouponLogo.php?coupon_id="+coupon_id;
	req(pop_box, strURL);
}

function delDealLogo(deal_id) {
	document.getElementById('mainDiv').style.display="block";
	pop_box=document.getElementById('popup');
	pop_box.style.display="block";
	strURL="editDealLogo.php?deal_id="+deal_id;
	req(pop_box, strURL);
}

function delStore(store_id) {
	var r=confirm("Are you Sure? you want to delete this Store?");
	if(r==true) {
		window.location="store.delete.php?store_id="+store_id;
	}
	else {
		return false;	
	}
}

function delCoupon(coupon_id) {
	var r=confirm("Are you Sure? you want to delete this Coupon?");
	if(r==true) {
		window.location="coupon.delete.php?coupon_id="+coupon_id;
	}
	else {
		return false;	
	}
}

function delDeal(deal_id) {
	var r=confirm("Are you Sure? you want to delete this Deal?");
	if(r==true) {
		window.location="deal.delete.php?deal_id="+deal_id;
	}
	else {
		return false;	
	}
}

function getStores(cat) {
	elem=document.getElementById('storeName');
	strURL="getStores.php?cat="+cat;
	req(elem, strURL);
}

function checkStore(val) {
	elem=document.getElementById('storeDuplicate');
	strURL="checkStore.php?val="+val;
	req(elem, strURL);
}

function searchStore(val) {
	elem=document.getElementById('schStore');
	strURL="getStoresById.php?val="+val;
	req(elem, strURL);
}


function userReports(user) {
	var elem=document.getElementById('dateReports');
	var dId = "day"+user; 
	var mId = "month"+user; 
	var yId = "year"+user; 
	var dayElem = document.getElementById(dId);
	var monthElem = document.getElementById(mId);
	var yearElem = document.getElementById(yId);
	var day = dayElem.options[dayElem.selectedIndex].value;
	var month = monthElem.options[monthElem.selectedIndex].value;
	var year = yearElem.options[yearElem.selectedIndex].value;
	var date = year + "-" + month + "-" + day;
	strURL="files.reportsDate.php?date="+date+"&user="+user;
	req(elem, strURL);
}

function hide() {
	document.getElementById('mainDiv').style.display="none";
	document.getElementById('popup').style.display="none";
	document.getElementById('popup').innerHTML="<div id='loader'><img src='../images/ajax-loader(2).gif' /></div>";
}


// Ajax Data Function 
function req(elem, strURL) {
			var req = getXMLHTTP();			
				if (req) { 							
					req.onreadystatechange = function() {
						if (req.readyState == 1) {
						document.getElementById('loader').style.display="block"; 				
						}
						if (req.readyState == 4) {
							// only if "OK"
							if (req.status == 200) {		
								elem.innerHTML=req.responseText;
								document.getElementById('loader').style.display='none';
							} else {
								alert("There was a problem while using XMLHTTP:\n" + req.statusText);
							}
						}				
					}			
			req.open("GET", strURL, true);
			req.send(null);
				}
			}	
	function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
		}
