

//For DEBUG
// @depend jgrowl.js
// @see http://www.stanlemon.net/projects/jgrowl.html
function debug(msg,data,type){
	if(DEBUG){
		var datas = "";
		if((data) && (data.isArray)){
			datas = ":" + arrayToString(data);
		}
		alert( msg + datas );
		//$.jGrowl(msg);
	}else{}
}
//For User
function userMessage( msg,type ){
//$("body").append("<div id='userMessageDialogBox' />");
//	$("#userMessageDialogBox").dialog();
	alert(msg);
}

		    function loadGMap(obj,zip,address){
		      if (GBrowserIsCompatible()) {
		        var mapObj = document.getElementById(obj);
		        	mapObj.style.width = '400px';
		        	mapObj.style.height = '300px';
		        var map = new GMap2( mapObj );
		        var geocoder = new GClientGeocoder();
				geocoder.getLatLng(
				    zip + address,
				    function(point) {
				      if (!point) {
				        alert(address + " not found");
				      } else {
				        map.setCenter(point, 13);
				        //alert(point);
				        var marker = new GMarker(point);
				        map.addOverlay(marker);
				        map.addControl(new GSmallMapControl());
						map.addControl(new GMapTypeControl());
				        marker.openInfoWindowHtml( zip + address);
				      }
				    }
				);
		      }
		    }


//[TODO] NIY ... Session or Request by Server
function getUserID( ){
	var userID = "Unknown";
	return userID;
}

	function getUserInfoXX(){
		var USERINFO_JSON_URI = "order/userInfoJSON";
/*Penngind by Yoshi: 2009/05/11 -- no moveing
		var uriX = USERINFO_JSON_URI;
		var params = {};
		
		try{
		debug("HIHI:"+uriX);
		    	$.getJSON(
		            uriX,
		            params,
		            function(json) {
		            	//debug( json );
		                alert("HIHIHI");
		      		}
		      	);
		debug("HIHI:"+uriX);
		}catch(e){
			alert("" + e);
		}
*/		
	}


//Date

function getDateTime(){
	var result = "";

	myDate = new Date();
	YYYY = myDate.getFullYear();
	MM = myDate.getMonth()+1;
	DD = myDate.getDate();
	HH = myDate.getHours();
	MI = myDate.getMinutes();
	SS = myDate.getSeconds();
	result = YYYY+"/"+MM+"/"+DD+" "+ HH + ":" + MI +":" + SS + "";
	// debug( result );
	return result;
}

//Array to String
function arrayToString( array ){
	//CATALOG_DB["CSCB100503B"].productCode +
    var str = "Data[]:";
    for (var k in array ) {
        str += "[" + k + "]";
  	}
  	return str;
}

//[Cookie]
var COOKIE_DEFAULT_EXPIRES = { path: '/',expires: 7 };
function setCookie( key,value,expr ){
	$.cookie(key,value,expr);
}

/**
  * URL params
  *
  */
var locationParameters;
function getURLParameter( name ){

	locationParameters = new Object;
	var pair=location.search.substring(1).split('&');
	for(i=0;pair[i];i++) {
		var kv = pair[i].split('=');
		locationParameters[kv[0]]=kv[1];
	}
	return locationParameters[ name ];
}

//[CSS loader]
	function loadCss(href, check) {
	
		if(typeof(check) == 'undefined') check = true;
	
		var head = document.getElementsByTagName('head')[0];
		var link = document.createElement('link');
		link.rel = 'stylesheet';
		link.type = 'text/css';
		link.href = href;
	
		if(check) {
			var links = head.getElementsByTagName('link');
			for(var i = 0; i < links.length; i++) {
				if(links[i].href == link.href) return false;
			}
		}
	
		head.appendChild(link);
	}

//[jTemplate]
	/**
	 * Util make HTML by Template pre/suffix
	 *
	 */
	function createTemplateHTML( targetTag,data){ //, templatePrefix,templateSuffix ){
		//Get Template file Id @reference /template/product_{ID}.html
		var templateId = data.templateSuffix;
		var templateFile = null;
			if( templateId.length > 0 ){
				templateFile= data.templatePrefix + templateId + ".html";
			}else{
				templateFile = data.templatePrefix + 0 + ".html";
			}
			//templateFile = homePageUrl + "js/template/" + templateFile;
			templateFile = getAppPath( "js/template/" + templateFile );
			//alert(templateFile);
			//IE cache
			templateFile = templateFile + "?" + Math.random().toString(36).slice(-8);
		//funftion()
		try{
			$("#" + targetTag).setTemplateURL( templateFile );
			$("#" + targetTag).processTemplate(data);
		}catch(e){
			//[DEBUG]
			//alert(e); //Not found template file.
			userMessage("大変ご迷惑をおかけします。ただいまアクセスが大変混雑しております。");
		}

	}


//[csv2table]
/**
 * CSVto Table
 * @code utf-8 & CRLF
 * @see http://jsgt.org/lib/jquery/plugin/csv2table/
 * @example:  
 * <div id="view1"></div>
 * <script>
 * $(function(){
 * $('#view1').csv2table('./data/excelsample.csv');
 * });
 * </script>
 */
function createTable( divId,path ){
	$('#'+divId).csv2table('' + path);
}


var CATALOGPAGE_LASTID = 'CATALOGPAGE_LASTID';
//[Common] DB
	//[Common] Set Version of DB
	function setDBVersion( version ){
		catalogVersion = version;
	}
	
	//[Common] Get Version of DB
	function getDBVersion(){
		return catalogVersion;
	}
	//[Common] Set DB for global
	function setDB( db ){
		CATALOG_DB = db;
	}
	
	//[Common] Get DB for global
	function getDB(){
		return CATALOG_DB;
	}
	
	//[Common]Set Catalog
	function setCatalogID( _id ){
	    _id = _id.toUpperCase(); //"CATALOG_RA01"
	    if( _id.indexOf(CATALOG_PREFIX) > 0 ){
	    	catalogID = _id.replace(CATALOG_PREFIX,"");
	    	selectCatalogID = _id;
	    }else{
			catalogID = _id;
	    	selectCatalogID = CATALOG_PREFIX + catalogID; //"CATALOG_RA01"
	    }
		if(catalogID){
			$.cookie( CATALOGPAGE_LASTID,catalogID,COOKIE_DEFAULT_EXPIRES );
		}else{}
	}
	
	function getCatalogID(){
		return $.cookie( CATALOGPAGE_LASTID);
	}
	
	function getSelectCatalogID(){
		return selectCatalogID;
	}
	

