// AJAX
// Create a boolean variable to check for a valid Internet Explorer instance:
var xmlhttp = false;

// Check if we are using IE:
try {
	// If the IE version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch	(e) {
	// If not, then use the older active x object.
	try {
		// If we are using MS.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		// Else we must be using a non-IE browser.
		xmlhttp = false;
	}
}
// If we are using a non-IE browser, create a Javascript instance of the object:
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}
/* ========================================================================= */
// AJAX - Username check:
function UsernameCheck (uname) {

var strURL = "../ajax/username_check.php?uname=" + uname;
    xmlhttp.open("GET", strURL, true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        if (xmlhttp.responseText == 1) {
            document.getElementById('messageusererror').innerHTML = "This Username has already been registered.";
        } else {
            document.getElementById('messageusererror').innerHTML = "";
        }
    }		
    }
    xmlhttp.send(null);
}
/* ========================================================================= */
// AJAX - Login details check:
function LoginCheck (username, pass) {

var strURL = "../ajax/login_check.php?username=" + username + "&pass=" + pass;
    xmlhttp.open("GET", strURL, true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        if (xmlhttp.responseText == 0) {
            document.getElementById('messageboxerror').innerHTML = "Username and Password combination is incorrect, please try again.";
        } else {
            document.getElementById('messageboxerror').innerHTML = "";
        }
    }		
    }
    xmlhttp.send(null);
}

/* ========================================================================= */
// AJAX - Tripple Drop-Down-List:
function getstate (country) {

	var strURL = "../ajax/find_state.php?country_id=" + country;
	xmlhttp.open("GET", strURL, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			document.getElementById('statediv').innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function getCity (state) {
	
	var strURL = "../ajax/find_city.php?sId=" + state;
	xmlhttp.open("GET", strURL, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			document.getElementById('citydiv').innerHTML = xmlhttp.responseText;	
		}
	}
	xmlhttp.send(null);
}

/* ========================================================================= */
// AJAX - Category Tripple Drop-Down-List:
function getSubCat1 (category) {

	var strURL = "../ajax/subcat_1.php?subcat_1=" + category;
	xmlhttp.open("GET", strURL, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			document.getElementById('subcat1div').innerHTML = xmlhttp.responseText;
			document.getElementById('subcat1div').style.display='block';
			document.getElementById('subcat1nmdiv').style.display='block';
		}
	}
	xmlhttp.send(null);
}

function getSubCat2 (subcat1) {

	var strURL = "../ajax/subcat_2.php?subcat_2=" + subcat1;
	xmlhttp.open("GET", strURL, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			document.getElementById('subcat2div').innerHTML = xmlhttp.responseText;
			document.getElementById('subcat2div').style.display='block';
			document.getElementById('subcat2nmdiv').style.display='block';
		}
	}
	xmlhttp.send(null);
}

function getSubCat3 (subcat2) {

	var strURL = "../ajax/subcat_3.php?subcat_3=" + subcat2;
	xmlhttp.open("GET", strURL, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			document.getElementById('subcat3div').innerHTML = xmlhttp.responseText;
			document.getElementById('subcat3div').style.display='block';
			document.getElementById('subcat3nmdiv').style.display='block';
		}
	}
	xmlhttp.send(null);
}
function getSubCat4 (subcat3) {

	var strURL = "../ajax/subcat_4.php?subcat_4=" + subcat3;
	xmlhttp.open("GET", strURL, true);
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			
			document.getElementById('subcat4div').innerHTML = xmlhttp.responseText;
			document.getElementById('subcat4div').style.display='block';
			document.getElementById('subcat4nmdiv').style.display='block';
		}
	}
	xmlhttp.send(null);
}

/* ========================================================================= */
// AJAX - Remove Image:

function RemoveImg (img) {
    var strURL = "../ajax/remove_img.php?image=" + img;
    xmlhttp.open("GET", strURL, true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText == 1) {
                document.getElementById("image_details").innerHTML = "";
                document.getElementById("file_div").innerHTML = document.getElementById("file_div").innerHTML;
                document.getElementById("size").innerHTML = "";
            } else {
                document.getElementById("errormsg").innerHTML = "";
                document.getElementById("file_div").innerHTML = document.getElementById("file_div").innerHTML;
            }
        }
    }
    xmlhttp.send(null);
}
// AJAX - Remove Student Image
function RemoveStudImg (img) {
    var strURL = "../ajax/remove_stud_img.php?image=" + img;
    xmlhttp.open("GET", strURL, true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText == 1) {
                document.getElementById("image_details").innerHTML = "";
                document.getElementById("file_div").innerHTML = document.getElementById("file_div").innerHTML;
                document.getElementById("size").innerHTML = "";
            } else {
                document.getElementById("errormsg").innerHTML = "";
                document.getElementById("file_div").innerHTML = document.getElementById("file_div").innerHTML;
            }
        }
    }
    xmlhttp.send(null);
}

// =====================================================
//  AJAX - Member ID:
// AJAX - Username check:
function MemberIDCheck (id) {

var strURL = "../ajax/memberid_check.php?id=" + id;
    xmlhttp.open("GET", strURL, true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        if (xmlhttp.responseText == 1) {
            document.getElementById('messageusererror').innerHTML = "This Member Id does not exist";
        } else {
            document.getElementById('messageusererror').innerHTML = "";
        }
    }		
    }
    xmlhttp.send(null);
}
/* ========================================================================= */
// AJAX - Remove Image:

function RemoveImg(img) {
    var strURL = "../ajax/remove_img.php?image=" + img;
    xmlhttp.open("GET", strURL, true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText == 1) {
                document.getElementById("image_details").innerHTML = "";
                document.getElementById("file_div").innerHTML = document.getElementById("file_div").innerHTML;
                document.getElementById("size").innerHTML = "";
            } else {
                document.getElementById("errormsg").innerHTML = "";
                document.getElementById("file_div").innerHTML = document.getElementById("file_div").innerHTML;
            }
        }
    };
    xmlhttp.send(null);
}
/* ========================================================================= */
//AJAX MEMBER ID For Share Experience
function MemberIdCheck (id) {

var strURL = "../ajax/member_id.php?id=" + id;
    xmlhttp.open("GET", strURL, true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        if (xmlhttp.responseText == 1) {
            document.getElementById('messageusererror').innerHTML = "this member id does not exist";
        } else {
            document.getElementById('messageusererror').innerHTML = "";
        }
    }		
    };
    xmlhttp.send(null);
} 

