// JavaScript Document
var url="http://www.winterfieldsafes.co.uk/"
var title="Winterfield Safes - Making you Safer"
function addfave() {
if (document.all)
window.external.AddFavorite(url,title)}

function checkSearch(strng) {
	var error = "";

	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]@']/

	if (strng.match(illegalChars)) {
		return false;
	}

	return true;
}


function search_validator(theForm)
{

	if(theForm.txtSearch.value == "") {
		 alert("Please enter a search term.");
		 theForm.txtSearch.focus();
		 return(false);
	}
	
	if(theForm.txtSearch.value == "search here") {
		 alert("Please enter a valid search term.");
		 theForm.txtSearch.focus();
		 return(false);
	}
	
	if(theForm.txtSearch.value == " ") {
		 alert("Please enter a valid search term.");
		 theForm.txtSearch.focus();
		 return(false);
	}
	
	if(!checkSearch(theForm.txtSearch.value)) {
		 alert("Please use alpha-numeric characters only.");
		theForm.txtSearch.focus();
		 return false;

	}
	
	return (true);
}


function openUpload(whichImg,prodID) {
	myWindow = window.open("/admin/img-upload-form.asp?ProdID=" + prodID + "&WhichImg=" + whichImg , "UploadWindow", 'status,toolbar=no,scrollbar=no,width=250,height=100')
}



function viewPic(img)
{ 	
    picfile = new Image(); 
    picfile.src =(img); 
    fileCheck(img); 
}

function fileCheck(img)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        makeWindow(img); 
    }
    else 
    {
        funzione="fileCheck('"+img+"')"; 
        intervallo=setTimeout(funzione,50); 
    }
}

function makeWindow(img)
{ 	

	ht = picfile.height;
	wd = picfile.width;

	ht1 = picfile.height+20;
	wd1 = picfile.width;

    var args= "height=" + ht1 + ",innerHeight=" + ht1;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2; 
        var ycen = (avht - ht1) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes"; 	
    }
	popwin=window.open("","_blank",args)
	popwin.document.open()
	popwin.document.write('<html><head><title>Winterfield Safes</title></head><body onBlur=\"window.close() \" bgcolor=white scroll=no   topmargin=0 leftmargin=0 rightmargin=0 bottomargin=0 marginheight=0 marginwidth=0>  <div style="position: absolute; top:0px;left:0px"><img src="'+img+'" width="'+wd+'" height="'+ht+'" border="0"></div><div style="position: absolute; top:'+ht+'; width:'+wd+'; height:20px; background:#314E72;">&nbsp;<a href="javascript:window.close()" style="color:#ffffff;font: normal 12px/20px Arial, Verdana, Helvetica, sans-serif;">close</a></div></body></html>')
	popwin.document.close()
} 


function countSels() {
	theform = document.compform;
	thefield = theform.ProdID;
	
	var thislist = 0;
	for(a=0; a<(thefield.length); a++) {
		if (thefield[a].checked == true) {
			thislist = thislist +  1;
			if (thislist >= 5) {
				thefield[a].checked = false;
				alert("You can compare up to 4 products.");
				
			}
		}
	}

}

function checkComp() {
	theform = document.compform;
	thefield = theform.ProdID;
	
	var thislist = 0;
	for(a=0; a<(thefield.length); a++) {
		if (thefield[a].checked == true) {
			thislist = thislist +  1;
		}
	}
	if (thislist >= 5 || thislist == 0 || thislist == 1) {
		alert("You must select 2-4 products to compare.");
		return false;
	}else{
		return true;
	}
}