﻿/* ================================================================ */
/*                                  AJAX function for checking valid url                                */
/* ================================================================ */
function openAjax() {
	var ajax; 
	try { 
		ajax = new XMLHttpRequest(); 
	} catch (ee) { 
		try { 
			ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e) { 
			try { 
				ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
			} catch (E) { 
				ajax = false; 
			} 
		} 
	} 
	return ajax;
}

function check_url (url_path) {
	var AJAX = null;				// Initialize the AJAX variable.
	var url = url_path;
	
	AJAX = openAjax();
	
	AJAX.onreadystatechange = function() {                      	// When the browser has the request info..
		if (AJAX.readyState==4 || AJAX.readyState=="complete") {		//  see if the complete flag is set.
			alert(AJAX.status)
			var status = AJAX.status;
			/*
			if (AJAX.status  == 404) {
				// Do nothing
				return false;
				//alert ("no image found");
			} else {
				// Go to the URL
				return true;
				//alert ("image exists");
			}*/
			return status;
		}                                                      	
	}
	
	AJAX.open("GET", url, true);	
	AJAX.send(null);
}

function get_shopGiftList (shopID, giftID) {
	var AJAX = null;				// Initialize the AJAX variable.
	AJAX = openAjax();
	var url_path = "include/get_shopGiftList.php?shopID=" + shopID + "&giftID=" + giftID;
	var url = url_path;

	AJAX.onreadystatechange = function() {                      	// When the browser has the request info..
		if (AJAX.readyState==4 || AJAX.readyState=="complete") {		//  see if the complete flag is set.
			document.getElementById("promo_giftID").innerHTML=AJAX.responseText;
		} else {
			document.getElementById("promo_giftID").innerHTML="loading...";
		}                                                      	
	}
	
	AJAX.open("GET", url, true);
	AJAX.send(null);
}

function get_shopGift (shopID) {
	var AJAX = null;				// Initialize the AJAX variable.
	AJAX = openAjax();
	var url_path = "../include/get_shopGift.php?shopID=" + shopID;
	var url = url_path;

	AJAX.onreadystatechange = function() {                      	// When the browser has the request info..
		if (AJAX.readyState==4 || AJAX.readyState=="complete") {		//  see if the complete flag is set.
			document.getElementById("shop_giftStat").innerHTML=AJAX.responseText;
		} else {
			document.getElementById("shop_giftStat").innerHTML="loading...";
		}                                                      	
	}
	
	AJAX.open("GET", url, true);
	AJAX.send(null);
}

function get_giftSubCat (giftCat1ID, giftSubcatID, level, style) {
	var AJAX = null;				// Initialize the AJAX variable.
	AJAX = openAjax();
	var url_path;
	
	if (level == 1) {
		url_path = "include/get_giftSubcat.php?giftCat1ID=" + giftCat1ID + "&giftSubcatID=" + giftSubcatID + "&style=" + style;
	} else if (level == 2) {
		url_path = "../include/get_giftSubcat.php?giftCat1ID=" + giftCat1ID + "&giftSubcatID=" + giftSubcatID + "&style=" + style;
	}
	var url = url_path;

	AJAX.onreadystatechange = function() {                      	// When the browser has the request info..
		if (AJAX.readyState==4 || AJAX.readyState=="complete") {		//  see if the complete flag is set.
			document.getElementById("frm_gift_subcat").innerHTML=AJAX.responseText;
		} else {
			document.getElementById("frm_gift_subcat").innerHTML="loading...";
		}                                                      	
	}
	
	AJAX.open("GET", url, true);
	AJAX.send(null);
}

function district_info (district1) {
	var AJAX = null;				// Initialize the AJAX variable.
	AJAX = openAjax();
	var url_path = "include/get_districtInfo.php?shop_district1=" + district1;
	var url = url_path;

	AJAX.onreadystatechange = function() {                      	// When the browser has the request info..
		if (AJAX.readyState==4 || AJAX.readyState=="complete") {		//  see if the complete flag is set.
			//document.getElementById("district_info").innerHTML=AJAX.responseText;
			return AJAX.responseText;
		}                                                      	
	}
	
	AJAX.open("GET", url, true);	
	AJAX.send(null);
}

function check_username (type, input_var) {
	var AJAX = null;				// Initialize the AJAX variable.
	AJAX = openAjax();
	var url_path = "include/check_duplicate.php?type=" + type + "&login=" + input_var;
	var url = url_path;

	AJAX.onreadystatechange = function() {                      	// When the browser has the request info..
		if (AJAX.readyState==4 || AJAX.readyState=="complete") {		//  see if the complete flag is set.
			if (type == "shop" || type == "member_username") {
				document.getElementById("username_result").innerHTML=AJAX.responseText;
			} else {
				document.getElementById("email_result").innerHTML=AJAX.responseText;
			}
			//return AJAX.responseText;
		} else {
			if (type == "shop" || type == "member_username") {
				document.getElementById("username_result").innerHTML = '<img src="images/wait01.gif" width="15" height="15" border="0" />';
			} else {
				document.getElementById("email_result").innerHTML = '<img src="images/wait01.gif" width="15" height="15" border="0" />';
			}
		}
	}
	
	AJAX.open("GET", url, true);	
	AJAX.send(null);
}
/* ================================================================ */
/*                              End AJAX function for checking valid url                             */
/* ================================================================ */