function selectAction1(f){
	if(document.actionForm.selAction.value == ''){
			
			alert("Please select an actionsss to be performed");
				
			return false;
			
	}
	if(document.actionForm.selAction.value != 'drop'){
	document.listingForm.mode.value = "performAction";
	document.listingForm.selectedAction.value = document.actionForm.selAction.value;
	sendRequest(f);
	}
	else{
	document.listingForm.mode.value = "performDelete";
	document.listingForm.selectedAction.value = document.actionForm.selAction.value;
	sendRequest(f,'performDelete');
	}
	
	//document.listingForm.submit();
	return false;
}


function selectAction(){
	
	if(document.actionForm.selAction.value == ''){
			
			alert("Please select an action to be performed");
				
			return false;
			
	}
	if(document.actionForm.selAction.value != 'drop')
	document.listingForm.mode.value = "performAction";
	else
	document.listingForm.mode.value = "performDelete";
	document.listingForm.selectedAction.value = document.actionForm.selAction.value;
	document.listingForm.submit();
	return false;
}


function showNextPage(path, extraParams){

	var redirectURL = path + extraParams + "page=" + document.getElementById('pageSelect').value;

	window.location.href = redirectURL;
}

function selCategory(){
	var form1 = document.catSelect;
	form1.product_id.value  = form1.parent_id.value;
	form1.section_listing.value  = 	form1.section_listing.value;
	form1.submit();
	
}
function selSection(f1){
	var form1 = f1;
	switch(form1.mode.value){
		
	case "saveCategory"	:
			form1.mode.value = "addCategory";
			form1.section.value = 	form1.section_listing.value;
			break;
	case "updateCategory":	
			form1.mode.value = "editCategory";
			form1.section.value = 	form1.section_listing.value;
			break;
	}
	form1.submit();
}
function selSectionProduct(f1){
	
	
	var form1 = f1;
	switch(form1.mode.value){
		
	case "saveProduct"	:
			form1.mode.value = "addProduct";
			
			break;
	case "updateProduct":	
			form1.mode.value = "editProduct";
			
			break;
	}
	
	
	form1.submit();
	
}
function FormField(name, description, type, additional_params){
	
	this.name = name;
	this.description = description;
	this.type = type;	
	this.additional_params = additional_params; // multi-use
	this.isValid = function(f){
			
				switch(this.type){
					case "text" :
					return (f.elements[this.name].value != "");
					break;
					
					case "number" :
					var number_regex = /^[0-9]+$/;
					return ( number_regex.test(f.elements[this.name].value));
					break;
					case "character" :
					var number_regex = /^[A-Za-z ]+$/;
					return ( number_regex.test(f.elements[this.name].value));
					break;
					case "email" :
					var email_regex = /^([a-z0-9_-]+\.)*[a-z0-9_-]+@([a-z0-9_-]+\.)+[a-z]{2,3}$/i;
					return (email_regex.test(f.elements[this.name].value));
					break;
					case "password" :
					var password_regex =  /^[A-Za-z ]+$/;
					return ((password_regex.test(f.elements[this.name].value)) && f.elements[this.name].value.length>=5);
					break;
					default : return false;
				};
		};
	
}
function validateForm(f){
	
		var fields_with_errors = new Array();
		for (var i in required_fields){
				if(!required_fields[i].isValid(f)){
					
					fields_with_errors[fields_with_errors.length] = required_fields[i].description;
				}
		}
		
		if(fields_with_errors.length > 0){
			alert("Make sure following fields are complete and correct:\n\n-" + fields_with_errors.join("\n -"));
			return false;
		}else{
		return true;
		}
		return false;
}

function changeDate(val,elem){
	
	
elem.value = val;
}


function changeID(id,f){

document.listingForm.id.value =	id;
sendRequest(f);
}




function changeIDMode(id,f,mode1){
f.mode.value = mode1;

document.listingForm.id.value =	id;
sendRequest(f);
}


function changeMode(mode,f){

f.mode.value =	mode;
sendRequest(f);
}


function checkSearch(){
	
	
	if(document.searchForm.searchField.value == '')	{
	document.getElementById("divSearchError").style.display  = "";
	document.searchForm.searchValue.blur();
	return false;
	}
	else{
		document.getElementById("divSearchError").style.display  = "none";;
	}
	return true;
	
}
