function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//
// Check Box Validation
//
function click_allbox(check)
{
	var field = document.form1['check_box[]'];
	
	if(check)
		for(i = 0; i < field.length; i++)
			field[i].checked = true;
	else
		for(i = 0; i < field.length; i++)
			field[i].checked = false;
}

function click_checkbox()
{
	if(is_all_selected())
		document.form1.all_box.checked = true;
	else
		document.form1.all_box.checked = false;
}

function is_all_selected()
{
	var counter = 0;
	var field = document.form1['check_box[]'];
	
	for(i = 0; i < field.length; i++)
	{
		if(field[i].checked)
			counter += 1;
	}
	
	if(counter >= field.length)
		return true;
	else
		return false;
}

//
// Textarea Input Validation
//
function textCounter(field,cntfield,maxlimit)
{
	if(field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}

//
// Pop Up Window
//
function popup(url,iwidth,iheight) 
{
 if(iwidth > 0) { var width = iwidth; } else { var width = 750; }
 if(iheight > 0) { var height = iheight; } else { var height = 650; }
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/4;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

//
// Image Exchange
//
function changeImage(urlPath,urlLink,idOfImg)
{
	var popupWin = '';
	
	if(urlLink != null) {
		popupWin = 'onclick="popup(\'' + urlLink + '\')" class="hand_click"';
	}
	
	if(idOfImg != null) {
		for(i=1;i<=4;i++) {
			var tmp = 'thumb'+i;
			if(document.getElementById(tmp)) {
				document.getElementById(tmp).style.borderColor = '#CCC';
			}
		}
		
		document.getElementById(idOfImg).style.borderColor = '#CC0000';
	}
	
	document.getElementById('largeBox').innerHTML = '<img src="' + urlPath + '" ' + popupWin + ' />';
}

function confirmBrowse(base_url,prod_id,mem_sess)
{
	if(mem_sess == '') {
		if (confirm("You have to register as a member and login to see product/service detail.")) {
	    	location.href = base_url + '?m=main&c=shw_login&error=1&mem_prod_id=' + prod_id;
		}
	} else {
		location.href = base_url + '?m=main&c=shw_product_info&mem_prod_id=' + prod_id;
	}
}

function showHiddenBox(e_type)
{
	if(e_type == 'checkbox') {
		if(document.getElementById('hiddenBox').style.display == 'none') {
			document.getElementById('hiddenBox').style.display = 'block';
		} else {
			document.getElementById('hiddenBox').style.display = 'none';
		}	
	}
	else {
		if(document.getElementById('search_type').value == 'prod') {
			document.getElementById('hiddenBox').style.display = 'none';
		} else {
			document.getElementById('hiddenBox').style.display = 'block';
		}
	}	
}

function popupnews(e)
{
	if(e) {
		if(document.getElementById(e).style.display == 'block') {
			document.getElementById(e).style.display = 'none';
			return true;
		} else {
		      var elms = document.getElementsByTagName("div");
		      for(var i = 0, maxI = elms.length; i < maxI; i++) {
				if(elms[i].id != '') {
					document.getElementById(elms[i].id).style.display = 'none';
				}
			}
			
			document.getElementById(e).style.display = 'block';
			return true;
		}
	}
	
	return false;
}

function newsDiv (url)
{
	var form = document.forms['form1'];
	var tmp = form.member_country;
	for(var i=0;i<tmp.options.length;i++) {
		if(tmp.options[i].selected == true) {
			var _value = tmp.options[i].value;
		}
	}
	
	window.location.href = url + '?m=main&c=shw_main&v=' + _value + '#newsContent';
}