/*
	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
		}
	}
}
/*17Aug09 - FH: This is a new function which checks the browser in a more stable manner*/
function iFrameResize(ifrId){
	
	if (document.getElementById(ifrId)){
		var h;
		var addHeight = 5;
		var extraHeight = -999;

		if(iFrameResize.arguments.length>1){
			addHeight = iFrameResize.arguments[1];
		}
		if(iFrameResize.arguments.length>2){
			extraHeight = iFrameResize.arguments[2];
		}	

		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
			//test for MSIE x.x;
			//alert('IE');
			try {
				h = document.frames(ifrId).document.body.scrollHeight;
				if (extraHeight!=-999) {
					h = h + extraHeight;
				}
				eval('document.all.'+ifrId+'.style.height = h+5');
			}
			catch (e) {
				//do nothing
				eval('document.all.'+ifrId+'.style.height = '+addHeight);
			}
		}else {
			//	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
			//test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
			//alert('Firefox');
			try {
				h = document.getElementById(ifrId).contentDocument.documentElement.scrollHeight;
				if (extraHeight!=-999) {
					h = h + extraHeight;
				}
				document.getElementById(ifrId).height = h;
			}
			catch (e) {
				//do nothing
				document.getElementById(ifrId).height = addHeight;
			}
		}
		try{
			window.scrollTo(0,0);
		}catch(e){}
	}
}

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);
	}
}

function adjustIFrameSize(ifrId,divId){

	var h;
	var addHeight = 30;

 if(document.getElementById && !(document.all)) {
		try {
		
			height = document.getElementById(divId).offsetHeight;
	
			document.getElementById(ifrId).height = height;
		}
		catch (e) {
			//do nothing
		}
	}
else if(document.all) {
		try {
		
			h = window.frames(ifrId).document.body.scrollHeight;
			
			document.getElementById(ifrId).height = h + addHeight;

		}
		catch (e) {
		//do nothing
		}
	}
}

function clearBox(box) {
		            	 	 if(box.value==box.defaultValue) {
		            	 	 	 box.value = "";}
		            	 	 
						}