//----  JETRO MyWeb Custum Template use to JavaScript [ for English ]  ----//
//
//			2003.04.01 update
//  maked by infocom

var sBrows   = navigator.appName;
var sVersion = navigator.appVersion;


//--------  Query HTML  --------//

//----  create to Selection Field  ----//
function createQueryCheckBox( nam, val, spr, max ) {
	var tag = '';
	var n   = 1;

	tag += '<table border="0">\n';
	for( var i = 0; i < val.length; i++ ) {
		if ( n == 1 ) {
			tag += '<tr>\n';
		}
		tag += '<td>';
		var tmp = val[ i ].split( spr );
		if ( tmp[1] ) {
			tag += makeCheckBoxTag( nam, '', tmp[1], tmp[0] );
		} else {
			tag += makeCheckBoxTag( nam, '', val[ i ], val[ i ] );
		}
		tag += '&nbsp;&nbsp;';
		tag += '</td>\n';

		if ( n == max ) {
			tag += '</tr>\n';
			n = 0;
		}
		n++;

	}
	if ( n != 1 ) {
		for( var i = n; i < max; i++ ) {
			tag += '<td></td>\n';
		}
		tag += '</tr>\n';
	}
	tag += '</table>';

	return tag;
}

function createQueryTicket( nam, val, other_j, other_e ) {
	var tag = '';

	tag += '<table border="0">';
	tag += '<tr>';
	tag += '<td nowrap>' + makeCheckBoxTag( nam, '', val[0], val[0] ) + '&nbsp;' + '</td>';
	tag += '<td nowrap>' + makeCheckBoxTag( nam, '', val[1], val[1] ) + '&nbsp;' + '</td>';
	tag += '</tr>';
	tag += '<tr>';
	tag += '<td nowrap>' + makeCheckBoxTag( nam, '', val[2], val[2] ) + '&nbsp;' + '</td>';
	tag += '<td nowrap>' + makeCheckBoxTag( nam, '', val[3], val[3] ) + '&nbsp;' + '</td>';
	tag += '</tr>';
	tag += '</table>';
	tag += '<table border="0">';
	tag += '<tr>';
	tag += '<td nowrap rowspan="2">' + makeCheckBoxTag( nam, '', val[4], val[4] ) + '&nbsp;' + '</td>';
	tag += '<td nowrap>jp : ' + other_j + '</td>';
	tag += '</tr>';
	tag += '<tr>';
	tag += '<td nowrap>en : ' + other_e + '</td>';
	tag += '</tr>';
	tag += '</table>';

	return tag;
}


function createQueryInputDate( val ) {
	var tag = '';

	tag += '<input type="text" name="' + val + '_y1" value="" size="4">' + ' - ';
	tag += '<input type="text" name="' + val + '_m1" value="" size="2">' + ' - ';
	tag += '<input type="text" name="' + val + '_d1" value="" size="2">' + ' ';
	tag += ' &nbsp; to &nbsp; ';
	tag += '<input type="text" name="' + val + '_y2" value="" size="4">' + ' - ';
	tag += '<input type="text" name="' + val + '_m2" value="" size="2">' + ' - ';
	tag += '<input type="text" name="' + val + '_d2" value="" size="2">' + ' ';
	tag += ' ';

	return tag;
}


//--------  Result.html  --------//

function createResultHTML( hits ) {
	var tag = '';

	tag += 'Result:' + hits + 'hits';
	tag += '<br><br>'
	if ( hits > 0 ) {
		tag += '<input type="submit" name="$Query"  value="New Search">';
		tag += '<input type="submit" name="$Refine" value=" Refine ">';
		tag += '<input type="submit"                value=" List ">';
	} else {
		tag += '<input type="button"                value="Go Back" onClick="javascript:doBack();">';
	}

	return tag;
}


//--------  Document HTML  --------//


//----  Industry  ----//
function createIndustry( clss, inds, spr, flg ) {
	var tag = '';

	if ( ( clss == '' || clss == null ) && ( inds == '' || inds == null ) ) {
		return tag;
	}

	var cls = clss.split( spr );
	var ind = inds.split( spr );
	if ( cls.length > ind.length ) {
		var last = cls.length;
	} else {
		var last = ind.length;
	}
	for( var i = 0; i < last; i++ ) {
		if ( cls[ i ] ) {
			var ldat = cls[ i ];
		} else {
			var ldat = '&nbsp;';
		}
		if ( ind[ i ] ) {
			var rdat = ind[ i ];
		} else {
			var rdat = '&nbsp;';
		}

		if ( flg == 'sel' ) {
			tag += '<option value="' + ldat + ':' + rdat + '">' + ldat + ' / ' + rdat + '</option>';
		} else {
			if ( tag != '' ) {
				tag += '<br>';
			}
			tag += ldat + ' / ' + rdat;
		}
	}

	return tag;
}

//----  Industry Item Adder  ----//
function setIndAdd( form, dmmy, clss, man ) {
	var dlist = eval( form + '.' + dmmy );
	var clist = eval( form + '.' + clss );
	var mlist = eval( form + '.' + man );

	if ( clist.selectedIndex < 1 ) {
		alert( 'Please select the main industry sector.' );
		return;
	}
	if ( mlist.selectedIndex < 1 ) {
		alert( 'Please select the sub industry sector.' );
		return;
	}

	if ( dlist.length == 6 ) {
		alert( 'The maximum number of items you can register six.' );
		return;
	}

	for( var i = 0; i < dlist.length; i++ ) {
		var tmp = dlist.options[ i ].value.split( ':' );
		if ( tmp[1] ) {
			if ( clist.options[ clist.selectedIndex ].value == tmp[0] &&
			     mlist.options[ mlist.selectedIndex ].value == tmp[1] ) {
				alert( 'You have already selected this industry.' );
				return;
			}
		}
	}

	dlist.length++;
	dlist.options[ dlist.length -1 ].value = clist.options[ clist.selectedIndex ].value + ':' + mlist.options[ mlist.selectedIndex ].value;
	dlist.options[ dlist.length -1 ].text  = clist.options[ clist.selectedIndex ].value + ' / ' + mlist.options[ mlist.selectedIndex ].value;
}


//----  set Main Industry List Items  ----//
function setMainIndustry( form, clss, man ) {
	var clist = eval( form + '.' + clss );
	var mlist = eval( form + '.' + man );

	if ( clist.selectedIndex < 1 ) {
		return;
	}
	mlist.length = 1;
	mlist.options[ mlist.length -1].value = '';
	mlist.options[ mlist.length -1].text  = '...';
	for( var i = 0; i < ind_Main_EN.length; i++ ) {
		var tmp = ind_Main_EN[ i ].split( ':' );
		if ( clist.options[ clist.selectedIndex ].value == tmp[0] ) {
			mlist.length++;
			mlist.options[ mlist.length -1].value = tmp[1];
			mlist.options[ mlist.length -1].text  = tmp[1];
		}
	}
}


//----  Industry Item Delete  ----//
function setIndDel( form, dmmy, clss, man ) {
	var dlist = eval( form + '.' + dmmy );
	var clist = eval( form + '.' + clss );
	var mlist = eval( form + '.' + man );

	if ( dlist.length < 1 ) {
		return;
	}
	if ( dlist.selectedIndex < 0 ) {
		return;
	}
	if ( isNaN( dlist.selectedIndex ) ) {
		return;
	}
	for( var i = dlist.selectedIndex; i < dlist.length -1; i++ ) {
		if ( dlist.length > 1 ) {
			dlist.options[ i ].value = dlist.options[ i +1 ].value;
			dlist.options[ i ].text  = dlist.options[ i +1 ].text;
		}
	}
	dlist.length--;
}


//----  area  ----//
function createAreaView( area, coun, city, other ) {
	var tag = '';
	var tmp = new Array( area, coun, city, other );

	// alert( area + ' : ' + coun + ' : ' + city + ' : ' + other );

	for( var i = 0; i < tmp.length; i++ ) {
		if ( tmp[ i ] != '' && tmp[ i ] != ' ' && tmp[ i ] != '&nbsp;' ) {
			if ( tag != '' ) {
				tag += ' / ';
			}
			tag += tmp[ i ];
		}
	}

	return tag;
}


function setAreaCountry( form, area, coun ) {
	var alist = eval( form + '.' + area );
	var clist = eval( form + '.' + coun );

	if ( alist.selectedIndex < 1 ) {
		return;
	}
	clist.length = 1;
	clist.options[ clist.length -1].value = '';
	clist.options[ clist.length -1].text  = '...';
	for( var i = 0; i < CountryName.length; i++ ) {
		var tmp = CountryName[ i ].split( ':' );
		if ( alist.options[ alist.selectedIndex ].value == tmp[0] ) {
			clist.length++;
			clist.options[ clist.length -1].value = tmp[1];
			clist.options[ clist.length -1].text  = tmp[1];
		}
	}
}

function doSelectCity( base, form, area, coun, other ) {
	var alist  = eval( form + '.' + area );
	var clist  = eval( form + '.' + coun );
	var ccheck = eval( form + '.' + other );

	if ( ccheck.checked ) {
		alert( 'You cannot select a City because you have placed a checkmark next to "Other".' );
		return;
	}

	if ( alist.selectedIndex < 1 ) {
		alert( 'Please select a region.' );
		return;
	}
	if ( clist.selectedIndex < 1 ) {
		alert( 'Please select a country.' );
		return;
	}

	var adat = alist.options[ alist.selectedIndex ].value;
	var cdat = clist.options[ clist.selectedIndex ].value;
	for ( var i = 0; i < AreaName.length; i++ ) {
		if ( adat == AreaName[ i ] ) {
			var areahtml = '/en/' + AreaHTML[ i ];
			doOpenWind( base, areahtml, 'area', 400, 600 );
		}
	}
}

function changeCityValue( form, area, coun, city, other ) {
	var alist  = eval( form + '.' + area );
	var clist  = eval( form + '.' + coun );
	var ctext  = eval( form + '.' + city );
	var ccheck = eval( form + '.' + other );
	if ( ccheck.checked ) {
/*** close to comment
		alist.selectedIndex = 0;
		clist.selectedIndex = 0;
		clist.length        = 1;
***/
		ctext.value         = '';
	}
}


//----  clear city data  ----//
function clearAreaCity( form, city ) {
	var ctext = eval( form + '.' + city );
	ctext.value = '';
}




//--------  Multi Pratform  --------//

//----  window open  ----//
function doOpenWind( base, url, name, col, row ) {
	if ( base != '' ) {
		url = base + url;
	}
	var sts = 'toolbar=no,location=no,directores=no,menubar=no,scrollbars=yes' + ',width=' + col + ',height=' + row;
	var w;
	w = window.open( url, name, sts );
	w.focus();
}


//----  Field Value Separator CHAR Change  ----//
function moveFieldSpr( val, ospr, nspr ) {
	var tag = '';
	var tmp = val.split( ospr );

	for( var i = 0; i < tmp.length; i++ ) {
		if ( tag != '' ) {
			tag += nspr;
		}
		tag += tmp[ i ];
	}
	if ( tag == '' ) {
		tag = val;
	}

	return tag;
}


//----  history back  ----//
function doBack() {
	if ( history.length >0 ) {
		if ( self.window.name == 'updatedoc' ) {
			self.window.top.close();
		} else {
			self.history.back();
		}
	} else {
		self.window.top.close();
	}
}


//----  flag data table select  ----//
function createSelectField( value, vid ) {
	var tag = '';

	if ( value == '' || value == null ) {
		return tag;
	}
	val = eval( 'val' + vid );
	for( var i = 0; i < val.length; i++ ) {
		var tmp = val[i].split( ':' );
		if ( value == tmp[1] ) {
			tag += tmp[0];
		}
	}
	if ( tag == '' ) {
		tag = value;
	}

	return tag;
}


//----  make check box  ----//
function makeCheckBoxTag( nam, chkval, val, txt ) {
	var tag = '';

	tag += '<input type="checkbox" name="' + nam + '" value="' + val + '"';
	if ( chkval.toLowerCase() == val.toLowerCase() ) {
		tag += ' checked';
	}
	tag += '>' + txt;

	return tag;
}


//----  make radio box  ----//
function makeRadioTag( nam, chkval, val, txt ) {
	var tag = '';

	tag += '<input type="radio" name="' + nam + '" value="' + val + '"';
	if ( chkval.toLowerCase() == val.toLowerCase() ) {
		tag += ' checked';
	}
	tag += '>' + txt;

	return tag;
}


//----  make hidden type field  ----//
function makeField( fId, fVal ) {
	return '<input type="hidden" name="' + fId + '" value="' + getFVal( fVal ) + '">';
}


//----  get to FieldValue data  ----//
// fVal : Field nn Value
// ( type = textarea, text, hidden )
function getFVal( fVal ) {
	var Data = fVal;	// original data
	var sPos = 0;		// search offset
	
	if ( Data.indexOf( '<textarea', 0 ) > -1 ) {
		sPos = Data.indexOf( '>', 0 );
		if ( sPos > -1 ) {
			Data = Data.substring( sPos +1, Data.length );
			sPos = Data.indexOf( '</textarea', 0 );
			if ( sPos > -1 ) {
				Data = Data.substring( 0, sPos );
			}
		}
	} else if ( Data.indexOf( 'type="text"', 0 ) > -1 ) {
		sPos = Data.indexOf( 'value="', 0 );
		if ( sPos > -1 ) {
			Data = Data.substring( sPos +7, Data.length );
			sPos = Data.indexOf( '"', 0 );
			if ( sPos > -1 ) {
				Data = Data.substring( 0, sPos );
			}
		}
	} else if ( Data.indexOf( '<input type="hidden"', 0 ) > -1 ) {
		sPos = Data.indexOf( 'value="', Data.indexOf( '<input type="hidden"', 0 ) );
		if ( sPos > -1 ) {
			Data = Data.substring( sPos +7, Data.length );
			sPos = Data.indexOf( '"', 0 );
			if ( sPos > -1 ) {
				Data = Data.substring( 0, sPos );
			}
		}
	}
	return Data;
}


//---- Date Split ----//
function makeDateSpliter( val, spr, type ) {
	var tmp = new Array( '', '', '' );
	if ( val == '' || val == null ) {
		return tmp;
	}

	if ( spr == '' ) {
		return tmp;
	}
	if ( isNaN( spr ) == true ) {
		var tmp = val.split( spr );
	} else {
		if ( spr != 2 && spr != 4 ) {
			return val;
		}
		var tmp = new Array();
		if ( ( spr == 2 && val.toString().length != 6 ) || ( spr == 4 && val.toString().length != 8 ) ) {
			return val;
		}
		tmp[0] = val.toString().substring( 0, spr );
		var dy = val.toString().substring( spr, val.toString().length );
		tmp[1] = dy.toString().substring( 0, 2 );
		tmp[2] = dy.toString().substring( 2, dy.toString().length );
	}

	return tmp;
}


//----  date value out format setting  ----//
function makeFormatDate( val, spr, type ) {

	if ( type == '' || type == null ) {
		return val;
	}

	var tmp = makeDateSpliter( val, spr );
	if ( ! tmp[2] ) {
		return val;
	}

	if ( type == '0' ) {
		return tmp[ 0 ] + spr + setDigit( tmp[ 1 ], 2 ) + spr + setDigit( tmp[ 2 ], 2 );
	} else if ( type == '1' ) {
		return  tmp[ 0 ] + '-' + setDigit( tmp[ 1 ], 2 ) + '-' + setDigit( tmp[ 2 ], 2 );
	} else if ( type == '2' ) {
		return  tmp[ 0 ] + '/' + setDigit( tmp[ 1 ], 2 ) + '/' + setDigit( tmp[ 2 ], 2 );
	} else if ( type == '3' ) {
		if ( tmp[2] != 0 ) {
			return  tmp[ 0 ] + ' - ' + setDigit( tmp[ 1 ], 2 ) + ' - ' + setDigit( tmp[ 2 ], 2 ) + ' ';
		} else {
			return  tmp[ 0 ] + ' - ' + setDigit( tmp[ 1 ], 2 ) + ' ';
		}
	}

	return val;
}


//---- Data set [ normal format -> myquick format ] ----//
function setDateValue( nam, year, month, day ) {
	ntext = eval( nam );
	if ( year != '' && month != '' && day != '' ) {
		if ( checkDate( year, month, day ) ) {
			ntext.value = year + '-' + month + '-' + day;
			return true;
		} else {
			return false;
		}
	} else {
		return true;
	}
}


//---- check Date ----//
function checkDate( year, month, day ) {
	if ( year == '' || month == '' || day == '' ) {
		return false;
	}

	if ( isNaN( year ) ) {
		return false;
	} else if ( year.toString().length != 4 ) {
		return false;
	}
	if ( isNaN( month ) ) {
		return false;
	} else if ( month < 1 || month > 12 ) {
		return false;
	}

	if ( isNaN( day ) ) {
		return false;
	} else if ( day < 1 || day > check_day( year, month ) ) {
		return false;
	}

	return true;
}


//----  year & month from to check  ----//
function check_day( year, month ){	
	day = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
	if( month == 2 && leapyear( year ) ) return 29;
	return day[ month -1 ];
}


//----  leap year check  ----//
function leapyear( year ){
	return year%4 == 0 && ( year%100 != 0 || year%400 == 0 );
}


//----  set digit  ----//
function setDigit( sVal, len ) {
	var sTmp = sVal.toString();
	for ( var i = sVal.length;i < len; i++ ) {
		sTmp = '0'.toString() + sTmp.toString();
	}
	return sTmp;
}


//----  get Now Date  ----//
function getNowDate( spr ) {
	var val;

	now = new Date();

	var yy = now.getYear();
	if ( yy.toString().length < 4 ) {
		if ( yy.toString().length == 3 ) {
			yy = 1900 + parseInt( yy );
		} else if ( parseInt( yy ) < 31 ) {
			yy = 1900 + parseInt( yy );
		} else {
			yy = 2000 + parseInt( yy );
		}
	}

	var mm = now.getMonth();
	mm = parseInt( mm ) + 1;

	var dd = now.getDate();

	return yy + spr + setDigit( mm, 2 ) + spr + setDigit( dd, 2 );
}


//----  get now URL  ----//
function getURL( url ) {
	var work = '';
	var dat  = url.split( '/' );
	for( var i = 0; i < dat.length; i++ ) {
		if ( dat[i].indexOf( '.exe' ) > -1 ||
		     dat[i].indexOf( '.htm' ) > -1 ||
		     dat[i].indexOf( '.asp' ) > -1 ||
		     dat[i].indexOf( '|' ) > -1    ||
		     dat[i].indexOf( '?' ) > -1 ) {
			break;
		} else {
			work += dat[i] + '/';
		}
	}
	return work;
}


//--------  secound version update  --------//

//----  create text input Field  ----//
function makeTextInput( type, name, val, size, max, opt ) {
	var tag = '';

	tag += '<input type="' + type + '" name="' + name + '" value="' + val + '"';
	if ( size ) {
		if ( size.indexOf( '%' ) > -1 ) {
			tag += ' size="' + size + '"';
		} else if ( sBrows.charAt(0) == 'N' ) {
			if ( sVersion.charAt(0) == '4' ) {
				tag += ' size="' + Math.round( eval( size * 0.5 ) ) + '"';
			} else if ( sVersion.charAt(0) == '6' ) {
				tag += ' size="' + Math.round( eval( size * 0.75 ) ) + '"';
			} else {
				tag += ' size="' + Math.round( eval( size * 0.75 ) ) + '"';
			}
		} else {
			tag += ' size="' + size + '"';
		}
	}
	if ( max ) {
		tag += ' maxlength="' + max + '"';
	}
	if ( opt ) {
		tag += ' ' + opt;
	}

	tag += '>';

	return tag;
}


// set cookie
function setCookie( val ) {
	// setting to cookie
	document.cookie = val;

	return true;
}


// get cookie
function getCookie() {
	return document.cookie;
}

// Convert Number
function changeNumberView( num ) {
	var val = '';
	var flg = '';

	if( num == null || num == '' ) {
		return '';
	}
	if ( isNaN( num ) ) {
		return num;
	}

	var dat  = num;
	if ( dat.charAt( 0 ) == '-' ) {
		dat = dat.substring( 1, dat.length );
		flg = '-';
	} else {
		flg = '';
	}
	var work = '';

	while( dat.length > 3 ) {
		work = dat.substring( dat.length -3, dat.length );
		dat  = dat.substring( 0, dat.length -3 );

		if ( val != '' ) {
			val = ',' + val;
		}
		val = work + val;
	}
	if ( dat.length > 0 ) {
		if ( val != '' ) {
			val = ',' + val;
		}
		val = dat + val;
	}

	return flg + val;
}


//----  End of File  ----//