//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>' ));
}


//dynamic nav script
turnonToggle = 1; //change this to 0 if you don't want to use toggling
// preload controls
// 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";

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

function replaceUnloadImage() {
	// Start create variable to check Browser
	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();
	// End create variable to check Browser
	
	var noimg = "/venda-support/images/spacer.gif";
	if (document.getElementsByTagName) { //  detect this function first
		var images = document.getElementsByTagName("img");
		for (var i = 0; i < images.length; i++) {
			if (images[i].className.match("icon")) {
				var preload = new Image();
				preload.src = images[i].src;
				if (preload.src == "") {
					images[i].src = noimg;
				} else {
					if (BrowserDetect.browser=="Explorer") {
						if (!images[i].complete) {
							images[i].src = noimg;
							images[i].alt = "";
						}
					} else {
						if (!preload.complete) {
							images[i].src = noimg;
							images[i].alt = "";
						}
					}
				}
			}
		}
	} else {
		return false;						 
	} 
}

function getCurPage(cur_form){
	
	var cur_url = location.href;
	var found = cur_url.indexOf("&log=4");
	if (found > 0) {
		cur_url = cur_url.substring(0,cur_url.indexOf("&log=4"));
	}
	found=0;
	found = cur_url.indexOf("page/");
	var valid = false;
	// Page
	if (found > 0) {
		cur_url = cur_url.substring(found + 5,cur_url.length);
		cur_form.page.value = cur_url;
		valid = true;
	} else {
		found = cur_url.indexOf("icat/");
		// Icat
		if (found > 0) {
			cur_url = cur_url.substring(found + 5,cur_url.length);
			cur_form.icat.value = cur_url;
			valid = true;
		} else {
			found = cur_url.indexOf("bin/");
			// bin/venda
			if (found > 0) {
				var my_array = cur_url.split("&");
				for (i=0; i<my_array.length; i++) {
					cur_obj = my_array[i].split('=');
					if ((cur_obj[0] == "page") && (cur_obj[1].length > 0)) {
						cur_form.page.value = cur_obj[1];
						valid = true;
					} else if ((cur_obj[0] == "icat") && (cur_obj[1].length > 0)) {
						cur_form.icat.value = cur_obj[1];
						valid = true;
					}
				}
				if (!valid) {
					cur_url = location.href;
					cur_form.searchparameters.value = cur_url.substring(cur_url.indexOf("/bin"),cur_url.length);
					cur_form.page.value = "predirect";
					valid = true;
				}
			} else {
				cur_form.page.value = "home";
				valid = true;
			}
		}
	}
	if (valid) {cur_form.submit();}
}

// set equalheight box productlist
function setequalheight(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	//return (arrReturnElements)
	var divs = arrReturnElements;
	//alert (divs.length);
	var maxHeight=0;
	for(i=0;i<divs.length;i++){
		//alert(a[i].offsetHeight);
		maxHeight = Math.max(maxHeight,divs[i].offsetHeight);
	}
	for(i=0;i<divs.length;i++){
		if(navigator.appName == "Microsoft Internet Explorer"){
			divs[i].style.height=maxHeight+"px";
		}else{
			divs[i].style.minHeight=maxHeight + "px";
		}
	}
	
}
// ---
// Array support for the push method in IE 5
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}




//    Start  RT  9198   
function setCookies(name, value, expires, path, domain, secure) { 
	 var curCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() : "") + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : ""); 
	 document.cookie = curCookie; 
}

function deleteCookies(name, value) {	
	 // now delete the test cookie 
	  exp = new Date(); 
	  exp.setTime(exp.getTime() - (24*60*60*1000)); 
  
	  exp = "Thu, 01-Jan-70 00:00:01 GMT";
	  setCookies(name, value, exp, "/", false, false); 	  
 }
	
function addCookies(name, value) { 
	 var exp = new Date(); 
	 exp.setTime(exp.getTime() + (24 * 60 * 60 * 1000)); 

	 exp = "";
	 setCookies(name, value, exp, "/", false, false); 
}

function getCookie(name)
{
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos);
		if (endpos == -1) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
	}
	else
	{
		return false; // the cookie couldn't be found! it was never set before, or it  expired.
	}
}

function Swapcontent(show, eid, classname1, classname2) {
	if (eid != '') {
		//   if user is in staff page or logged in from staff page
		if (show == true) {
			document.getElementById(eid).className = classname1;
		}
		//   if user is in normal sign in page or logged in from normal sign in page
		else {
			document.getElementById(eid).className = classname2;
		}
	}
}

function swapGuestGroup(show, eid, classname1, classname2, curusgrref, fixusgrref) {
	if (eid != '') {
		//   if user is in staff page or logged in from staff page
		if (show == true) {
			document.getElementById(eid).className = classname1;
		}
		//   if user is in normal sign in page or logged in from normal sign in page
		else {
			//   if user  group is  bbcstaffgroup
			if (curusgrref == fixusgrref) {
				document.getElementById(eid).className = classname1;
			}
			else {
				//   if user did not log in from staff page and user group <> bbcstaffgroup
				document.getElementById(eid).className = classname2;
			}
		}
	}
}
//    End  RT  9198   

function popup(url,width,height,name) {
    if (width == '' || width == null) width = 400;
    if (height == ''|| height == null) height = 425;
    if (name == '' || name == null) name = "details";
    var props = "toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,titlebar=no,menubar=no,width="+width+",height="+height;
    w = window.open(url, name, props);
    if (w) w.focus();
}

function addOnloadEvent(fnc) {
    if ( typeof window.addEventListener != "undefined" )
        window.addEventListener( "load", fnc, false );
    else if ( typeof window.attachEvent != "undefined" ) {
        window.attachEvent( "onload", fnc );
    }
    else {
         if ( window.onload != null ) {
         var oldOnload = window.onload;
            window.onload = function ( e ) {
            oldOnload( e );
            window[fnc]();
            };
        }
        else
            window.onload = fnc;
    }
}