function clearContact(){
	if (confirm('All the fields are about to be cleared. Are you sure you want to continue?')){
	var root=document.contact;
	root.name.value='';
	root.title.value='';
	root.company.value='';
	root.address.value='';
	root.phone1.value='';
	root.phone2.value='';
	root.email.value='';
	root.comment.value='';
	root.position.value='';
	root.fax.value='';
	root.web.value='';
	root.name.focus();
	
	}
	return false;
}
function validateContact(){
	var root=document.contact;
	var name=root.name.value;
	if(name==''){
		alert('Please fill up the name field');
		root.name.focus();
		return false;
	}
	var title=root.title.value;
	if(title==''){
		alert('Please fill up the title field');
		root.title.focus();
		return false;
	}
	var company=root.company.value;
	if(company==''){
		alert('Please fill up the company name');
		root.company.focus();
		return false;
	}
	var address=root.address.value;
	if(address==''){
		alert('Please specify an address');
		root.address.focus();
		return false;
	}
	var phone1=root.phone1.value;
	var phone2=root.phone2.value;
	if(phone1==''&&phone2==''){
		alert('Please specify at least one phone number');
		root.phone1.focus();
		return false;
	}
	var email=root.email.value;
	if(email==''){
		alert('Please specify an email address');
		root.email.focus();
		return false;
	}
	var comments=root.comment.value;
	if(comments==''){
		alert('Please enter your comments');
		root.comment.focus();
		return false;
	}
	return true;	
}

function validateAddCategory(){
	var root=document.cate;
	var name=root.catename.value;
	
	if(name==''){
		alert('Please fill up the name field');
		root.catename.focus();
		return false;
	}
	var uploadimagethumb = root.img[1].checked;
		if(uploadimagethumb){
			var image=root.cateimage.value;
			if(image==''){
				alert('Please browse an image');
				root.cateimage.focus();
				return false;
			
			}
		
		}
		
		var main = root.typemain.value;
		if(main==''){
				alert('Please select type of category');
				root.typemain.focus();
				return false;
		}
				
		var description = root.description.value;
		if(description==''){
				alert('Please insert a description');
				root.description.focus();
				return false;
		}

}

function validateAddSubCategory(){
	var root=document.subcate;
	var categories=root.categories.value;
	
	if(categories==''){
		alert('Please select a category');
		root.categories.focus();
		return false;
	}
	
	var subcategories=root.subname.value;
	
	if(subcategories==''){
		alert('Please specify a subcategory name');
		root.subname.focus();
		return false;
	}
	var uploadimagethumb = root.img[1].checked;
		if(uploadimagethumb){
			var image=root.cateimage.value;
			if(image==''){
				alert('Please browse an image');
				root.cateimage.focus();
				return false;
			
			}
		
		}
		
	var description = root.description.value;
	if(description==''){
			alert('Please insert a description');
			root.description.focus();
			return false;
		}
		return true;

}

function openTheWindow(entry, windowWidth, windowHeight){
	window.open('/solario/admin/preview_image.php?entry='+entry+'','mywindow',''+windowWidth+','+windowHeight+',scrollbars=0,menubars=0,left=100,top=100');
	return false;
}

function validateEditPhotos(){
	var root = document.add_photos;
	var name = root.photo_name.value;
	if (name == ''){
		alert('Please fill up the name field');
		root.photo_name.focus();
		return false;
	}
	var color = root.colors.value;
	if(color==''){
		alert('Please select a color');
		root.colors.focus();
		return false;
	}
	
	var existingthumb = root.thumb_choice_1[1].checked;
	var uploadimagethumb = root.thumb_choice_1[2].checked;
	
	var existingpreview = root.preview_choice_1[1].checked;
	var uploadimagepreview = root.preview_choice_1[2].checked;
	
	
	var myValue = '';
	if(existingpreview){
		myValue = root.existing_preview_1.value;
		if(myValue==''){
			alert('Please select a photo');
			return false;
		}
		
	}
	else if (uploadimagepreview){
		myValue = root.new_preview_1.value;
		if(myValue==''){
			alert('Please specify a photo to upload');
			return false;
		}
	}
	
	if(existingthumb){
		myValue = root.existing_thumb_1.value;
		if(myValue == ''){
			alert('Please select a thumbnail');
			return false;
		}
	}
	else if (uploadimagethumb){
		myValue = root.new_thumb_1.value;
		if(myValue == ''){
			alert('Please specify a thumbnail to upload');
			return false;
		}
	}
	
	
	
	return true;
	


}
function  validateAddPhotos(){
	var root = document.add_photos;
	var name = root.photo_name.value;
	if (name == ''){
		alert('Please fill up the name field');
		root.photo_name.focus();
		return false;
	}
	var color = root.colors.value;
	if(color==''){
		alert('Please select a color');
		root.colors.focus();
		return false;
	}
	
	var existingthumb = root.thumb_choice_1[0].checked;
	var uploadimagethumb = root.thumb_choice_1[1].checked;
	
	var existingpreview = root.preview_choice_1[0].checked;
	var uploadimagepreview = root.preview_choice_1[1].checked;
	
	
	var myValue = '';
	if(existingpreview){
		myValue = root.existing_preview_1.value;
		if(myValue==''){
			alert('Please select a photo');
			return false;
		}
		
	}
	else if (uploadimagepreview){
		myValue = root.new_preview_1.value;
		if(myValue==''){
			alert('Please specify a photo to upload');
			return false;
		}
	}
	
	if(existingthumb){
		myValue = root.existing_thumb_1.value;
		if(myValue == ''){
			alert('Please select a thumbnail');
			return false;
		}
	}
	else if (uploadimagethumb){
		myValue = root.new_thumb_1.value;
		if(myValue == ''){
			alert('Please specify a thumbnail to upload');
			return false;
		}
	}
	
	
	
	return true;
	
}


function openColorChart() {
	window.open("colorchart.html", "color", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=292,height=196");
	return false;
}

function validateAddColor(){
	var root = document.add_colors;
	var name=root.color_name.value;
	if(name==''){
		alert('Please enter a color name');
		root.color_name.focus();
		return false;
	}
	var color=root.bgcolor.value;
	if(color==''){
		alert('Please select a color');
		root.bgcolor.focus();
		return false;
	}
	
	return true;

}

function passReplace(){
pass=document.login.password.value;
user=document.login.username.value;
pattern = /^([a-zA-Z0-9_-])*$/;
			
			flag = pattern.test(user);
			flag2 = pattern.test(pass);
			
			if(!flag || user == ""){
				alert('Please enter your username.');
				document.login.username.focus();
				return false;
				}

			if(!flag2 || pass ==""){
				alert('please enter your password.');
				document.login.password.focus();
				return false;
			}
			else{
				pass=hex_md5(pass);			
				document.login.password.value=pass;
				return true;
			}
}

//password validation
function passValidation(){
	oldpass=document.change_password.old;
	newpass=document.change_password.newp;
	pass=document.change_password.confnew;
				
				if(oldpass.value == ""){
					alert('Please insert your old password.');
					oldpass.focus();
					return false;	
				}

				if(oldpass.value.length < 6){
					alert('Old password should not be less than 6 characters.');
					oldpass.focus();
					return false;	
				}
				
				
				if(newpass.value == ""){
					alert('Please insert your new password.');
					newpass.focus();
					return false;	
				}
				if(newpass.value.length < 6){
					alert('New password should not be less than 6 characters.');
					newpass.focus();
					return false;	
				}
				if(pass.value == ""){
					alert('Please retype your password.');
					pass.focus();
					return false;	
				}
				if(pass.value.length < 6){
					alert('password confirmation should not be less than 6 characters.');
					pass.focus();
					return false;	
				}
				if(newpass.value != pass.value){
					alert("Your password and it's confirmation do not match.");
					pass.focus();
					return false;	
				}
			oldpass.value=hex_md5(oldpass.value);
			newpass.value=hex_md5(newpass.value);
			pass.value=hex_md5(pass.value);
			return true;
			
				
			}
function reloadCategoriesPage(direct){
	var cat = document.subcate.categories[document.subcate.categories.selectedIndex].value;	
	location.href= direct + '?type=subcat&catId=' + cat;
}

function reloadPhotosPage(direct){
	var cat = document.list_photos.colors[document.list_photos.colors.selectedIndex].value;	
	location.href= direct + '?catId=' + cat;
}

function reloadViewCategoriesPage(direct){
	var cat = document.viewCats.categories[document.viewCats.categories.selectedIndex].value;	
	location.href= direct + '?catId=' + cat;
}
function preview(page,folder,i){
	var newEntry = eval('document.'+page+'.existing_preview_'+i+'.value');
	var array = newEntry.split("|");
	if (newEntry == ''){
		alert('Please select an image.');
		return false;
	}
	var entry = folder+array[0];
	window.open('/solario/admin/preview_image.php?entry='+entry,'view_image','width='+array[1]+',height='+array[2]+',status=0,toolbar=0,scrollbars=0,history=0,left=100,top=100');
	return false;
}

function previewthumb(page,folder,i){
	var newEntry = eval('document.'+page+'.existing_thumb_'+i+'.value');
	var array = newEntry.split("|");
	if (newEntry == ''){
		alert('Please select an image.');
		return false;
	}
	var entry = folder+array[0];
	window.open('/solario/admin/preview_image.php?entry='+entry,'view_image','width='+array[1]+',height='+array[2]+',status=0,toolbar=0,scrollbars=0,history=0,left=100,top=100');
	return false;
}