/*
 * UtilitiesJS Package 0.1
 */

function verifyEmail(email) {
	// check for @
	i = email.indexOf("@");
	if (i == -1) return false;
	// separate the user name and domain
	var username = email.substring(0, i);
	var domain = email.substring(i + 1, email.length);
	
	// look for spaces at the beginning of the username
	i = 0;
	while ((username.substring(i, i + 1) == " ") && 
		(i < username.length)) {
		i++;
	}
	// remove any found
	if (i > 0) {
		username = username.substring(i, username.length);
	}

	// look for spaces at the end of the domain
	i = domain.length - 1;
	while ((domain.substring(i, i + 1) == " ") && (i >= 0)) {
		i--;
	}
	// remove any found
	if (i < (domain.length - 1)) {
		domain = domain.substring(0, i + 1);
	}
	
	// check for bad characters in the username
	var ch;
	for (i = 0; i < username.length; i++) {
	    ch = (username.substring(i, i + 1)).toLowerCase();
	    if (!(((ch >= "a") && (ch <= "z")) || 
	        ((ch >= "0") && (ch <= "9")) ||
	        (ch == "_") || (ch == "-") || (ch == "."))) {
	            return false;
	    }
	}
	
	// check for bad characters in the domain
	for (i = 0; i < domain.length; i++) {
	    ch = (domain.substring(i, i + 1)).toLowerCase();
	    if (!(((ch >= "a") && (ch <= "z")) || 
	        ((ch >= "0") && (ch <= "9")) ||
	        (ch == "_") || (ch == "-") || (ch == "."))) {
	            return false;
	    }
	}
	
	// Is there a . in domain name
	i = domain.indexOf(".");
	if (i == -1) return false;
	/*
	var bFoundSuffix = false;
	i = 0;
	while (i < aSuffix.length) {
	    if (("." + aSuffix[i]) == domain.substring(domain.length 
	- aSuffix[i].length - 1, domain.length)) {
	        return true;
	    }
	    i++;
	}
	*/
	
	return true;
}

function enlargeImage (source, width, height, altText) {
	if (altText==undefined) altText="";
	windowX = screen.width;
	windowY= screen.height;
	//image = new Image();
	//image.src = source;
	//imgWidth = image.width;
	//imgHeight = image.height;
	imgWidth = width;
	imgHeight = height;
	imgLeft = (windowX - imgWidth) / 2;
	imgTop = (windowY - imgHeight - 150) / 2;
	windowWidth = imgWidth + 20;
	windowHeight = imgHeight + 50;
	htmlCode = "<img src='"+ source + "' alt='"+ altText +"'/><br/>";
	htmlCode += "<div style='margin-top: 7px; text-align: center;'><a href='#' onclick='window.close();'>Pencereyi Kapat</a></div>";
	specs = "top=" + imgTop + ",left=" + imgLeft + ",width="+ windowWidth +",height="+ windowHeight;
	//alert (specs);
	imgWindow = window.open('','',specs);
	imgWindow.document.write(htmlCode);
	imgWindow.document.close();
}
