$(document).ready(function(){
	$('#photoGalleryWrap a').lightBox({
		imageLoading: SITE_URL+'/_images/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev: SITE_URL+'/_images/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext: SITE_URL+'/_images/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose: SITE_URL+'/_images/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank: SITE_URL+'/_images/lightbox/lightbox-blank.gif'			// (string) Path and the name of a blank image (one pixel)
	});

	// close notify error
	$(".close").click(
		function () {
			$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
				$(this).slideUp(400);
			});
			return false;
		}
	);

	// add red color for request field
	$('label:contains("*")').each(function(){$(this).html($(this).html().replace('*','<span>*</span>'));});

	$("a[ref='myPopup']").click(function() {
		$.nyroModalManual({
			width: 678,
			height: 510,
			overflow: "hidden",
			forceType: "iframe",
			url: $(this).attr("href")
		});
		return false;
	});

	$.nyroModalSettings({
		overflow: "hidden"
	});

	$('#nav ul li').hover(
		function() {
			var hasClass = $(this).hasClass('actived');
			if(!hasClass) {
				$('#nav ul li.actived  div ul li').hide();
			}
		},function() {
			$('#nav ul li.actived div ul li').show();
		}
	)
})


function validateForm(form, validate){
	var oInput, sName, sTest, bReq, msg = "";
	var pairs = validate.split(",");
	var oName, oType, aTest, ant = "";
	for(i in pairs){
		aTest = "";
//		oInput = eval("document." + form + ".elements['" + pairs[i].split("=")[0] + "']");
		oInput = eval("document.getElementById('" + pairs[i].split("=")[0] + "')");
		oType = oInput.type;	//alert(oType);
		oName = pairs[i].split("=")[0];
		sName = pairs[i].split("=")[1];
		sTest = pairs[i].split("=")[2];
		bReq = eval(pairs[i].split("=")[3]);
		msg += validateInput(oInput, sName, sTest, bReq);

		if(oType=="radio") {
			oInput = eval("document." + form + ".elements['" + pairs[i].split("=")[0] + "']");
			aTest = checkRadio(oInput);
			if(aTest != ""){ msg += sName + ": " + aTest + "\n"}
			oInput = document.getElementById(oName).parentNode;
		}

		if(validateInput(oInput, sName, sTest, bReq) || aTest!="") {
			addClassName(oInput,"error");
			//throwError = true;
		} else {
			if(hasClass( "error", (oInput.className || oInput).toString().split(/\s+/) ) > -1) {
				delClassName(oInput,"error");
			}
		}
		// if(throwError) document.getElementById("error").innerHTML = "Your form is incomplete. Please see highlighted fields below to correct.";
	}

	if(msg != ""){
		if(jqry){
			msg = msg.replace(/\n/g, "<br>")
			msg = "Your form is incomplete. <br/>"+msg;
			if($('#msgbox').length == 0) {
				jalert(msg);
			}else{
				showMsg(msg);
			}
			return false;
		}
		alert(msg);
		return false;
	}
	return true;
}

