/**
* file: imageUtils.jsp
* descr: image utils. Handle the change image on mousehover and mouseout of link
* date: 11 Apr 2002
* author: Michele Lazzeri
*/


// load the home image
var homeImage = new Image();

var gotolink = "#"
var currentImg=0
var currentLink = "#"

// the immage collection an the current link
var myImages=new Array()

// change the image. if imageIndex is -1 set the home Image
function changeimage(imageIndex,url){
 currentImg = imageIndex
 currentLink = url
 if (document.images.targetimage && myImages[imageIndex]) document.images.targetimage.src = myImages[imageIndex].src
 gotolink = url
}

// go to Current
function goToCurrent(){
 if (document.images && myImages[currentImg]) {
 	 document.images.targetimage.src = myImages[currentImg].src;
 gotolink = currentLink
 }
}


// go to home Image
function goToHomeImage(){
 if (document.images) document.images.targetimage.src = homeImage.src;
 gotolink = "#"
}

// Set the home Image
function setHomeImage(homeImageSrc){
 homeImage.src = homeImageSrc;
}

// open the link
function warp(){
 window.location = gotolink
}

// preload the image
function preloadimages(){


 for (i = 0;i < preloadimages.arguments.length; i++){
  myImages[i] = new Image()
  myImages[i].src = preloadimages.arguments[i]
 }

 setHomeImage(preloadimages.arguments[0]);
}

// open a empty popup and put on it the form result 
// tgt = target
// frm = the form target
// w = whidth
// h = height 
function popUpForm(tgt,frm,w,h,em){
	if (!(em === null)) {
		if (checkEmailAddress(em) != 1) {
			alert("Controlla indirizzo email: '"+em+"' non è valido");
			return;
		}	
	}
	var neww = window.open("",tgt,
		"titlebar=no,height="+h+",width="+w+",scrollbars=no,status=no,resizable=no,alwaysRaised=yes,screenX=20,screenY=20");
	neww.window.focus();
	frm.submit();
}


// open a popup for images 
// imgPath = the image path
// w = whidth
// h = height 
function popUpImage(imgPath,w,h){
	var neww = window.open(imgPath,"_new",
		"titlebar=no, height="+h+", width="+w+",scrollbars=no,status=no,resizable=no,alwaysRaised=yes");
	neww.window.focus();
}


// check if an email is OK 
// email = the email address
function checkEmailAddress(email){

	// one and only one @
	var chiocciolaPos = email.indexOf("@");
	if (chiocciolaPos == -1) return -1;

	var domain = email.substr(chiocciolaPos+1);
	
	// no @ in the domain
	if (domain.indexOf("@") != -1) return -1;
	
	// at least a dot in the domain
	var dotPos = email.indexOf(".");
	if  (dotPos == -1) return -1;
	
	// at least a char after the first dot
	var afterdomain = email.substr(dotPos+1);
	if  (afterdomain == "") return -1;
	
	// probably is OK
	return 1;
}