IE4=!!document.all;
W3C=DOM=!!document.getElementById;
NS4=!!document.layers;
opendir = '';
function getObj(id) {
    if (document.getElementById) {
    	return document.getElementById(id);
    } else if (document.all) {
	    return document.all[id];
    } else {
    	return false;
    }
} 

function showMenuItems(divid, href) {
	if (NS4) {
		window.location.replace(href);
	} else {
	var el = getObj(divid);
		if(opendir != '') {
			 clopen = getObj(opendir);
			 clopen.style.display = "none";
		}
		if (el.style.display == "block") {
			el.style.display = "none";
		} else {
			el.style.display = "block";
		}
		opendir = divid;
	}
}

function show(layernavn) {
var el = getObj(layernavn);
if(el)
	el.style.visibility="visible";
else
	document.layers[layernavn].visibility = "show";		
}

function hide(layernavn) {
var el = getObj(layernavn);
if(el)
	el.style.visibility="hidden";
else
	document.layers[layernavn].visibility = "hide";
}

function hide_logo ( name ) {
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
W3C = (document.getElementById) ? 1 : 0; 
if (W3C) {
document.getElementById(name).style.visibility = "hidden";
} else if (NS4) {
document.layers[name].visibility = "hidden";
} else {
document.all[name].style.visibility = "hidden";
}
}
function show_logo (name ) {
var ele; //points to the popup element

NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
W3C = (document.getElementById) ? 1 : 0;

if ( W3C ) {
ele = document.getElementById(name);
} else if ( NS4 ) {
ele = document.layers[name];
} else { // meant for IE4
ele = window.opener.document.all[name];
}

if ( NS4 ) {
ele.visibility = "show";
} else { // IE4 & W3C
ele.style.visibility = "visible";
}
}

function CheckLogo(){ 

if (document.entry_form.logo[0].checked == true)
{ 
show_logo('input_logo');
}
if (document.entry_form.logo[1].checked == true)
{ 
hide_logo('input_logo');
}

}

function CheckLogoUpdate(){ 

if (document.entry_form.logo[0].checked == true)
{ 
hide_logo('input_logo');
}
if (document.entry_form.logo[1].checked == true)
{ 
show_logo('input_logo');
}
if (document.entry_form.logo[2].checked == true)
{ 
hide_logo('input_logo');
}

}

function validateForm() {
	num_errors = 0;
	  var ext1= document.entry_form.userfile.value;
	  ext1 = ext1.substring(ext1.length-3,ext1.length);
	  ext1 = ext1.toLowerCase();   
	  felter = new Array('company_name','tourist_address','post_address','moo','tambon','phone_primary','contact_person')
	
	for(i = 0 ; i < felter.length ; i++) {
		felt = eval('document.entry_form.'+felter[i]+'.value')
		if(felt == "") {	
			felt_id = felter[i]+'_id'
			show(felt_id)
			num_errors++
		} else {
			felt_id = felter[i]+'_id'
			hide(felt_id)
		}
	}
if(document.entry_form.logo[0].checked){
			 if((ext1== 'gif' || ext1== 'jpg' || ext1== 'bmp')){
				if(num_errors>0){
					num_errors++
				}
				else{
	  			 num_errors =0;
				}
			}
			else{
				alert('You selected logo a .'+ext1+
			  ' file; please select a .gif  or a .jpg  or a .bmp file instead!');
	 			return false
	 		}
}
	if(num_errors > 0) {
		alert('Please fill out the required fields, marked in red');
		return false
	} else 
		return true
}

function validateForm1() {
	num_errors = 0;
	  var ext1= document.entry_form.userfile.value;
	  ext1 = ext1.substring(ext1.length-3,ext1.length);
	  ext1 = ext1.toLowerCase();   
	  felter = new Array('company_name','tourist_address','post_address','moo','tambon','phone_primary','contact_person')
	
	for(i = 0 ; i < felter.length ; i++) {
		felt = eval('document.entry_form.'+felter[i]+'.value')
		if(felt == "") {	
			felt_id = felter[i]+'_id'
			show(felt_id)
			num_errors++
		} else {
			felt_id = felter[i]+'_id'
			hide(felt_id)
		}
	}
if(document.entry_form.logo[1].checked){
			 if((ext1== 'gif' || ext1== 'jpg' || ext1== 'bmp')){
	  			 if(num_errors>0){
					num_errors++
				}
				else{
	  			 num_errors =0;
				}
			}
			else{
				alert('You selected logo a .'+ext1+
			  ' file; please select a .gif  or a .jpg  or a .bmp file instead!');
	 			return false
	 		}
}
	if(num_errors > 0) {
		alert('Please fill out the required fields, marked in red');
		return false
	} else 
		return true
}

function validateSearch() {
if(document.forms[0].q.value == '' || document.forms[0].q.value == 'Company Name') {
	alert('You have to type in a company name');
	return false;
} else
	return true;
}

function positionMap(vis) {
	var t_offsetW=t_offset()
	var m=t_getelement("thailandmap")
	if(NS4){
		m.moveTo(t_offsetW+mapPos,200)
		m.visibility=vis?"show":"hide"
	}else{
		m.style.left=t_offsetW+mapPos
		m.style.top=200
		m.style.visibility=vis?"visible":"hidden"
		m.style.zIndex=10000
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}