function maskKeyPress(objEvent) 
{
    var iKeyCode;   
	if (objEvent.keyCode) { 
	iKeyCode = objEvent.keyCode; 
	} 
	else { 
	iKeyCode = objEvent.which; 
	}; 
    if((iKeyCode>=48 && iKeyCode<=57)||(iKeyCode==8)||(iKeyCode==46)) return true;
    return false;
}
function popup(url,winname,opt)
{
	var win = window.open(url,winname,opt);
	win.focus();
}

function frmSame(elem)
{
	var frm = document.regind;
	if(elem.checked)
	{
		frm.dtitle.selectedIndex=frm.title.selectedIndex;
		frm.dfirstname.value=frm.firstname.value;
		frm.dsurname.value=frm.surname.value;
		frm.daddress.value=frm.address.value;
		frm.dtown.value=frm.town.value;
		frm.dcity.value=frm.city.value;
		frm.dcounty.value=frm.county.value;
		frm.dpostcode.value=frm.postcode.value;
	}else{
		frm.dtitle.selectedIndex=0;
		frm.dfirstname.value='';
		frm.dsurname.value='';
		frm.daddress.value='';
		frm.dtown.value='';
		frm.dcity.value='';
		frm.dcounty.value='';
		frm.dpostcode.value='';
	}
}

function limit(objEvent,elem,maxchars,typ) 
{
	var iKeyCode;   
	if (objEvent.keyCode) { 
	iKeyCode = objEvent.keyCode; 
	} 
	else { 
	iKeyCode = objEvent.which; 
	};
    var strlen = elem.value.length;
	switch(typ) {
		case 'alphanum':
			if((strlen<maxchars && ((iKeyCode>=65 && iKeyCode<=90)||(iKeyCode>=97 && iKeyCode<=122)||(iKeyCode>=48 && iKeyCode<=57))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode>=37 && iKeyCode<=40))){return true;}	
			break;
		case 'num':
			if((strlen<maxchars && ((iKeyCode>=48 && iKeyCode<=57))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode>=37 && iKeyCode<=40))){return true;}
			break;
		case 'curr':
			//count decimal points
			//alert(elem.value);
			var char = '';
			var decCount = 0;
			for(i=0;i<strlen;i++)
			{
				char = elem.value.substring(i,i+1);
				//alert('char = ' + char);
				if(char=='.'){decCount++;}
			}
			//alert('decCount = ' + decCount);
			if((strlen<maxchars && ((iKeyCode>=48 && iKeyCode<=57))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode>=37 && iKeyCode<=40)))
			{
				if((decCount>0)&&(iKeyCode==46)){
					return false;
				}else{
					return true;
				}
			}
			break;
		case 'date':
			if((strlen<maxchars && ((iKeyCode>=47 && iKeyCode<=57)))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode>=37 && iKeyCode<=40)){return true;}
			break;
	}
	return false;
}

function charCount(elem,maxchars,updID)
{
	var fldlen = elem.value.length;
	if(fldlen>maxchars)
	{
		alert('The description field has a maximum of ' + maxchars + ' characters.');
		elem.value=elem.value.substring(0,maxchars);
		fldlen=maxchars;
	}
	eval('document.getElementById(\'' + updID + '\').innerHTML=fldlen;');
}
function fullimage(id)
{
	var win = window.open('/view-image/' + id + '.image','img' + id,'width=300,height=300,scrollbars=no');
	win.focus();
}
function jump(page,frm)
{
	eval('var theForm = document.' + frm + ';');
	theForm.page.value=page;
	theForm.submit();
}
function repImg(image)
{
	var newI =  new Image();
	newI.src = 'http://www.hplmotors.co.uk/productimages/' + image;
	document.getElementById('MainImg').src = 'http://www.hplmotors.co.uk/productimages/' + image;
	var img = document.getElementById("LrgImg");
	img.src = 'http://www.hplmotors.co.uk/productimages/' + image;
	
	//adjust shadow dimensions
	//img.src += '?' + img.width + img.height;
	adjustShadow(newI);
}

function modSelect(elem,modField,addAll)
{
	var make = elem.options[elem.selectedIndex].value;
	var fld = document.getElementById(modField);
	fld.options.length=0;
	
	if(modelsArray)
	{
		optStart=1;
		if(addAll){optStart=0;}
		for(i=0;i<modelsArray.length;i++)
		{
			mods = modelsArray[i];
			if(mods[0].toString() == make.toString())
			{
				if(addAll){fld.options[0]=new Option("All",-1);}
				for(s=1;s<mods.length;s++)
				{
					model_id = mods[s].substring(0,mods[s].indexOf(":"));
					modelname = mods[s].substring(mods[s].indexOf(":")+1);
					fld.options[s-optStart]=new Option(modelname,model_id);
				}
			}
		}
	}
	if(fld.options.length==0)
	{
		fld.options[0]=new Option("All",-1);
	}
}
function makeUpd(elem,modeldd,modelfld)
{
	if(!elem.value=='')
	{
		document.getElementById(modeldd).style.display='none';
		document.getElementById(modelfld).style.display='';		
	} else {
		document.getElementById(modeldd).style.display='';
		document.getElementById(modelfld).style.display='none';	
	}
	
}
function openImage()
{
	var imgcon = document.getElementById("LargeImage");
	var img = document.getElementById("LrgImg");
	imgcon.style.display='';
	//adjust shadow dimensions
	iw = img.width;
	ih = img.height;
	adjustShadow(img);
}
function closeImage()
{
	document.getElementById("LargeImage").style.display='none';
}
function adjustShadow(img)
{
	//var img2 = document.getElementById("LrgImg");
	//alert(img.height + ', ' + img.width);
	iw = img.width;
	ih = img.height;
	var shad = document.getElementById("shadow");
	shad.style.width = parseInt(iw) + 'px';
	shad.style.height = parseInt(ih) + 'px';
	//alert("shad.style.width = " + shad.style.width + ", shad.style.height = " + shad.style.height);
}