/*
	functions that is used by common components
*/
function showExtraText(vno){
	var txtDiv = $('et_'+vno);
	$$('div.extratextclass').invoke('hide');
	//remove active class
	$$('div.destinationlinks a').each(function(el) {
		el.removeClassName('active');
	});	
	//add activeclass
	var activeLink = $('destinationlink_'+vno);
	if(activeLink){activeLink.addClassName('active');}
	//show div
	txtDiv.show();	
}

function imageZoom(e){			
	/*
			,
			position: 'relative',
			offsetTop: oT,
			offsetLeft: oL			
	*/
	/*modalLink = e.id;
	e.href=link+modalLink;
	*/
	Control.Modal.close();
	pos_a = Position.cumulativeOffset($(e.id));
	
	var oT = pos_a[1]-100;
	var oL = pos_a[0]-50;			
	Control.Modal.open("<img title='click to close' alt='click to close' style='border: 2px solid #CCC;' src='"+e.href+"' onclick='Control.Modal.close();'>",{			
			fade: true
		});  
}
/*
function iFrameHeight(id) {
	if(document.getElementById && !(document.all)) {
		h = document.getElementById('iframename').contentDocument.body.scrollHeight;
		document.getElementById('iframename').style.height = h;
	}
	else if(document.all) {
		h = document.frames('iframename').document.body.scrollHeight;
		document.all.iframename.style.height = h;
	}
}
*/

function iFrameHeight(ifrId){
	var h;
	var addHeight = 5;
	if(iFrameHeight.arguments.length>1){
		addHeight = iFrameHeight.arguments[1];
	}
	if(document.getElementById && !(document.all)) {
		try {
			document.getElementById(ifrId).height=addHeight;
			h = document.getElementById(ifrId).contentDocument.body.scrollHeight;
			document.getElementById(ifrId).height = h+addHeight;
		}
		catch (e) {
			//do nothing
		}
	}
	else if(document.all) {
		try {
			h = document.frames(ifrId).document.body.scrollHeight;
			eval('document.all.'+ifrId+'.style.height = h+'+addHeight);
		}
		catch (e) {
		//do nothing
		}
	}
}

function setdynheight(){
	var objArray = $$('iframe.dynheight');
	if(objArray.length>0){
		for(var i = 0; i < objArray.length; i++) {
			var objId = objArray[i].readAttribute('id');
			obj = $(objId);
			if(!obj.hasClassName('noobserve')){
				Event.observe(obj,'load',iFrameHeight(objId));
			}	
		}
	}
}

addLoadEvent(setdynheight);

/*validate email*/
function isEmail(str) {
	var email = str;
	//regexp
	var ps_pattern = /^([\w\-~.]+\@([\w\-]+\.){1,}[a-zA-Z]{2,4})$/;
	//test email
	if (email == "" || ps_pattern.test(email) == false ) {
		return false;
	}
	return true;
}

function checkEmailAndSubmit(f,str,emsg){
	if(isEmail(str)){
		f.submit();
	}
	else{
		alert(emsg);
	}
}
