function viewImage ( id )
{
	window.open ( "viewimage.php?id=" + id, "owk_viewimage", "width=750,height=630" );
}
function viewImageNews ( id )
{
	window.open ( "viewimage_news.php?id=" + id, "owk_viewimage", "width=750,height=580" );
}
function viewImageComp ( id )
{
	window.open ( "viewimage_comp.php?id=" + id, "owk_viewimage", "width=750,height=580" );
}
function printReport ( id, userid )
{
	window.open ( "pages/print_report.php?id=" + id, "Report", "width=630,height=630" );
}
function findObj ( theObj, theDoc )
{
	var p, i, foundObj;

	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	{
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

	return foundObj;
}

function validateForm ()
{
	var i, p, q, nm, test, num, min, max, errors='', args = validateForm.arguments;
  
	for ( i = 0; i < ( args.length - 2 ); i += 3 )
	{
		test = args [i + 2];
		val = findObj ( args [i] );
		if ( val )
		{
			nm = val.name;
			if ( ( val = val.value ) != "" )
			{
				if ( test.indexOf ( "isEmail" ) != -1 )
				{
					p = val.indexOf ('@');
					if ( p < 1 || p == ( val.length-1 ) )
						errors += "- " + args [i+1] + " must be an e-mail address.\n";
				} else
				if ( test != "R" )
				{
					num = parseFloat ( val );
        			if ( isNaN ( val ) )
						errors += "- " + args [i+1] + " must be a number.\n";
			        if ( test.indexOf ( 'inRange' ) != -1 )
					{
						p = test.indexOf ( ":" );
						min = test.substring ( 8, p );
						max = test.substring ( p + 1 );
						if ( num < min || max < num )
							errors += "- " + args [i+1] + " must be a number between " + min + " and " + max + ".\n";
					}
				}
			} else
			if ( test.charAt (0) == "R" )
				errors += "- " + args [i+1] + " must be entered.\n";
		}
	}
	
	if ( errors )
		alert ( "The following errors were found:\n" + errors );
	return ( errors == '' );
}

function swapImageRestore ()
{
	var i, x, a = document.sr;
	for ( i = 0; a && i < a.length && ( x = a [i] ) && x.oSrc; i++ )
		x.src=x.oSrc;
}

function preloadImages ()
{
	var d = document;
	if ( d.images )
	{
		if ( !d.p ) d.p = new Array ();
		var i, j = d.p.length, a = preloadImages.arguments;
		for ( i = 0; i < a.length; i++ )
		{
			if ( a [i].indexOf ( "#" ) != 0 )
			{
				d.p [j] = new Image;
				d.p [j++].src = a [i];
			}
		}
	}
}

function swapImage ()
{
	var i, j = 0, x, a = swapImage.arguments;
	document.sr = new Array;
	for ( i = 0; i < ( a.length - 2 ); i += 3 )
	{
		if ( ( x = findObj ( a [i] ) ) != null )
		{
			document.sr [j++] = x;
			if ( !x.oSrc ) x.oSrc = x.src;
			x.src= a [i+2];
		}
	}
}

function changeadmincat ( ss )
{
	window.location.replace ( "index.php?page=admin/items&pid=" + ss.value );
}

function changecat ( ss, page )
{
	var f = findObj ('additemsform');
	f.elements ['cid'].value = ss;
	f.elements ['page'].value = page;
	f.submit ();
}

var itemdescpopup = 0;

function itemdescription ( code )
{
	if ( itemdescpopup )
	{
		if ( !itemdescpopup.closed ) itemdescpopup.close ();
	}
	var url = "itemdesc.php?code=" + code;
	itemdescpopup = window.open ( url, "itemdescpopup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=600,height=500,left=100,top=100,screenY=100"); 
}

function use_editor ()
{
	tinyMCE.init({
		// General options
		mode : "textareas",
		elements : "content",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}

function validate_blog()
{
	var posted = document.getElementById('posted');
	var description = document.getElementById('description');
	
	valid = true;
	
	if( isDescription(description, "Required") )valid = false;
	if( isPosted(posted, "Required") )valid = false;
	
    return valid;
	
}

function isPosted(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('posted_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('posted_validate').innerHTML = '';
	}
	
}


function isDescription(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('description_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('description_validate').innerHTML = '';
	}
	
}

function validate_client(){
	var title = document.getElementById('title');
	var name = document.getElementById('name');
	var surname = document.getElementById('surname');
	var id_no = document.getElementById('id_no');
	var telephone_home = document.getElementById('telephone_home');
	var telephone_work = document.getElementById('telephone_work');
	var cell = document.getElementById('cell');
	var email = document.getElementById('email');

	valid = true;
	if( isEmail(email, "Required") )valid = false;
	if(isCell(cell, "Require at least one contact number") && isTelephoneWork(telephone_work, "Require at least one contact number") && isTelephoneHome(telephone_home, "Require at least one contact number"))
	{
		valid = false;
	}
	if( isSurname(surname, "Required" ) )valid = false;
	if( isName(name, "Required" ) )valid = false;
	if( isTitle(title, "Required" ) )valid = false;
    
		return valid;
}

function isTitle(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('title_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('title_validate').innerHTML = '';
	}
	
}

function isName(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('name_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('name_validate').innerHTML = '';
	}
	
}


function isSurname(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('surname_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('surname_validate').innerHTML = '';
	}
	
}

function isIdno(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('id_no_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('id_no_validate').innerHTML = '';
	}
	
}

function isTelephoneHome(elem, helperMsg){
		if(elem.value.length == 0){
		document.getElementById('telephone_home_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('telephone_home_validate').innerHTML = '';
	}
	
}

function isCell(elem, helperMsg){
		if(elem.value.length == 0){
		document.getElementById('cell_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('cell_validate').innerHTML = '';
	}
	
}

function isTelephoneWork(elem, helperMsg){
		if(elem.value.length == 0){
		document.getElementById('telephone_work_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('telephone_work_validate').innerHTML = '';
	}
	
}

function isEmail(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('email_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('email_validate').innerHTML = '';
	}
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function isPostalAddress1(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_address1_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_address1_validate').innerHTML = '';
	}
	
}

function isPostalCity(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_city_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_city_validate').innerHTML = '';
	}
	
}

function isPostalPostalcode(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_postalcode_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_postalcode_validate').innerHTML = '';
	}
	
}

function isPostalCountry(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_country_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_country_validate').innerHTML = '';
	}
	
}

function isPostalProvince(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_province_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_province_validate').innerHTML = '';
	}
	
}
////////////////////////////////////////////////////////////////////////////////////////////////
function isDeliveryAddress1(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_address1_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_address1_validate').innerHTML = '';
	}
	
}

function isDeliveryCity(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_city_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_city_validate').innerHTML = '';
	}
	
}

function isDeliveryPostalcode(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_postalcode_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_postalcode_validate').innerHTML = '';
	}
	
}

function isDeliveryCountry(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_country_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_country_validate').innerHTML = '';
	}
	
}

function isDeliveryProvince(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_province_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_province_validate').innerHTML = '';
	}
	
}

function isPassword(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('password_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('password_validate').innerHTML = '';
	}
	
}

function isConfirmPass(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('confirmpass_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('confirmpass_validate').innerHTML = '';
	}
	
}

function isMatchPassword(new_p, confirm_p, helperMsg)
{
	if(new_p.value != confirm_p.value){
		document.getElementById('confirmpass_validate').innerHTML = helperMsg;
		confirm_p.focus(); // set the focus to this input
		return true;
	}
	else {
		document.getElementById('confirmpass_validate').innerHTML = '';
	}
	
}

function validate_password(){
	var email = document.getElementById('email');
	
	valid = true;
	
	if( isEmail(email, "Required") )valid = false;
    return valid;
		
}


function isEmail(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('email_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('email_validate').innerHTML = '';
	}
	
}

function validate_delivery(){
	
	var delivery_address1 = document.getElementById('delivery_address1');
	var delivery_address2 = document.getElementById('delivery_address2');
	var delivery_city = document.getElementById('delivery_city');
	var delivery_postalcode = document.getElementById('delivery_postalcode');
	var delivery_country = document.getElementById('delivery_country');
	var delivery_province = document.getElementById('delivery_province');
	
	var new_address = document.getElementById('new_address');
	
	valid = true;
	if( new_address.checked )
	{
		if( isDeliveryProvince(delivery_province, "Required") )valid = false;
		if( isDeliveryCountry(delivery_country, "Required") )valid = false;
		if( isDeliveryPostalcode(delivery_postalcode, "Required") )valid = false;
		if( isDeliveryCity(delivery_city, "Required") )valid = false;
		if( isDeliveryAddress2(delivery_address2, "Required") )valid = false;
		if( isDeliveryAddress1(delivery_address1, "Required") )valid = false;
	}
	
    return valid;
		
	
}

////////////////////////////////////////////////////////////////////////////////////////////////
function isDeliveryAddress1(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_address1_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_address1_validate').innerHTML = '';
	}
	
}

function isDeliveryAddress2(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_address2_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_address2_validate').innerHTML = '';
	}
	
}

function isDeliveryCity(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_city_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_city_validate').innerHTML = '';
	}
	
}

function isDeliveryPostalcode(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_postalcode_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_postalcode_validate').innerHTML = '';
	}
	
}

function isDeliveryCountry(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_country_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_country_validate').innerHTML = '';
	}
	
}

function isDeliveryProvince(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_province_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_province_validate').innerHTML = '';
	}
	
}

function validate(){
	var title = document.getElementById('title');
	var name = document.getElementById('name');
	var surname = document.getElementById('surname');
	var id_no = document.getElementById('id_no');
	var telephone_home = document.getElementById('telephone_home');
	var telephone_work = document.getElementById('telephone_work');
	var email = document.getElementById('email');
	
	var postal_address1 = document.getElementById('postal_address1');
	var postal_address2 = document.getElementById('postal_address2');
	var postal_city = document.getElementById('postal_city');
	var postal_postalcode = document.getElementById('postal_postalcode');
	var postal_country = document.getElementById('postal_country');
	var postal_province = document.getElementById('postal_province');
	
	var delivery_address1 = document.getElementById('delivery_address1');
	var delivery_address2 = document.getElementById('delivery_address2');
	var delivery_city = document.getElementById('delivery_city');
	var delivery_postalcode = document.getElementById('delivery_postalcode');
	var delivery_country = document.getElementById('delivery_country');
	var delivery_province = document.getElementById('delivery_province');
		
	valid = true;
	
	if( isMatchPassword(password,confirmpass, "Password do not match") )valid = false;
	
	if( isDeliveryProvince(delivery_province, "Required") )valid = false;
	if( isDeliveryCountry(delivery_country, "Required") )valid = false;
	if( isDeliveryPostalcode(delivery_postalcode, "Required") )valid = false;
	if( isDeliveryCity(delivery_city, "Required") )valid = false;
	if( isDeliveryAddress2(delivery_address2, "Required") )valid = false;
	if( isDeliveryAddress1(delivery_address1, "Required") )valid = false;
	
	if( isPostalProvince(postal_province, "Required") )valid = false;
	if( isPostalCountry(postal_country, "Required") )valid = false;
	if( isPostalPostalcode(postal_postalcode, "Required") )valid = false;
	if( isPostalCity(postal_city, "Required") )valid = false;
	if( isPostalAddress2(postal_address2, "Required") )valid = false;
	if( isPostalAddress1(postal_address1, "Required") )valid = false;
	
	if( isEmail(email, "Required") )valid = false;
	if( isTelephoneWork(telephone_work, "Required") )valid = false;
	if( isTelephoneHome(telephone_home, "Required") )valid = false;
	if( isIdno(id_no, "Required" ) )valid = false;
	if( isSurname(surname, "Required" ) )valid = false;
	if( isName(name, "Required" ) )valid = false;
	if( isTitle(title, "Required" ) )valid = false;

    return valid;
		
	
}

function isTitle(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('title_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('title_validate').innerHTML = '';
	}
	
}

function isName(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('name_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('name_validate').innerHTML = '';
	}
	
}


function isSurname(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('surname_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('surname_validate').innerHTML = '';
	}
	
}

function isIdno(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('id_no_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('id_no_validate').innerHTML = '';
	}
	
}

function isTelephoneHome(elem, helperMsg){
		if(elem.value.length == 0){
		document.getElementById('telephone_home_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('telephone_home_validate').innerHTML = '';
	}
	
}

function isTelephoneWork(elem, helperMsg){
		if(elem.value.length == 0){
		document.getElementById('telephone_work_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('telephone_work_validate').innerHTML = '';
	}
	
}

function isEmail(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('email_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('email_validate').innerHTML = '';
	}
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////
function isPostalAddress1(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_address1_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_address1_validate').innerHTML = '';
	}
	
}

function isPostalAddress2(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_address2_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_address2_validate').innerHTML = '';
	}
	
}

function isPostalCity(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_city_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_city_validate').innerHTML = '';
	}
	
}

function isPostalPostalcode(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_postalcode_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_postalcode_validate').innerHTML = '';
	}
	
}

function isPostalCountry(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_country_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_country_validate').innerHTML = '';
	}
	
}

function isPostalProvince(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('postal_province_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('postal_province_validate').innerHTML = '';
	}
	
}
////////////////////////////////////////////////////////////////////////////////////////////////
function isDeliveryAddress1(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_address1_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_address1_validate').innerHTML = '';
	}
	
}

function isDeliveryAddress2(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_address2_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_address2_validate').innerHTML = '';
	}
	
}

function isDeliveryCity(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_city_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_city_validate').innerHTML = '';
	}
	
}

function isDeliveryPostalcode(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_postalcode_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_postalcode_validate').innerHTML = '';
	}
	
}

function isDeliveryCountry(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_country_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_country_validate').innerHTML = '';
	}
	
}

function isDeliveryProvince(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('delivery_province_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('delivery_province_validate').innerHTML = '';
	}
	
}

function isPassword(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('password_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('password_validate').innerHTML = '';
	}
	
}

function isConfirmPass(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('confirmpass_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('confirmpass_validate').innerHTML = '';
	}
	
}

function isMatchPassword(new_p, confirm_p, helperMsg)
{
	if(new_p.value != confirm_p.value){
		document.getElementById('confirmpass_validate').innerHTML = helperMsg;
		confirm_p.focus(); // set the focus to this input
		return true;
	}
	else {
		document.getElementById('confirmpass_validate').innerHTML = '';
	}
	
}

function validate_password()
{
	var old_password = document.getElementById('old_password');
	var new_password = document.getElementById('new_password');
	var confirm_password = document.getElementById('confirm_password');
	var get_old_password = document.getElementById('get_old_password');
	
	
	valid = true;
	
	if( isConfirmPassword(confirm_password, "Required") )valid = false;
	if( isNewPassword(new_password, "Required") )valid = false;
	if( isOldPassword(old_password, "Required") )valid = false;
	if( isMatchOld(get_old_password,old_password, "- Old Password Incorrect") )valid = false;
	if( isMatchPassword(new_password,confirm_password, "Password do not match") )valid = false;
	
    return valid;
	
}

function isOldPassword(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('old_password_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('old_password_validate').innerHTML = '';
	}
	
}


function isNewPassword(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('new_password_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('new_password_validate').innerHTML = '';
	}
	
}

function isConfirmPassword(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('confirm_password_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('confirm_password_validate').innerHTML = '';
	}
	
}

function isMatchOld(get_p, p, helperMsg)
{
	if(get_p.value != p.value){
		document.getElementById('get_old_password_validate').innerHTML = helperMsg;
		p.focus(); // set the focus to this input
		return true;
	}
	else {
		document.getElementById('get_old_password_validate').innerHTML = '';
	}
	
}

function isMatchPassword(new_p, confirm_p, helperMsg)
{
	if(new_p.value != confirm_p.value){
		document.getElementById('confirm_password_validate').innerHTML = helperMsg;
		confirm_p.focus(); // set the focus to this input
		return true;
	}
	else {
		document.getElementById('confirm_password_validate').innerHTML = '';
	}
	
}

function validate_vacancy(){
	
	var name = document.getElementById('name');
	var surname = document.getElementById('surname');
	var email = document.getElementById('email');
	
	valid = true;
	
	if( isName(name, "Required" ) )valid = false;
	if( isSurname(surname, "Required" ) )valid = false;
	if( isEmail(email, "Required" ) )valid = false;

    return valid;
		
	
}

function isName(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('name_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('name_validate').innerHTML = '';
	}
	
}


function isSurname(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('surname_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('surname_validate').innerHTML = '';
	}
	
}


function isEmail(elem, helperMsg){
	if(elem.value.length == 0){
		document.getElementById('email_validate').innerHTML = helperMsg;
		elem.focus(); // set the focus to this input
		return true;
	}else {
		document.getElementById('email_validate').innerHTML = '';
	}
	
}

//Animated Collapsible DIV- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated Aug 1st, 07'. Fixed bug with "block" parameter not working when persist is enabled
//Updated June 27th, 07'. Added ability for a DIV to be initially expanded.

var uniquepageid=window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, "") //get current page path and name, used to uniquely identify this page for persistence feature

function animatedcollapse(divId, animatetime, persistexpand, initstate){
	this.divId=divId
	this.divObj=document.getElementById(divId)
	this.divObj.style.overflow="hidden"
	this.timelength=animatetime
	this.initstate=(typeof initstate!="undefined" && initstate=="block")? "block" : "contract"
	this.isExpanded=animatedcollapse.getCookie(uniquepageid+"-"+divId) //"yes" or "no", based on cookie value
	this.contentheight=parseInt(this.divObj.style.height)
	var thisobj=this
	if (isNaN(this.contentheight)){ //if no CSS "height" attribute explicitly defined, get DIV's height on window.load
		animatedcollapse.dotask(window, function(){thisobj._getheight(persistexpand)}, "load")
		if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
			this.divObj.style.visibility="hidden" //hide content (versus collapse) until we can get its height
	}
	else if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //just collapse content if CSS "height" attribute available
	if (persistexpand)
		animatedcollapse.dotask(window, function(){animatedcollapse.setCookie(uniquepageid+"-"+thisobj.divId, thisobj.isExpanded)}, "unload")
}

animatedcollapse.prototype._getheight=function(persistexpand){
	this.contentheight=this.divObj.offsetHeight
	if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes"){ //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //collapse content
		this.divObj.style.visibility="visible"
	}
	else //else if persistence is enabled AND this content should be expanded, define its CSS height value so slideup() has something to work with
		this.divObj.style.height=this.contentheight+"px"
}


animatedcollapse.prototype._slideengine=function(direction){
	var elapsed=new Date().getTime()-this.startTime //get time animation has run
	var thisobj=this
	if (elapsed<this.timelength){ //if time run is less than specified length
		var distancepercent=(direction=="down")? animatedcollapse.curveincrement(elapsed/this.timelength) : 1-animatedcollapse.curveincrement(elapsed/this.timelength)
	this.divObj.style.height=distancepercent * this.contentheight +"px"
	this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10)
	}
	else{ //if animation finished
		this.divObj.style.height=(direction=="down")? this.contentheight+"px" : 0
		this.isExpanded=(direction=="down")? "yes" : "no" //remember whether content is expanded or not
		this.runtimer=null
	}
}


animatedcollapse.prototype.slidedown=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==0){ //if content is collapsed
			this.startTime=new Date().getTime() //Set animation start time
			this._slideengine("down")
		}
	}
}

animatedcollapse.prototype.slideup=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==this.contentheight){ //if content is expanded
			this.startTime=new Date().getTime()
			this._slideengine("up")
		}
	}
}

animatedcollapse.prototype.slideit=function(){
	if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
		alert("Please wait until document has fully loaded then click again")
	else if (parseInt(this.divObj.style.height)==0)
		this.slidedown()
	else if (parseInt(this.divObj.style.height)==this.contentheight)
		this.slideup()
}

// -------------------------------------------------------------------
// A few utility functions below:
// -------------------------------------------------------------------

animatedcollapse.curveincrement=function(percent){
	return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
}


animatedcollapse.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
}

animatedcollapse.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

animatedcollapse.setCookie=function(name, value){
		document.cookie = name+"="+value
}
