function gotoandclose(url)
{
top.opener.location.href = url
window.close()
}

function windowPopUp(url, name, args)
{
	if (typeof(popupWin) != "object"){
		popupWin = window.open(url,name,args);
    } else {
		if (!popupWin.closed){
			popupWin.location.href = name;
        } else {
			popupWin = window.open(url,name,args);
        }
	}
    
}


function putFocus(formInst, elementInst) 
{
  if (document.forms.length > 0) 
{
   document.forms[formInst].elements[elementInst].focus();
}
}
 
 
function convertupper()
{
    document.addmessage.messagetext.value = document.addmessage.messagetext.value.toUpperCase();
}

function convertobjupper(frmObj)
{
    frmObj.value = frmObj.value.toUpperCase();
}

function convertlower()
{
    document.addmessage.messagetext.value = document.addmessage.messagetext.value.toLowerCase();
}

function convertobjlower(frmObj)
{
    frmObj.value = frmObj.value.toLowerCase();
}

function changeCase(frmObj)
{
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if ((tmpChar == " " || tmpChar == "\n") && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
frmObj.value = tmpStr;
}

function cmdTownLookup_OnClick()
{
	var strQuery, strTemp;
	
	strQuery="";
	
	strTemp = document.addressform.address2.value;

	strCountry = document.addressform.countrylist.options[document.addressform.countrylist.selectedIndex].value;

	if(strTemp != "")
	{
		if(strQuery != "") strQuery = strQuery + "&";
		strQuery = strQuery + "town=" + EncodeSpaces(strTemp);
	}

	if(strTemp != "")
	{
		if(strQuery != "") strQuery = strQuery + "&";
		strQuery = strQuery + "countryid=" + strCountry;
	}	
	
	windowPopUp('/sales/address/intltownsearch.asp?' + strQuery, 'TownLookup', 'toolbar=no,height=350,width=600,status=no,scrollbars=yes,resizable=yes,copyhistory=no,menubar=no');
}

function cmdLookup_OnClick()
{
	var strQuery, strTemp;
	
	strQuery="";
	
	strTemp = document.addressform.address1.value;

	if(strTemp != "")
	{
		if(strQuery != "") strQuery = strQuery + "&";
		strQuery = strQuery + "street=" + EncodeSpaces(strTemp);
	}

	strTemp = document.addressform.address3.value;

	if(strTemp != "")
	{
		if(strQuery != "") strQuery = strQuery + "&";
		strQuery = strQuery + "town=" + EncodeSpaces(strTemp);
	}

	strTemp = document.addressform.address5.value;
	
	if(strTemp != "")
	{
		if(strQuery != "") strQuery = strQuery + "&";
		strQuery = strQuery + "postcode=" + EncodeSpaces(strTemp);
	}
	
	windowPopUp('/sales/address/postcode.asp?' + strQuery, 'Lookup', 'toolbar=no,height=350,width=600,status=no,scrollbars=yes,resizable=yes,copyhistory=no,menubar=no');
}

function EncodeSpaces(strSource)
{
	var nLength, nLooper, strDest, strTemp;
	
	strDest="";
	nLength=strSource.length;
	if(nLength ==0) return "";	
	for(nLooper=0;nLooper<nLength;nLooper++)
	{	
		strTemp=strSource.substring(nLooper, nLooper+1);
		if(strTemp == " ")
			strDest = strDest + "+";
		else
			strDest = strDest + strTemp;
	}
	return strDest;
}

function popitup(url,name)
{
	var newwindow = '';
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,name,'toolbar=no,location=no,height=400,width=640,status=no,scrollbars=yes,resizable=no,copyhistory=no,menubar=no');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function popitupsmall(url,name)
{
	var newwindow = '';
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,name,'toolbar=no,location=no,height=450,width=325,status=no,scrollbars=no,resizable=no,copyhistory=no,menubar=no');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

