//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 > 50) {
           stringlist.push( usemail.slice(0,50));
           usemail=usemail.substr(50);
        }
        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(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;*/
}

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

}

/**
* @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");

/**
 * Example function called 'getValue'.
 * Venda.Ebiz.getValue = function(param1, param2) {
 *      ..... Place function code here ....
 * };
 * PLEASE REMOVE THIS COMMENT BEFORE USING
 */
 /**
 * 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) {
	 var phonenumber = frmObj.usxtrecage.value;
	 regExp = /[^\d/+/]/;
	 if ((regExp.test(phonenumber))==true){
			alert("Your age can only contain 0-9");
			return false;
		}			
	if ((frmObj.usxtrecage.value.length)>3){
			alert("Your age can contain less than 3 digits");
			return false;
	}	
	} 
	return true;
}

Venda.Ebiz.getPostcodePrefix  = function(frmVal) {
	var postCodeStem = frmVal;
	
	// trim all spaces. 
	postCodeStem = postCodeStem.replace(/^\ +/, ''); 
	postCodeStem = postCodeStem.replace(/\ +$/, ''); 

	if (postCodeStem != "" && postCodeStem.length >= 2) {
		postCodeStem = postCodeStem.substr(0, 2);
	}
	return postCodeStem;
};
 

