/*
	JavaScript functions
	********************
	Created: 27 jan 2009
	Author: Victor Rosu (victor@redpx.ro, victor@cerebralart.ro)
*/

var emailRegEx = /^[a-zA-Z0-9._%+-]+@[A-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;

function clearField(id) {
	$(id).value = "";
} // end function()

function setFieldValue(id, txt) {
	if($(id).value == "") {
		$(id).value = txt;
	}
} // end function()

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");

}
function fieldVar(text) {
	return escape(trim(text));
}

// goto Page
function gotoPage(url) {
	document.location.href = url;
}

// Scroll
var cursor = 0;
var viteza = 15;
var timeID;
var scroller = {
	sus: function(id) {
		cursor = (cursor - viteza)<0 ? 0 : (cursor-viteza);
		$(id).scrollTop = cursor;
		timeID = setTimeout("scroller.sus('"+id+"')", 60);
	},
	jos: function(id) {
		cursor += viteza;
		$(id).scrollTop = cursor;
		timeID = setTimeout("scroller.jos('"+id+"')", 60);
	},
	stanga: function(id) {
		cursor = (cursor - viteza)<0 ? 0 : (cursor-viteza);
		$(id).scrollLeft = cursor;
		timeID = setTimeout("scroller.stanga('"+id+"')", 60);
	},
	dreapta: function(id) {
		cursor += viteza;
		$(id).scrollLeft = cursor;
		timeID = setTimeout("scroller.dreapta('"+id+"')", 60);
	},
	restart: function() {
		clearTimeout(timeID);	
	}
}

function checkContact() {
	var f1 = $F("contactName");
	var f2 = $F("contactEmail");
	var f3 = $F("contactMessage");
	
	if(f1 == "" || f1 == "my name")
		alert("Name is required!");
	else if(f2 == "" || f2.search(emailRegEx) == -1)
		alert("Email is required!");
	else if(f3 == "" || f3 == "i like to say...")
		alert("Please write us a message!");
	else {
		document.contactFrm.action = "/actions.php?action=contact_submit";
		document.contactFrm.submit();
	}
}

var client = {
	over: function(id, src) {
		$("client" + id).src = src;
		$("clientName" + id).style.display = "block";
	},
	out:  function(id, src) {
		$("client" + id).src = src;
		$("clientName" + id).style.display = "none";
	}
}

var cstud = {
	over: function(id, src) {
		$("cstud" + id).src = src;
	},
	out:  function(id, src) {
		$("cstud" + id).src = src;
	}
}

var projindex = {
	over: function(id) {
		$("projImage" + id).style.opacity = 1;
		$("projName" + id).style.display = "block";
	},
	out: function(id) {
		$("projImage" + id).style.opacity = 0.6;
		$("projName" + id).style.display = "none";
	}
}

function newsArchiveSlide(id) {
	//new Effect.toggle(id, "slide", {duration:0.7});
	var elements = $("theNewsContent").getElementsByClassName("newsArchiveItems");
	for(var i=0; i<elements.length; i++) {
		elmsid = elements[i].id;
		if($(elmsid).style.display == "block" || $(elmsid).style.display == "")
			new Effect.SlideUp(elmsid, {duration:0.7});
	}
	new Effect.toggle(id, "slide", {duration:0.7});
	delete elements;
}

function setFilename(id) {
	$("fakefield" + id).value = $("cvField" + id).value;
}

function checkCareersForm(id) {
	var f1 = $F("cvField" + id);
	if(f1 != "") {
		$("careersSubmitForm" + id).action = "/actions.php?action=submit_cv&id=" + id;
	}
	else {
		alert("To submit your CV please select a file!");
	}
}

function checkAgency() {
	var f2 = $F("emailAP");
	if(f2 == "" || f2.search(emailRegEx) == -1) {
		alert("Wrong email address\nPlease check the address.");
		$("emailAP").value = "e-mail address";
	}
	else {
		document.agencyProfile.action = "/actions.php?action=agency_submit";
		document.agencyProfile.submit();
	}
}

function getMouse(e) {
	var msx = Event.pointerX(e);
	var msy = Event.pointerY(e);
	if($('toolTip') != null) {
		$('toolTip').style.left = (msx - 20) + "px";
		$('toolTip').style.top = (msy - 40) + "px";
	}
}
Event.observe(document, 'mousemove', getMouse);
var tooltip = {
	show: function(caption) {
		$('toolTipCaption').innerHTML = caption;
		$('toolTip').style.display = "block";
	},
	hide: function() {
		$('toolTipCaption').innerHTML = ""
		$('toolTip').style.display = "none";
	}
}

function showBigImage(url) {
	$("bigImage").src = url;
	$("bigImageLink").href = url;
}

function setImg(id, src) {
	$(id).src = src;
}

function showHideElement(id) {
	if($(id).style.display == "block")
		$(id).style.display = "none";
	else
		$(id).style.display = "block";
}

// Check RQ form
function validateRQform() {
	/*var elms = $("rqForm").getInputs();
	elms.each(function(el, index) {
		if(el.type != "image" && el.type != "hidden")
			//ceva
	});*/
	$('rqForm').request({
		onSuccess: function(t) {
			if(t.responseText == "NOERROR") {
				document.rqForm.action = "/actions.php?action=requestquote_process";
				document.rqForm.submit();
			}
			else {
				alert(t.responseText);
			}
		}
	});
	return false;
}
//











