//Login Controller to assign Input Methods
function LoginController () {
	this.attachAction ()
}
	LoginController.prototype.attachAction = function () {
		document.LoginForm.User_Email.onclick = function () {
			if (this.value == 'Email') {
				this.value = ''
			}
		}
		document.LoginForm.User_Email.onblur = function () {
			if (this.value == '') {
				this.value = 'Email'
			}
		}
		
		//onfocus need method 
		document.LoginForm.User_Pass.onfocus = function () {
		if (this.value == 'Password') {
				this.value = ''
				this.setAttribute('type', 'Password')
			}
		}
		document.LoginForm.User_Pass.onclick = function () {
			if (this.value == 'Password') {
				this.value = ''
				this.setAttribute('type', 'Password')
			}
		}
		document.LoginForm.User_Pass.onblur = function () {
			if (this.value == '') {
				this.setAttribute('type', 'Text')
				this.value = 'Password'
			}
		}
	}
//Login Form Validity Check Upon Submition
function ValidateLogin (that) {
var Validity = true
var Error = ''
if (that.User_Email.value == 'Email' || that.User_Pass.value == 'Password') {
	Validity = false
	document.getElementById('UserControl').innerHTML += '<br /><br />Please fill in the missing fields'
}
return Validity
}

	//REMOVE CATEGORY
		//ajax call to remove a category
		//in php check user admin status
			//defer to index.php to login if user is not an admin
			//send flag for redirection if the user is not an admin
function RemoveCategory (Cat_Id, Cat_Title) {
	var confirmRemove = confirm('Are you sure you wish to remove ' + Cat_Title + '?\r\n\r\n This action will drop all subcategories, products, and images associated with this category.')
	if (confirmRemove) {
		var action 		= '?Action=RemoveCategory'
			Cat_Id 		= '&Cat_Id=' + Cat_Id
		var Response	= '&Response=RemoveCategory_Response'
		var get_vars 	= action 
		var post_vars	= Cat_Id + Response
		makePOSTRequest(ajax_url + get_vars, post_vars);
	}
}
	//Remove Category Callback, fired when php returns a str response eval'd in Ajax_Lib.js
	function RemoveCategory_Response (status, output, Cat_Id, redirect) {
		document.getElementById('DisplayStatusMsg').style.display = '' ;
		document.getElementById('DisplayStatusMsg').innerHTML = output ; 
		switch (status) {
			case '1': 
				//Remove the Category from the CategoryList Div
				var cat = document.getElementById('CategoryList-' + Cat_Id)
					cat.parentNode.removeChild(cat)						
				//Remove the Category from the DisplayPane Div
				var cat = document.getElementById('Cat-' + Cat_Id)
					cat.parentNode.removeChild(cat)
			break ;
			case '0': 
				if (redirect != "") {
					window.location = redirect
				}
			break ;
		}
	}


	//REMOVE SUBCATEGORY
		//ajax call to remove a subcategory
		//in php check user admin status
			//defer to index.php to login if user is not an admin
			//send flag for redirection if the user is not an admin
function RemoveSubCategory (SubCat_Id, SubCat_Title) {
	var confirmRemove = confirm('Are you sure you wish to remove ' + SubCat_Title + '?\r\n\r\n This action will drop all products, and images associated with this category.')
	if (confirmRemove) {
		var action 		= '?Action=RemoveSubCategory'
			SubCat_Id 	= '&SubCat_Id=' + SubCat_Id
		var Response	= '&Response=RemoveSubCategory_Response'
		var get_vars 	= action 
		var post_vars	= SubCat_Id + Response
		makePOSTRequest(ajax_url + get_vars, post_vars);
	}
}
	//Remove SubCategory Callback, fired when php returns a str response eval'd in Ajax_Lib.js
	function RemoveSubCategory_Response (status, output, SubCat_Id, redirect) {
		document.getElementById('DisplayStatusMsg').style.display = '' ;
		document.getElementById('DisplayStatusMsg').innerHTML = output ; 
		switch (status) {
			case '1': 
				//Remove the Category from the CategoryList Div
				var subcat = document.getElementById('SubCatList-' + SubCat_Id)
					subcat.parentNode.removeChild(subcat)						
				//Remove the Category from the DisplayPane Div
				var subcat = document.getElementById('SubCat-' + SubCat_Id)
					subcat.parentNode.removeChild(subcat)
			break ;
			case '0': 
				if (redirect != "") {
					window.location = redirect
				}
			break ;
		}
	}
	
	//REMOVE PRODUCT
		//ajax call to remove a product
		//in php check user admin status
			//defer to index.php to login if user is not an admin
			//send flag for redirection if the user is not an admin
function RemoveProduct (Prod_Id) {
	var confirmRemove = confirm('Are you sure you wish to remove ' + Prod_Id + '?\r\n\r\n This action will drop the product and all information associated with it.')
	if (confirmRemove) {
		var action 		= '?Action=RemoveProduct'
			Prod_Id 	= '&Prod_Id=' + Prod_Id
		var Response	= '&Response=RemoveProduct_Response'
		var get_vars 	= action 
		var post_vars	= Prod_Id + Response
		makePOSTRequest(ajax_url + get_vars, post_vars);
	}
}
	//Remove Product Callback, fired when php returns a str response eval'd in Ajax_Lib.js
	function RemoveProduct_Response (status, output, Prod_Id, redirect) {
		document.getElementById('DisplayStatusMsg').style.display = '' ;
		document.getElementById('DisplayStatusMsg').innerHTML = output ; 
		switch (status) {
			case '1': 					
				//Remove the Product from the DisplayPane Div
				var subcat = document.getElementById('Product-' + Prod_Id)
					subcat.parentNode.removeChild(subcat)
			break ;
			case '0': 
				if (redirect != "") {
					window.location = redirect
				}
			break ;
		}
	}
