function check_Redirect(){var X_URL = location.href;var doRedirect=false;if (X_URL.indexOf('%5F')>-1){X_URL=X_URL.replace(/%5F/gi,'_');doRedirect=true;}if (X_URL.indexOf('index.asp')>-1){X_URL=X_URL.replace('index.asp','');doRedirect=true;}if (doRedirect==true){location.replace (X_URL);}}
check_Redirect();
function hi(which){
	window.defaultStatus = document.getElementById('pic' + which + 'l').href;
	window.status = document.getElementById('pic' + which + 'l').href;
//	document.getElementById('pic' + which + 't').style.border='1px solid #FF00BF';
//	document.getElementById('pic' + which + 't').style.borderBottom='1px dashed #BBBBBB';
//	document.getElementById('pic' + which + 'b').style.border='1px solid #FF00BF';
//	document.getElementById('pic' + which + 'b').style.borderTop='';
//	document.getElementById('pic' + which + 'b').style.background='url(/images/arrow_on.gif) 100% 100% no-repeat';
}
function lo(which){
	window.status ='';
	window.defaultStatus ='';
//	document.getElementById('pic' + which + 't').style.border='1px solid #BBBBBB';
//	document.getElementById('pic' + which + 't').style.borderBottom='1px dashed #BBBBBB';
//	document.getElementById('pic' + which + 'b').style.border='1px solid #BBBBBB';
//	document.getElementById('pic' + which + 'b').style.borderTop='';
//	document.getElementById('pic' + which + 'b').style.background='url(/images/arrow.gif) 100% 100% no-repeat';
}
var clHold=false;
function cl(which){
	if (!clHold){location.href = document.getElementById('pic' + which + 'l').href;}
}

function btncng(theImage){
	var imgSrc=theImage.src;
	if (imgSrc.indexOf('_on')>-1)
	{
		imgSrc=imgSrc.substr(0,imgSrc.indexOf('_on'))+'_off.gif';
	} else 
	{
		imgSrc=imgSrc.substr(0,imgSrc.indexOf('_off.gif'))+'_on.gif';
	}
	theImage.src=imgSrc;
//	document[imgName].src=imgSrc;
}

function testEmail(src){var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;return regex.test(src);}
function testInvalidChar(src){var regex = /[^a-z\d@\!\#\_\&\-\~. ]/i;return regex.test(src);}
function testInvalidChar2(src){var regex = /[^a-z\d@\!\&\_\-\~. ]/i;return regex.test(src);}

function preResetPageHeight()
{
	//alert('preResetPageHeight');
	try{
		var navDiv = document.getElementById('nav');
		var headerDiv = document.getElementById('header');
		var navODiv = document.getElementById('navO');
		var headerODiv = document.getElementById('headerO');
		var contentDiv = document.getElementById('content');
		
			//headerODiv.style.paddingBottom='0px';
			headerDiv.style.top = '-5000px';
			headerDiv.style.left = '-5000px';
			navDiv.style.top = '-5000px';
			navDiv.style.left = '-5000px';
	} catch(e){alert(e) }	
}

function resetPageHeight()
{
	try{
		var nHeight = document.getElementById('nav').offsetHeight;
		var pHeight = document.getElementById('content').offsetHeight;
		
		var headerDiv = document.getElementById('header');
		var headerODiv = document.getElementById('headerO');
		var navDiv = document.getElementById('nav');
		var navODiv = document.getElementById('navO');
		var navRDiv = document.getElementById('navR');
		var nav0RDiv = document.getElementById('nav0R');
		var contentDiv = document.getElementById('content');
		var nHeight = document.getElementById('nav').offsetHeight;
		var pHeight = document.getElementById('content').offsetHeight;

		nav0RDiv.innerHTML = navRDiv.innerHTML;

		//navDiv.style.display='block';
	//if (navDiv.offsetLeft > 200){alert();}
		if (headerDiv.offsetTop == '0' || navDiv.offsetLeft > 100 || navDiv.offsetLeft==-5000 || navRDiv.offsetLeft==-5000 || headerDiv.offsetLeft==-5000){
			headerODiv.innerHTML = headerDiv.innerHTML;
			navODiv.innerHTML = navDiv.innerHTML;
			headerODiv.style.height = (headerODiv.offsetHeight-12) + 'px';
			headerODiv.style.paddingTop='12px';
			headerODiv.style.marginBottom='0px';
			//headerODiv.style.paddingBottom='0px';
			headerDiv.style.top = '-5000px';
			headerDiv.style.left = '-5000px';
			contentDiv.style.paddingTop ='0px';
			navDiv.style.top = '-5000px';
			navDiv.style.left = '-5000px';
			navRDiv.style.top = '-5000px';
			navRDiv.style.left = '-5000px';
			nHeight = document.getElementById('navO').offsetHeight;
		}
//		window.status = navDiv.offsetLeft;
		
		if (nHeight>pHeight){document.getElementById('content').style.height = nHeight +'px';} else {document.getElementById('content').style.height='auto';}
	} catch(e){ }
}

function changeRPP(list){
	var url = location.href;
	var pos = -1;
	pos = url.indexOf('?rpp=');
//	alert(pos);
	if (pos>-1){
		url = url.substr(0,pos);
	}
	if (url.indexOf('?')>-1){
		//alert(url + '&rpp=' + list.options[list.selectedIndex].value);
		location.href=url + '&rpp=' + list.options[list.selectedIndex].value;
	} else {
		//alert(url + '?rpp=' + list.options[list.selectedIndex].value);
		location.href=url + '?rpp=' + list.options[list.selectedIndex].value;
	}
	
}

var arrayEmails=new Array();arrayEmails[0]=new Array();arrayEmails[0][0]='enquiries';arrayEmails[0][1]='sweetieworld.co.uk';
	function emailSW(thisLink,what,which){switch (which){case 0:thisLink.href='mai' + 'lto:' + arrayEmails[what][0] + '@' + arrayEmails[what][1];return true;break;case 1:window.status='mai' + 'lto:' + arrayEmails[what][0] + '@' + arrayEmails[what][1];return true;break;case 2:window.status='';return true;break;case 3:return arrayEmails[what][0] + '@' + arrayEmails[what][1];}}
	
	
var objxmlhttp;
function getHTTPRequest(url,processRequest) 
{
	try{
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			objxmlhttp = new XMLHttpRequest();
			if (processRequest){objxmlhttp.onreadystatechange = processHTTPRequest;}
			objxmlhttp.open("GET", url, true);
			objxmlhttp.send(null);
		} else if (window.ActiveXObject) {
			objxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			if (objxmlhttp) {
				if (processRequest){objxmlhttp.onreadystatechange = processHTTPRequest;}
				objxmlhttp.open("GET", url, true);
				objxmlhttp.send();
			}
		}
	} catch(err){}
}

function processHTTPRequest() 
{
    // only if req shows "complete"
    if (objxmlhttp.readyState == 4) {
        // only if "OK"
        if (objxmlhttp.status == 200) {
			if (objxmlhttp.responseText.indexOf('getRelatedItems - ')>-1){
				processRelatedItems(objxmlhttp.responseText);
			}
			if (objxmlhttp.responseText.indexOf('getSimilarItems - ')>-1){
				processSimilarItems(objxmlhttp.responseText);
			}
//			alert(xmlhttp.responseText);
			
        } else {
			//error occurred
        }
    }
}

function processRelatedItems(result){if (result!=''){document.getElementById('relatedItems').innerHTML = result.replace('getRelatedItems - ','');}}
function processSimilarItems(result){if (result!=''){document.getElementById('similarItems').innerHTML = result.replace('getSimilarItems - ','');}}

function changeSweetImage(src)
{
	document.getElementById('sweetimg').src=src;
}

function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  

  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return '';
}


var addr1 = 'Sweetie World Ltd';
var addr2 = '4 Bassett Court';
var addr3 = 'Bassett Avenue';
var addr4 = 'Southampton';
var addr5 = 'SO16 7DR';
var coNo = '06863671';
var VatNo = '982 6017 07';
function doAddress(which)
{
	if (which==1){
		return addr1 + '<br>' + addr2 + '<br>' + addr3 + '<br>' + addr4 + '<br>' + addr5; 
	} else if(which ==2){
		return addr1 + ', ' + addr2 + ', ' + addr3 + ', ' + addr4 + ', ' + addr5; 
	}
}


function pCase(fld)
{
	var str = fld.value;
	var strlen = str.length;
	var sMc=new Array("Mc","Mac");
	jj = str.substring(0,1).toUpperCase();
	jj = jj + str.substring(1,strlen).toLowerCase();
	for (i = 1; i <= strlen; i++) {
		if (jj.charAt(i)==" " || jj.charAt(i)=="-" || jj.charAt(i)=="'" || jj.charAt(i)=="(") {
			lefthalf = jj.substring(0,i+1);
			righthalf = jj.substring(i+1,strlen);
			righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen);
			jj=lefthalf+righthalf;
		}
	}
	for (var s=0; s<sMc.length; s++) {
		if (jj.indexOf(sMc[s])>-1){
			i = jj.indexOf(sMc[s]);
			lefthalf = jj.substring(0,i+sMc[s].length);
			righthalf = jj.substring(i+sMc[s].length,strlen);
			righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen);
			jj=lefthalf+righthalf;
		}
	}
	
	fld.value = jj;
}