//Focus on first field
//---------------------------------------------------------------------------------------------------------------------
function putFocus(formInst, elementInst) 
{
	if (document.forms.length > 0) 
	{
		document.forms[formInst].elements[elementInst].focus();
	}
}
//Pop-up window
function pop_up(wch_window,wdth,heght,scrl)
		{
		var winl = (screen.width - wdth) / 2;
		var wint = (screen.height - heght) / 2;
						           
		window.open(wch_window,"newWindow","toolbar=0,menubar=0,location=no,directories=0,status=0,fullscreen=No,scrollbars="+scrl+",resizable=no,width="+wdth+",height="+heght+",left="+winl+",top="+wint);
		}
		function pager(wch_cat,wch_pg)
		{
			window.location = "shop.asp?category="+wch_cat+"&pn="+wch_pg
		}
//Submit order
function order()
{
    document.cart.submit()
}
//Add main category
function addcategory()
{
	if (document.add_category.maincategory.value == "")
	{
		alert('Please enter a category')
		document.add_category.maincategory.focus()
		return false;
	}
	confirm_val = confirm("Are you sure you want to add this category?")
	if (confirm_val == true)
	{			
		document.add_category.submit()
	}
	else
	{
		return false;
	}
}
//Main category reset
function addcategoryreset()
{
	window.location = "control_panel.asp?cmd=categories"
}
//Add page reset
function addpagereset()
{
	window.location = "control_panel.asp?cmd=add_page"
}
//Modify page reset
function modpagereset()
{
	window.location = "control_panel.asp?cmd=mod_page"
}
//Parent page reset
function parpagereset()
{
	window.location = "control_panel.asp?cmd=parent_page"
}
//Contact reset
function contactreset()
{
	window.location = "control_panel.asp?cmd=contact"
}

//Prepop modify category
function modifycat()
{
	var wch_cat
	wch_cat = document.modify_subcategory.modify_subcat.options[document.modify_subcategory.modify_subcat.selectedIndex].value
	window.location = "control_panel.asp?cmd=navigation&wchcat="+wch_cat
}

//Prepop delete category
function deletecat()
{
	var wch_cat
	wch_cat = document.delete_subcategory.delete_subcat.options[document.delete_subcategory.delete_subcat.selectedIndex].value
	window.location = "control_panel.asp?cmd=navigation&deletewchcat="+wch_cat
}

//Prepop add page category
function addcat()
{
	for (var i=0; i < document.addpage.imageposition.length; i++)
	{
	if (document.addpage.imageposition[i].checked)
		{
		var wch_position = document.addpage.imageposition[i].value;
		}
	}
	wch_cat      = document.addpage.content_category.options[document.addpage.content_category.selectedIndex].value
	wch_subcat   = document.addpage.content_subcategory.options[document.addpage.content_subcategory.selectedIndex].value
	wch_header   = document.addpage.pageheader.value
	wch_footer   = document.addpage.pagefooter.value
	window.location = "control_panel.asp?cmd=add_page&wchcat="+wch_cat+"&subcat="+wch_subcat+"&header="+wch_header+"&footer="+wch_footer+"&position="+wch_position	
}

//Prepop modify page category
function modcat()
{
	wch_cat      = document.modpage.content_category.options[document.modpage.content_category.selectedIndex].value
	wch_subcat   = document.modpage.content_subcategory.options[document.modpage.content_subcategory.selectedIndex].value
	wch_subsubcat   = document.modpage.content_subsubcategory.options[document.modpage.content_subsubcategory.selectedIndex].value
	window.location = "control_panel.asp?cmd=mod_page&wchcat="+wch_cat+"&subcat="+wch_subcat+"&sub2="+wch_subsubcat
}

//Modify category
function modifycategories()
{
	if (document.modify_category.modify_cat.value == "" && document.modify_category.modify_cat_text.value == "")
	{
		alert("Please make a selection and enter your desired changes") 
		return false;
	}
	else if (document.modify_category.modify_cat.value != "" && document.modify_category.modify_cat_text.value == "")
	{
		alert("You did not enter a corresponding modification value for the CATEGORY you selected") 
		return false;
	}
	else
	{
		confirm_val = confirm("Are you sure you want to modify this data?\nModifying a main catgory will place all exising sub catgegories under the new category name.\nDo you wish to proceed?")
		if (confirm_val == true)
		{			
			document.modify_category.submit()
		}
		else
		{
			return false;
		}
	}
}

//Delete category
function deletecategories()
{
	if (document.delete_category.delete_cat.options[document.delete_category.delete_cat.selectedIndex].value == "")
	{
		alert("Please select a category") 
		document.delete_category.delete_cat.focus()
		return false;
	}
	else
	{
		confirm_val = confirm("Are you sure you want to delete this category?\nWarning! This action cannot be undone.\nDeleting a category will remove all data for that category.\nDo you wish to proceed?")
		if (confirm_val == true)
		{			
			document.delete_category.submit()
		}
		else
		{
			return false;
		}
	}
}	

//Add page data
function addpagedata1()
{
	if (document.addpage.content_category.value == "")
	{
		alert("Please select a category") 
		document.addpage.content_category.focus()
		return false;
	}

	if (document.addpage.fulldesc.value == "")
	{
		alert("Please enter a description") 
		document.addpage.fulldesc.focus()
		return false;
	}

	confirm_val = confirm("Are you sure you want to create this page?")
	if (confirm_val == true)
	{			
		document.addpage.submit()
	}
	else
	{
		return false;
	}
}

//Add page data
function addpagedata2()
{
	if (document.addpage.content_category.value == "")
	{
		alert("Please select a category") 
		document.addpage.content_category.focus()
		return false;
	}

	if (document.addpage.price.value == "")
	{
		alert("Please enter a price") 
		document.addpage.price.focus()
		return false;
	}
	
	if (document.addpage.desc.value == "")
	{
		alert("Please enter a title") 
		document.addpage.desc.focus()
		return false;
	}
	
	if (document.addpage.fulldesc.value == "")
	{
		alert("Please enter a description") 
		document.addpage.fulldesc.focus()
		return false;
	}
	
	if (document.addpage.wch_image.value == "")
	{
		alert("Please select an image") 
		document.addpage.wch_image.focus()
		return false;
	}

	confirm_val = confirm("Are you sure you want to create this page?")
	if (confirm_val == true)
	{			
		document.addpage.submit()
	}
	else
	{
		return false;
	}
}

//Modify page data
function parpagedata()
{
	if (document.parpage.pageheader.value == "")
	{
		alert("Please enter a page header") 
		document.parpage.pageheader.focus()
		return false;
	}
	else
	{
	    confirm_val = confirm("Are you sure you want to update this page?")
	    if (confirm_val == true)
	    {			
		    document.parpage.submit()
	    }
	    else
	    {
		    return false;
	    }
	 }
}
//Contact support
function contactsupport()
{
	document.contact.submit()
}
//Add email address
function addemail()
{
	window.location = "control_panel.asp?cmd=email&add=true"
}
//Reset email address
function reset_email()
{
	window.location = "control_panel.asp?cmd=email"
}
//Submit email address
function submit_email()
{
	emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	if (document.add_email.emailaddress.value == "")
	{
		alert('Please enter an email address')
		document.add_email.emailaddress.focus()
		return false;
	}
	if (!emailRe.test(document.add_email.emailaddress.value))
	{
		alert('Your email address seems to be invalid');
		document.add_email.emailaddress.focus()
		return false;
	}
	confirm_val = confirm("Are you sure you want to add this email address?")
	if (confirm_val == true)
	{			
		document.add_email.submit()
	}
	else
	{
		return false;
	}
}
//Update email addresses
function updateemail()
{
	emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	if(typeof document.add_email.modifyemail == 'object')
	{
		if (document.add_email.modifyemail.value == "")
		{
			alert('Please enter an email address')
			document.add_email.modifyemail.focus()
			return false;
		}
		if (!emailRe.test(document.add_email.modifyemail.value))
		{
			alert('Your email address seems to be invalid');
			document.add_email.modifyemail.focus()
			return false;
		}
		confirm_val = confirm("Are you sure you want to modify this email address?")
		if (confirm_val == true)
		{			
			document.add_email.submit()
		}
		else
		{
			window.location = "control_panel.asp?cmd=email"
			return false;
		}
	}
}

//Delete email address
function deleteemail(id)
{	
	confirm_val = confirm("Are you sure you want to delete this email address?")
	if (confirm_val == true)
	{			
		window.location = "control_panel.asp?cmd=email&deleteid="+id
	}
	else
	{
		window.location = "control_panel.asp?cmd=email"
		return false;
	}
}

//system logout
function system_logout()
{
	confirm_val = confirm("Are you sure you want to log out of the system?")
	if (confirm_val == true)
	{			
		window.location = "account_details.asp?logout=true"
	}
	else
	{
		return false;
	}
}

function controlpanel_logout()
{
	confirm_val = confirm("Are you sure you want to log out of the system?")
	if (confirm_val == true)
	{			
		window.location = "control_panel.asp?logout=true"
	}
	else
	{
		return false;
	}
}

//excel export
function excel_export(table)
{
	//document.main.target = '_blank'
	document.main.action = "export.asp?table="+table

	document.main.submit();
}

//search function
function searchdel(id)
{
	document.main.action = "control_panel.asp?cmd=query&search=true&deleteid="+id+"&target=contact";
	//document.main.target = "_self"
	document.main.submit();
}

//search function
function searchdel2(id)
{
	document.main.action = "control_panel.asp?cmd=query&search=true&deleteid="+id+"&target=alumni";
	//document.main.target = "_self"
	document.main.submit();
}

function listorder()
{
	confirm_val = confirm("Are you sure you want to re-order this list?")
	if (confirm_val == true)
	{			
		document.list.submit()
	}
	else
	{
		return false;
	}
}

function display_cat()
{
	wch_cat = document.modpage.content_category.options[document.modpage.content_category.selectedIndex].value
	window.location = "control_panel.asp?cmd=mod_page&cat="+wch_cat
}

function updaterec()
{
	confirm_val = confirm("Are you sure you want to update this record?")
	if (confirm_val == true)
	{			
		document.modpage.submit()
	}
	else
	{
		return false;
	}
}

function deleterec(wch_cat,wch_id)
{
	confirm_val = confirm("Are you sure you want to delete this record?")
	if (confirm_val == true)
	{			
		document.modpage.action = "control_panel.asp?cmd=mod_page&cat="+wch_cat+"&deleteid="+wch_id
		document.modpage.submit()
	}
	else
	{
		return false;
	}
}

function showimage()
{
	wch_cat = document.addpage.content_category.options[document.addpage.content_category.selectedIndex].value
	wch_price = document.addpage.price.value
	wch_title = document.addpage.desc.value
	wch_desc = document.addpage.fulldesc.value
	wch_image = document.addpage.wch_image.options[document.addpage.wch_image.selectedIndex].value
	window.location = "control_panel.asp?cmd=add_page&cat="+wch_cat+"&price="+wch_price+"&desc="+wch_title+"&fulldesc="+wch_desc+"&image="+wch_image
}


function pop_images()
{
	wch_cat = document.addpage.content_category.options[document.addpage.content_category.selectedIndex].value
	wch_price = document.addpage.price.value
	wch_title = document.addpage.desc.value
	wch_desc = document.addpage.fulldesc.value
	window.location = "control_panel.asp?cmd=add_page&cat="+wch_cat+"&price="+wch_price+"&desc="+wch_title+"&fulldesc="+wch_desc
}

//system logout
function modify_account()
{
	confirm_val = confirm("Are you sure you want to update your account information?")
	if (confirm_val == true)
	{			
		document.update.submit()
	}
	else
	{
		return false;
	}
}

function adddescon()
{
	wch_cat = document.addpage.content_category.options[document.addpage.content_category.selectedIndex].value
	wch_check = document.addpage.add_desc_on.value
	wch_desc = document.addpage.fulldesc.value
	window.location = "control_panel.asp?cmd=add_page&cat="+wch_cat+"&fulldesc="+wch_desc+"&ado="+wch_check
}

function adddescoff()
{
	wch_cat = document.addpage.content_category.options[document.addpage.content_category.selectedIndex].value
	wch_desc = document.addpage.fulldesc.value
	window.location = "control_panel.asp?cmd=add_page&cat="+wch_cat+"&fulldesc="+wch_desc
}

var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;
function isInteger(s)
{   var i;
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	return true;
}
function stripCharsInBag(s, bag)
{   var i;
	var returnString = "";
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
function checkInternationalPhone(strPhone)
{
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function validate_us_zipcode(zip_val)
{
	var re = /^\d{5}([\-]\d{4})?$/;
	if(!re.test(zip_val))
	{
		alert("Please enter a valid zip code");
		document.shipping.zip1.focus();
		return false;
	}
}

//Upload validation
function uploadcat()
{
	var wch_cat
	wch_cat = document.upload_image.targetfolder.options[document.upload_image.targetfolder.selectedIndex].value
	window.location = "upload.asp?folder="+wch_cat
}


function deleteorder(id)
{	
	confirm_val = confirm("Are you sure you want to delete this order entry?")
	if (confirm_val == true)
	{			
		window.location = "orders.asp?cmd=orders&deleteid="+id
	}
	else
	{
		return false;
	}
}

function deleteaccount(id)
{	
	confirm_val = confirm("Are you sure you want to delete this customer account?\nWarning! This action CAN NOT be undone.")
	if (confirm_val == true)
	{			
		window.location = "customer_accounts.asp?cmd=accounts&deleteaccid="+id
	}
	else
	{
		return false;
	}
}


function showDiv(val)
		{
			document.getElementById(val).style.display    = 'block';
		}


function closeDivs(val)
{
	if (document.getElementById(val)){document.getElementById(val).style.display    = 'none';}
}