/* layout/general */

if(document.getElementById) {
	window.getObj = function(id) {
		return document.getElementById(id);
	}
} else {
	window.getObj = function(id) {
		return false;
	}
}
function layout() {
	var cHeight=0;
	var sHeight=0;
	
	if (window.document.documentElement && window.document.documentElement.scrollHeight){
		sHeight = window.document.documentElement.scrollHeight;
	} else if (window.document.body){
		sHeight = window.document.body.scrollHeight;
	}
	
	if (!!window.innerHeight){
		cHeight = document.body.scrollHeight;
	} else if (window.document.documentElement && window.document.documentElement.clientHeight){
		cHeight = window.document.documentElement.clientHeight;
	} else if (window.document.body){
		cHeight = window.document.body.clientHeight;
	}
	
	//alert(document.documentElement.scrollHeight+':'+self.innerHeight+':'+document.documentElement.clientHeight+':'+document.body.scrollHeight);
	
	var left = document.getElementById('left');
	//var frontcontent = document.getElementById('front-contents');
	//var content = document.getElementById('contents');
	//var content_wide_white = document.getElementById('content_wide-white');
	var iframecontent = document.getElementById('iframe-contents');
	var externdoc = document.getElementById('externdoc');
	//var related = document.getElementById('related');
	var right = document.getElementById('right');
	
	//var contactdb_txt = document.getElementById('contactdb_txt');
	//var advsearch_txt = document.getElementById('advsearch_txt');
	
	if( left ) left.style.height=((cHeight>=sHeight?cHeight:sHeight)-57)+'px';
	//if( content ) content.style.height=((cHeight>=sHeight?cHeight:sHeight)-102)+'px';
	//if( content_wide_white ) content_wide_white.style.height=((cHeight>=sHeight?cHeight:sHeight)-80)+'px';
	//if( frontcontent ) frontcontent.style.height=((cHeight>=sHeight?cHeight:sHeight)-80)+'px';
	if( iframecontent ) iframecontent.style.height=((cHeight>=sHeight?cHeight:sHeight)-80)+'px';
	if( externdoc ) externdoc.style.height=((cHeight>=sHeight?cHeight:sHeight)-40)+'px';
	//if( related ) related.style.height=((cHeight>=sHeight?cHeight:sHeight)-40)+'px';
	if( right ) right.style.height=((cHeight>=sHeight?cHeight:sHeight)-60)+'px';
	//if( contactdb_txt ) contactdb_txt.style.height=((cHeight>=sHeight?cHeight:sHeight)-137)+'px';	
	//if( advsearch_txt ) advsearch_txt.style.height=((cHeight>=sHeight?cHeight:sHeight)-145)+'px';	
}

window.onresize=layout;

/* form validation */
function chkFormContactDatabase(f){
	
	if (f&&((f.searchtype.selectedIndex==0&&(f.company.value.replace(/ /g,'')!=''||f.cat_comp.selectedIndex!=0))||(f.searchtype.selectedIndex==1&&(f.person.value.replace(/ /g,'')!=''||f.cat_name.selectedIndex!=0))||f.country_id.selectedIndex!=0||f.genre_id.selectedIndex!=0)){
		return true;
	}
	alert('Please state search criteria(s).');
	return false;
}
function changeFormContactDatabase(idx){
	switch(idx){
		case 0:
			document.getElementById('div_name').style.display='none';
			document.getElementById('div_company').style.display='block';
			document.getElementById('div_cat_name').style.display='none';
			document.getElementById('div_cat_company').style.display='block';
			break;
		case 1:
			document.getElementById('div_name').style.display='block';
			document.getElementById('div_company').style.display='none';
			document.getElementById('div_cat_name').style.display='block';
			document.getElementById('div_cat_company').style.display='none';
			break;
	}
}

function changeFormSearch(idx){
	var f=document.getElementById('frmSearch');
	var fid=document.getElementById('id');
	var fkeyword=document.getElementById('frmSearchKeywords');	
	var fi01=document.getElementById('i01');
	var fperson=document.getElementById('person');
	var fcompany=document.getElementById('company');

	switch(idx){
		case 0:
			f.method='get';
			fid.value='107';
			break;
		case 1:
			f.method='get';
			fid.value='142';
			fi01.value=fkeyword.value;
			break;
		case 2:
			f.method='get';
			fid.value='150';
			fcompany.value=fkeyword.value;
			break;
		case 3:
			f.method='get';
			fid.value='150';
			fperson.value=fkeyword.value;
			break;
	}
}

function changeExternalLinkTarget() {
	if (document.links && document.links.length>0) {
		for (i=0;i<document.links.length;i++) {
			if (document.links[i].hostname != '' && (document.links[i].protocol=='http:' || document.links[i].protocol=='https:') && document.links[i].hostname.toLowerCase().indexOf(document.location.hostname.toLowerCase())==-1){
				document.links[i].target = 'externalwebsite';
			}
		}
	}
}

