// JavaScript Document







function stripeMe() {
	$(".stripe-me tbody tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
	$(".stripe-me tbody tr:even").addClass("alt");
}


/* Original from: http://github.com/kvz/phpjs/raw/master/functions/strings/strpos.js  : BEGIN */
function strpos (haystack, needle, offset) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14

    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}
/* Original from: http://github.com/kvz/phpjs/raw/master/functions/strings/strpos.js  : END */





function destroyMessageBox() {
	setTimeout('$(".message-box").slideUp("slow", function(){ $(this).detach()});', 3000);
}






function highLightField(selector) {
	$(selector).focus(function() {
		$(this).addClass("form-field-active");
	}).blur(function() {
		$(this).removeClass("form-field-active");
	});
}




function image_loader(container, imageSrc, style) {
	var img = new Image();
	var maxWidth = $(container).width();
	var maxHeight = $(container).height();
	//alert ('document dimensions: ' + maxWidth + ' x '+ maxHeight);
	//$(container).css("height", maxHeight + "px").attr("height", maxHeight);
	$(container).addClass("loading");
	$(img).load(function () {
		$(this).hide();
		var imgWidth = $(this).attr("width");
		var imgHeight = $(this).attr("height");
		//alert ("Imagem dimensionss: " + imgWidth + ' x '+ imgHeight);
		
/*
		var displayWidth = $(container).width();
		var displayHeight = $(container).height();
		//alert ("display dimensions: " + displayWidth + ' x '+ displayHeight);

		if (displayHeight > maxHeight) {
			displayHeight = maxHeight;
		}
		if (displayWidth > maxWidth) {
			displayWidth = maxWidth;
		}
		var Xratio = imgWidth / displayWidth;
		var Yratio = imgHeight / displayHeight;
		
		var newWidth = 0;
		var newHeight = 0;
		if (Xratio < Yratio) {
			newWidth = (imgWidth / Xratio) | 0;
			newHeight = (imgHeight / Xratio) | 0;
		} else {
			newWidth = (imgWidth / Yratio) | 0;
			newHeight = (imgHeight / Yratio) | 0;
		}
	*/
		var newHeight = 0;
		var newWidth = 0;

		if (style == 0) {
			newWidth = imgWidth;
			newHeight = imgHeight;
			//alert("new dimensions: " + newWidth + " x " + newHeight);
			//alert("new dimensions: " + halfWidth + " x " + halfHeight);
		}
		if (style == 1) {
			//alert(style);
			var displayWidth = $(container).width();
			var displayHeight = $(container).height();
			if (displayHeight > maxHeight) {
				displayHeight = maxHeight;
			}
			if (displayWidth > maxWidth) {
				displayWidth = maxWidth;
			}
			//alert("Display: "  +displayWidth+ " x " + displayHeight);
			
			if ((imgHeight > displayHeight) || (imgWidth > displayWidth)) {
				Xratio = 1;
				Yratio =1;
				if (imgHeight > displayHeight) {
					Yratio = imgHeight / displayHeight;
				}
				if (imgWidth > displayWidth) {
					Xratio = imgWidth / displayWidth;
				}
				if (Xratio > Yratio) {
					newWidth = displayWidth;
					newHeight = (imgHeight / Xratio) | 0;
				} else {
					newHeight = displayHeight;
					newWidth = (imgWidth / Yratio) | 0;
				}
				//alert('New size: '+ newWidth + '  ' + newHeight);
				
			} else {
				newWidth = imgWidth;
				newHeight = imgHeight;
			}			
			//alert("new dimensions: " + newWidth + " x " + newHeight);
		}
		$(container + " img").each(function() {
			$(this).fadeOut().remove();
		});

		halfHeight = (newHeight / 2) | 0;
		halfWidth = (newWidth / 2) | 0;
		
		//alert(' Half: ' + halfWidth + '  ' + halfHeight);

		$(container).removeClass('loading').append(this);
		if (style == 0) {
			$(this).css({"margin-left": "-"+halfWidth+"px", "margin-top": "-"+halfHeight+"px"});
		}
		if (style == 1) {
			//alert("halves: " + halfWidth + " x " + halfHeight);
			$(this).attr({"width": newWidth, "height": newHeight}).css({"margin-left":"-"+halfWidth+"px"}).css({"margin-top":"-"+(halfHeight+1)+"px"});
		}


		$(this).fadeIn();
	}).error(function () {
		// notify the user that the image could not be loaded
	}).attr('src', imageSrc);
}







function OpenPopup(URL, width, height) {
	window.self.name = "main";
	var now = new Date();
	var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=1");
}
