/*
 * common.js
 *
 */
 
// CGI path
//var theCGI = 'https://ngk.cpi.cronus.tbn/jp/contact/form/';
//var theCGI = 'https://ngk.turbine.co.jp/jp/contact/form/';
var theCGI = 'https://www.ngk.co.jp/jp/contact/form/';

// onload event set
window.onload = function () {
		fSearchBoxInit();
		fBLSearchBoxInit();
	if(typeof swapImage == "object"){
		swapImage.init();
	}
}

// clear default text on search input
function fSearchBoxInit(){
	$('input#inSiteSearch').focus(function() {
		fClearSearchBox(this);
	});
	$('input#inSiteSearch').blur(function() {
		fSetSearchBox(this);
	});
	
	if($('input#inSiteSearch').val() == "日本ガイシサイト内検索"){
		$('input#inSiteSearch').addClass('inSearchGray');
	}
}
function fClearSearchBox(arg_obj){
	if(arg_obj.value == "日本ガイシサイト内検索"){
		$(arg_obj).val('');
		$(arg_obj).removeClass('inSearchGray');
	}
}
function fSetSearchBox(arg_obj){
	if(arg_obj.value == ""){
		$(arg_obj).val("日本ガイシサイト内検索");
		$(arg_obj).addClass('inSearchGray');
	}
}


// 製品情報左ナビ
function fBLSearchBoxInit(){
	$('input#inBLProductSearch').focus(function() {
		fClearBLSearchBox(this);
	});
	$('input#inBLProductSearch').blur(function() {
		fSetBLSearchBox(this);
	});
	
	if($('input#inBLProductSearch').val() == "製品名"){
		$('input#inBLProductSearch').addClass('inSearchGray');
	}
}
function fClearBLSearchBox(arg_obj){
	if(arg_obj.value == "製品名"){
		$(arg_obj).val('');
		$(arg_obj).removeClass('inSearchGray');
	}
}
function fSetBLSearchBox(arg_obj){
	if(arg_obj.value == ""){
		$(arg_obj).val("製品名");
		$(arg_obj).addClass('inSearchGray');
	}
}


// popup
function fWinClosed(winVar) {
var ua = navigator.userAgent
	if( !!winVar ) {
		if( ( ua.indexOf('Gecko')!=-1 || ua.indexOf('MSIE 4')!=-1 ) && ua.indexOf('Win')!=-1 ) {
			return winVar.closed
		} else {
			return typeof winVar.document  != 'object'
		}
	} else {
		return true
	}
}
function fOpenWin(theURL,targetName,theW,theH) {
	if(fWinClosed(tWin)){
		var tWin = window;
		tWin = open(theURL,targetName,'scrollbars=yes,resizable=yes,toolbar=no,location=yes,directories=no,status=yes,menubar=no,width='+theW+',height='+theH+'');
		tWin.focus();
	}
}

// print
function fPrint(){
	if(document.getElementById || document.layers){
		window.print();
	} else {
		return false;
	}
}

function fOpenInquiry(arg){
	var theURL = '';
	switch(arg) {
		case 'common':
		case 'site':
		case 'academy':
		case 'procure':
		case 'recruit':
		case 'ir':
		case 'stock':
		case 'invest':
		case 'rd':
		case 'csr':
		case 'eco':
		case 'philanthropy':
			theURL = theCGI + 'common.php?type=' + arg;
			break;
		case 'survey':
			theURL = theCGI + 'survey.php?type=' + arg;
			break;
		case 'product':
			theURL = theCGI + 'generalproduct.php?type=' + arg;
			break;
		case 'houseuse':
			theURL = theCGI + 'houseuse.php?type=' + arg;
			break;
		case 'msds':
			theURL = theCGI + 'msds.php?type=' + arg;
			break;
		case 'nas':
			theURL = theCGI + 'nas.php?type=' + arg;
			break;	
		case 'catalog':
			theURL = theCGI + 'catalog.php?type=' + arg;
			break;	
		case 'report':
			theURL = theCGI + 'report.php?type=' + arg;
			break;		
		default:
			theURL = theCGI + 'product.php?type=' + arg;
			break;
	}
	fOpenWin(theURL,'popup',700,800);
}
function fOpenSurvey(arg){
	var theURL = theCGI+'survey.php?type=survey';
	fOpenWin(theURL,'popup',700,800);
}
function fOpenProcure(arg){
	var theURL = theCGI+'procurerequest.php?type=procurerequest';
	fOpenWin(theURL,'popup',700,800);
}
function fOpenCatalog(arg){
	var theURL = theCGI+'nascatalog.php?type=' + arg;
	fOpenWin(theURL,'popup',700,800);
}
function fOpenMembraneTest(){
	var theURL = theCGI+'membrane_test.php';
	fOpenWin(theURL,'popup',700,800);
}

function fOpenMap(theURL){
	fOpenWin(theURL,'map',700,800);
}

// 2011/11/02 汎用フォーム作成
function fOpenForm(url){
	var theURL = theCGI+url;
	fOpenWin(theURL,'popup',700,800);
}

// pageup scroll
//
function backToTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;
	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));
	window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
	if (x > 0 || y > 0) {
		window.setTimeout("backToTop()", 50);
	}
}


// tvcm
function fDispWmv(asxID) {
	document.write('<embed ');
	document.write('type="application/x-mplayer2"');
	document.write('src="'+asxID+'.asx"');
	document.write('name="MediaPlayer"');
	document.write('width="320" height="309"');
	document.write('autoStart="1"');
	document.write('showcontrols="1"');
	document.write('clicktoplay="1"');
	document.write('showstatusbar="1"');
	document.write('displaysize="-1"');
	document.write('showpositioncontrols="0"');
	document.write('>');
	document.write('<\/embed>');
}
function fDispWmvW(asxID) {
	document.write('<embed ');
	document.write('type="application/x-mplayer2"');
	document.write('src="'+asxID+'.asx"');
	document.write('name="MediaPlayer"');
	document.write('width="420" height="309"');
	document.write('autoStart="1"');
	document.write('showcontrols="1"');
	document.write('clicktoplay="1"');
	document.write('showstatusbar="1"');
	document.write('displaysize="-1"');
	document.write('showpositioncontrols="0"');
	document.write('>');
	document.write('<\/embed>');
}
function fOpenWmv(asxID,_width,_height) {
	document.write('<embed ');
	document.write('type="application/x-mplayer2"');
	document.write('src="'+asxID+'.asx"');
	document.write('name="MediaPlayer"');
	document.write('width="'+_width+'" height="'+_height+'"');
	document.write('autoStart="1"');
	document.write('showcontrols="1"');
	document.write('clicktoplay="1"');
	document.write('showstatusbar="1"');
	document.write('displaysize="-1"');
	document.write('showpositioncontrols="0"');
	document.write('>');
	document.write('<\/embed>');
}

function fOpenCM(theURL){
	fOpenWin(theURL,'popup',700,600);
}
function fOpenCMW(theURL){
	fOpenWin(theURL,'popup',700,650);
}
function fOpenInfHistory(theURL){
	fOpenWin(theURL,'popup',800,700);
}
function fOpenCSRPhilosophy(theURL){
	fOpenWin(theURL,'popup',1000,800);
}


//クッキーの読み込み
function fGetCookie(arg_ck_id) {
	return $.cookie(arg_ck_id);
}
 
//クッキーの書き込み
function fSetCookie(arg_ck_id, ary_id) {
	return $.cookie(arg_ck_id, ary_id, {path: ck_path, expires:ck_limit}); 
}








