// JavaScript Document



//email-a-friend function
function emailPage(URLStr, left, top, width, height) {
/********************************************
DESCRIPTION: emails a friend
DATE ADDED: 10th November 2007
*********************************************/
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function emailPageCheck(emailOne, emailTwo) {
/********************************************
DESCRIPTION: email-a-page-to-a-friend check
DATE ADDED: 10th November 2007
*********************************************/

	if (!emailValid(emailOne)) {
		return false;
	}
	if (!emailValid(emailTwo)) {
		return false;
	}
	return true;
}

function emailValid(email) {
/********************************************
DESCRIPTION: email address validator
DATE ADDED: 10th November 2007
*********************************************/
	
	// email validation
	var field = email; // email field
  	var str = field.value; // email string
  	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid (doesnt validate emails with long tld, e.g. .name)
  	if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
		return true;
  	}
  	else {
		alert("Please enter a valid email address."); 
		field.focus();
		field.select();
		return false;
  	}
}

function deleteItem(ID) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 5th April 2007
DATE UPDATED: -
*********************************************/
	
	document.frm_item.a.value = 3; //delete
	document.frm_item.step.value = 1; //wizard start
	document.frm_item.remove.value = ID;
	if (confirm("You are about to delete this item.\n\nAre you sure you want to continue?")) {
		document.frm_item.submit();
	}
}

function doItem(action) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 5th April 2007
DATE UPDATED: -
*********************************************/
	
	document.frm_item.a.value = action;
	document.frm_item.step.value = 1;
	document.frm_item.submit();
}

function selectItem(pID, ID, nID, stepID) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 6th April 2007
DATE UPDATED: -
*********************************************/
	document.frm_item.prev_id.value = pID;
	document.frm_item.item_id.value = ID;
	document.frm_item.next_id.value = nID;
	document.frm_item.step.value = stepID;
	document.frm_item.submit();
}

function selectItemExtra(pID, ID, nID, stepID, extraID) {
/********************************************
DESCRIPTION: updates action and submits page
DATE ADDED: 6th April 2007
DATE UPDATED: -
*********************************************/
	document.frm_item.prev_id.value = pID;
	document.frm_item.item_id.value = ID;
	document.frm_item.next_id.value = nID;
	document.frm_item.step.value = stepID;
	document.frm_item.extra_id.value = extraID;
	document.frm_item.submit();
}


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


jQuery.getScriptCache = function(src, callback) {
	jQuery.ajax({
		cache: 		true,
		type: 		"GET",
		url: 		src,
		dataType: 	"script",
		success: 	callback
	});
};
/*
if (!window.noSurvey) {
	var scriptDir = jQuery('head script[src*="jquery"]')[0].src.split('/').slice(0,-1).join('/')+'/';
	jQuery.getScript(scriptDir + "survey.js");
}	*/