/**
* @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.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>'); 
   }; 
//Remove function from general.js to Ebiz.js 
//order confirmation and order receipt page - split the email address on the RHN if too long
function splitEmailAdd(usemail) {
	var stringlist = new Array();
	while (usemail.length > 30) {
	   stringlist.push( usemail.slice(0,30));
	   usemail=usemail.substr(30);
	}
	if (usemail.length) {
	  stringlist.push(usemail);
	}
	document.write(stringlist.join( '<br>' ));
}

// Variables for dynamic nav
turnonToggle = 1; //change this to 0 if you don't want to use toggling
// Bullet images
// change path to the desired location
shown = new Image();
shown.src = "/venda-support/images/bulleton.gif";
hidden = new Image();
hidden.src = "/venda-support/images/bulletoff.gif";
//following function to be removed when RT#98865 in stable
function dynamicContent(where,what) {
	// find out what tag the function is called from so the correct value is passed for url
	identifyTag = where.tagName;
	if (identifyTag == "A"){
		ajaxFunction(where+'&layout=noheaders&temp=subcategories',what);
		if (turnonToggle == 1){toggle(where);}
	} else if (identifyTag == "INPUT" || identifyTag == "SELECT") {
		ajaxFunction(where.value,what);
	}
};

//Description: Returns the value of a specified URL parameter 
//Parameters:
//1. currURL = this is the URL which you wish to get the URL parameter value from
//2. urlParam = this is the name of the URL parameter you want to get the value for
//Returns: value for parameter specified urlParam.
function grabURL(currURL,urlParam) {
	//find out a value where is passed from current url
	var url = unescape(currURL);
	var spliter = '&';
	var sField = spliter+urlParam+'=';
	
	if (url.search(sField) == -1) {               
		sField = '?'+urlParam+'=';         
	}
	
	var urlArray = url.split(sField);
	if (urlArray[1]) {
		//get url param value
		var paramArray = urlArray[1].split(spliter);
		return(paramArray[0]);
	}
}

//This function is  for validating  userextendedfiields on registration and edit profile page. You may edit this to suit your user extended fields.
// frmObj is the  form  object in which the user extended fields reside.
function validateUserExtendedFields(frmObj) {
	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;
}

function validateQty(iform){
var iNum = /\D/;
var qty = iform.qty;

    if(iNum.test(qty.value)==true){
        alert("Please enter numbers only");
        return false;
    }
    else if(qty.value < "1"){
        alert("Please enter numbers more than 0."); 
    }
    else{
         iform.submit();
    }		
}	

// This function is used for defaulting the quantity to 1 or to make the quantity positive incase the user enters it wrong by mistake
function qtyValidate(thisBox,item){
  var regExp = /\D/g;
  var nonNum= thisBox.value.match(regExp);

    if(item > 0) {
        if ((nonNum != null) && (nonNum.length > 0) || (thisBox.value == "")) {
             thisBox.value = item;       
        }
    }else{
        if ((nonNum != null) && (nonNum.length > 0) || (thisBox.value == 0)) {
            thisBox.value = 1;        
        }
    }

}

$(document).ready(function(){
	$("#yourbasket table tbody tr:first").addClass("first");
	$(".orderitems table tbody tr:first").addClass("first");
	$(".topnavigation ul li:first").addClass("first");
	$("#giftwrap table tbody tr:first").addClass("first");
	$(".categorynavigation ul li:first").addClass("first");	
	$(".categorynavigation ul li:last").addClass("last");	
}); 
/**/
/*Equal Height col-one and col-two-three, base sources code from v2.1.0 by PVII-www.projectseven.com*/

 Venda.Ebiz.P7_colH2 = function(){
 var i,oh,h=0,tg,el,np,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
 for(i=1;i<dA.length;i+=2){dA[i+1].style.paddingBottom='';}for(i=1;i<dA.length;i+=2){
 oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=1;i<dA.length;i+=2){oh=dA[i].offsetHeight;
 if(oh<h){np=h-oh;if(!an&&dA[0]==1){Venda.Ebiz.P7_eqA2(dA[i+1].id,0,np);}else{
 dA[i+1].style.paddingBottom=np+"px";}}}document.p7eqa=1;
 document.p7eqth=document.body.offsetHeight;
 document.p7eqtw=document.body.offsetWidth;}
};

 Venda.Ebiz.P7_eqT2 = function(){
 if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){Venda.Ebiz.P7_colH2();}
};

 Venda.Ebiz.P7_equalCols2 = function(){
 var c,e,el;if(document.getElementById){document.p7eqc=new Array();
 document.p7eqc[0]=arguments[0];for(i=1;i<arguments.length;i+=2){el=null;
 c=document.getElementById(arguments[i]);if(c){e=c.getElementsByTagName(arguments[i+1]);
 if(e){el=e[e.length-1];if(!el.id){el.id="p7eq"+i;}}}if(c&&el){
 document.p7eqc[document.p7eqc.length]=c;document.p7eqc[document.p7eqc.length]=el}}
 setInterval("Venda.Ebiz.P7_eqT2()",10);}
};

Venda.Ebiz.P7_eqA2 = function(el,p,pt){
 var sp=10,inc=20,g=document.getElementById(el);np=(p>=pt)?pt:p;
 g.style.paddingBottom=np+"px";if(np<pt){np+=inc;
 setTimeout("Venda.Ebiz.P7_eqA2('"+el+"',"+np+","+pt+")",sp);}
};

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

