/**
* @fileoverview ebiz.js: A module used for client specific functionality
*
* This module defines a single symbol named "Venda.Ebiz"
* all ebiz utility functions are stored as properties of this namespace
* functions that are spacific this site shoudl be added to this file only.
*/

//Declare namespace for ebiz
Venda.namespace("Ebiz");
Venda.namespace("Ebiz.Search");

/**
 * Example function called 'getValue'.  
 * Venda.Ebiz.getValue = function(param1, param2) {
 *	..... Place function code here ....
 * };
 * PLEASE REMOVE THIS COMMENT BEFORE USING 
 */
Venda.Ebiz.Search.removeRefine = function(mapping) {
	if (typeof $ != "undefined") {
		$(mapping.selector).each(function() {
			if ($(this).html().indexOf(mapping.filter) != -1) {
				$(this).remove();
			}
		});
	}
};
YAHOO.util.Event.addListener(window,"load", function() {
	Venda.Ebiz.Search.removeRefine({
		selector: ".refinelist #collate .termtext",
		filter: "slider"
	});
});

/**
* This function is for setting col one to be equal to col content then set the banner to be aligned bottom.
*/
Venda.Ebiz.setEqualcol = function(){
	$(document).ready(function(){
		var contentHeight=0;
		if(document.getElementById("home-col-two")){contentHeight=document.getElementById("home-col-two").offsetHeight;}
		if(document.getElementById("col-two-no-three")){contentHeight=document.getElementById("col-two-no-three").offsetHeight;}
		if(document.getElementById("col-one")){
			if(document.getElementById("col-one").offsetHeight<contentHeight){
				$("div#col-one").css({"height":contentHeight+"px","position":"relative"});
				$("div.Lefthandpromo").css({"position":"absolute","bottom":0});
			}
		}
	});
};
Venda.Ebiz.setEqualcol();

/**
* Split a string so it can be displayed on multiple lines so it does not break display layout - used on order confirmation and order receipt page
* @param {string} strToSplit string that needs to be split
* @param {Integer} rowLen length of row which will hold the string
* @param {string} displayElem the html container which will display the splitted string
*/
Venda.Ebiz.splitString = function(strToSplit, rowLen, dispElem) {
	var stringlist = new Array();
	while (strToSplit.length > rowLen) {
		stringlist.push( strToSplit.slice(0,rowLen));
		strToSplit=strToSplit.substr(rowLen);
	}
	if (strToSplit.length) {
		stringlist.push(strToSplit);
	}
		document.getElementById(dispElem).innerHTML = stringlist.join('<br>');
};

/**
* A skeleton function for validating user extened fields - needs to be amended by the build team
* @param {object} frmObj HTML form containing user extended field elements
*/

Venda.Ebiz.validateUserExtendedFields = function(frmObj) {
/*	if(frmObj) {
		if ( (frmObj.usxtexample1.checked==false) && (frmObj.usxtexample2.checked==false) && (frmObj.usxtexample3.checked==false))  {
			alert("Please tick at least one checkbox");
			return false;
		}
		return true;
	}
	return false;
*/
	if (document.form) {
		if (document.form.usxthear) {
			if (document.form.usxthear.options[document.form.usxthear.selectedIndex].value != "Press (specify)" && document.form.usxthear.options[document.form.usxthear.selectedIndex].value != "Other") {
				document.getElementById("usxthearother").value = "";				
			}			
		}
		if (document.form.usxtage) {
			var num = document.form.usxtage.value;
			if(num.match("^[0-9]{1,2}$")){
				return true;
			} else {
				alert("Please enter a Age limit 1 - 99.");
				document.form.usxtage.focus();
				return false;				
			}
		}
	}
	return true;
};


var feedComcj = new CookieJar({expires:'',path: '/'});
	if(getUrlParam(window.location.href,'source')!=""){
		var feedComparamValue = getUrlParam(window.location.href,'source');
		var feedComCookie = feedComcj.put("source",feedComparamValue);
	}
/**
 * Gets the value of a specified URL parameter
 * @param {String} currURL 		this is the URL which you wish to get the URL parameter value from
 * @param {String} urlParam 	this is the name of the URL parameter you want to get the value for
 * @return match 							unescaped value for parameter specified urlParam if true else false
 */
function getUrlParam(url,urlParam) {
	//declare regular expression to be use.
	var re = new RegExp('[?&]'+urlParam+'=([^&]+)');
	var match = url.match(re);
	return match ? unescape(match[1]) : false;
};