/**
* @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
var ebiz = Venda.namespace("Ebiz");

/**
 * example function below
 * ebiz.myFunctionname = function(param1, param2) {
 *	..... Place function code here ....
 * }; 
 */

//2. declare function
ebiz.getIt = function (p1) {
	return p1 + 'TV.';
};
/*
 $(document).ready(function() {
    $('.Lpcatlinks li').hover(function() {
      $(this).addClass('topmenu-hover');
	   }, function() {
	   $(this).removeClass('topmenu-hover');
   });
 });
 */
 
 /**
   * Customize function for Client specif
  *  JQuery extension - function to grab the parameter from URL
 *  Ref - RT#100329
 */
 jQuery.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* @example value = $.getURLParam("paramName");
*/ 
 getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});
 /**
   * Customize function for Client specif
  *  Set condition to display Keyword search box on Header according with search parameter
  * Ref - RT#100329
 */

$(document).ready(function() {
var URL = $.getURLParam("termtextcatrestrict");
if(URL){
	if(URL == "retail"){
			$(".coloneretail").show();
			$(".coloneshoponline").empty();
	}
	else if(URL == "shoponline"){
			$(".coloneshoponline").show();		
			$(".coloneretail").empty();
	}
}
else{
		$(".coloneshoponline").empty();
		$(".coloneretail").empty();
}
});

/**
* Customize function to show/hide User Extended Field "USXTBROUGHT TEXT"
* Set condition to show/hide usxt input field according with Dropdown USXT
*/
$(document).ready(function() {
	showHideOtherBox();
	// see which browser we're working with
	if ($.browser.msie) {
	// ie doesn't pick up the option.click, so we'll have to use the select.change
	$('.usxtbrought').change(function(){
		showHideOtherBox();
	});
	}else { 
	// provide action for an option change
	$('.usxtbrought').click(function(){
			showHideOtherBox();
	});
	}
});
function showHideOtherBox(){
		if ($('.usxtbrought option:selected').text() =="Other"){
			$("#usxusxtbroughttext").show();
		}
		else{
			$("#usxusxtbroughttext").hide();
		}
}


/**
* Customize function to show/hide TITIEL OTHER TEXT Field "usxusxttitleother"
* Set condition to show/hide usxt input field according with Dropdown Title
*/
$(document).ready(function() {
	showHideTitleOther();
	// see which browser we're working with
	if ($.browser.msie) {
	// ie doesn't pick up the option.click, so we'll have to use the select.change
	$('#title').change(function(){
		showHideTitleOther();
	});
	}else { 
	// provide action for an option change
	$('#title').click(function(){
			showHideTitleOther();
	});
	}
});
function showHideTitleOther(){
		if ($('#title option:selected').text()=="Other"){
			$(".titleother").show();
		}
		else{
			$(".titleother").hide();
		}
}


Venda.Ebiz.addClass = function(selector, className) {	
   $(selector).ready(function() {$(selector).addClass(className)});
};

$(document).ready(function() {
	Venda.Ebiz.addClass("#listWeddinglist tr:odd","rowOdd");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#listWeddinglist tr:even","rowEven");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#manageWeddinglist tr:odd","rowOdd");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#manageWeddinglist tr:even","rowEven");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#boughtWeddinglist tr:odd","rowOdd");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#boughtWeddinglist tr:even","rowEven");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#reminderslist tr:odd","rowOdd");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#reminderslist tr:even","rowEven");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#addreminder tr:odd","rowOdd");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#addreminder tr:even","rowEven");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#editreminder tr:odd","rowOdd");
});
$(document).ready(function() {
	Venda.Ebiz.addClass("#editreminder tr:even","rowEven");
});

/**
* 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;
};