function stringTrim(str ){
	str=str.replace(/\s+/g," " );
	str=str.replace(/^ /,"" );
	str=str.replace(/ $/,"" );
	return str;
}

function stringChange(texto,de,por ){var regex = new RegExp(de, "g" );return texto.replace(regex,por );}

function stringChangeB(velho,novo,texto) {
	for (var i=0; i<texto.length; i++) {
		if (texto.substring(i,i+velho.length) == velho) {
		texto = texto.substring(0,i)+novo+texto.substring(i+velho.length,texto.length)
		}
	}
	return texto;
}

function HTMLObjSet(eln ){
	var rr = false;
	if( document.all ){
		if(  document.all[eln]  ){
		rr = document.all[eln];
		}
	}else{
		if(  document[eln]  ){
		rr = document[eln];	
		}else{
			if(  document.getElementById(eln)  ){
			rr = document.getElementById(eln );
			}
		}
	}
	return rr;
}

function JSNumberOnly( str ){

	var rs = '';

	if( stringTrim( str ) != '' ){
		strSize  = str.length;

		for( i = 0; i < strSize; i++ ){
			n = str.charCodeAt( i );
			if( n > 47 && n < 58 ){
			rs += String.fromCharCode( n );
			}
		}


	}

	return rs;

}


function JSJPZIPFormat( obj ){
 
 	objPart = new Array();
 	objval  = obj.value;

	if( objval != '' ){
		objPart[0] = objval.substring( 0, 3 );
		objPart[1] = objval.substring( 4 );
		//alert( objPart[0] + " - " + objPart[1] );

		objPart[3] = objPart[0].substring( 3 );
		//alert( " part3 " + objPart[3] );

		objPartInc = "-";
		objtmp = objPart[0].length;
		if( objtmp == 3 ){
		objPart[0] += objPartInc;
		}

		obj.value = objPart[0] + "" + objPart[1];
		
	}
 
}


function objSett(eln ){
	var rr = false;
	if( document.all ){
		if(  document.all[eln]  ){
		rr = document.all[eln];
		}
	}else{
		if(  document[eln]  ){
		rr = document[eln];	
		}else{
			if(  document.getElementById(eln)  ){
			rr = document.getElementById(eln );
			}
		}
	}
	return rr;
}




//ボタンをクリックしてデータベースに入れてマイリストのページへ行ってます
function alerListAdd( vtmp, vtmpBody, code, color ){

	page = 'alertList_add';
	ListAddPOP( page, vtmp, vtmpBody, code, color );

}

function ListAddPOP( page, vtmp, vtmpBody, code, color ){
	if( !code ){

		popLMsg( false, false );

	}else{
		var link      = page + ".php?code=" + code + "&color=" + color;
		window.open( 'about:blank', 'iframePopLayer' );
	
		getMousePosRS = new Array();
		if (document.all) {
			v1 = vtmp.clientX + vtmpBody.document.documentElement.scrollLeft;
			v2 = vtmp.clientY + vtmpBody.document.documentElement.scrollTop;
		}else{
			v1 = vtmp.pageX;
			v2 = vtmp.pageY;
		}
		//alert( vtmp.clientX );
		//alert( vtmpBody.document.documentElement.scrollTop );
	
		getMousePosRS['x'] = parseInt( v1 );
		getMousePosRS['y'] = parseInt( v2 );
	
		//alert(getMousePosRS['y']);
	
		popLMsg( false, getMousePosRS );
		window.open( link , 'iframePopLayer' );
		popLMsg( true, getMousePosRS ); // call layer to show message
	}
}


//ボタンをクリックしてデータベースに入れてマイリストのページへ行ってます
function mylistAdd( vtmp, vtmpBody, code, color ){

	page = 'mylist_add';
	ListAddPOP( page, vtmp, vtmpBody, code, color );

}

function popLMsgClear(){
	clearTimeout(popLMsgID);
	mylistAdd( false, false, false, false );
	//alert(1);
}

function popLMsg( popLMsgOpt, getMousePosRS ){

	seg = 3;

	objc = objSett( 'popLayerMsg' );

	if( !popLMsgOpt ){
		xxT  = 1;
		xxL  = -3000;
	}else{
		xxT = getMousePosRS['y'] - 50;
		xxL = getMousePosRS['x'] - 180;

		seg = seg * 1000;

		popLMsgID = setTimeout( "popLMsgClear()", seg );

	}

	//alert( xxT );

	objc.style.left = xxL + 'px';
	objc.style.top  = xxT + 'px';
}


function browserWH( ){
	var winWH = new Array( );
	winWH[0]  = 630;
	winWH[1]  = 460;
	
	if (parseInt(navigator.appVersion) > 3) {
	 if (navigator.appName=="Netscape") {
	  winWH[0] = window.innerWidth;
	  winWH[1] = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft") != -1) {
	  winWH[0] = document.body.offsetWidth;
	  winWH[1] = document.body.offsetHeight;
	 }
	}
	
	return winWH;
}

// {{{ number_format
function number_format( number, decimals, dec_point, thousands_sep ) {
    // Format a number with grouped thousands
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_number_format/
    // +       version: 804.1712
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://crestidg.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     

    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "," : dec_point;
    var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}// }}}

function numformat(num){
  if(num >= 1000000){
    var result = "" + ((num - (num % 1000000))/ 1000000);
    result += ",";
    if((((num - (num % 1000)) % 1000000) / 1000) < 10){
      result += "00" + (((num - (num % 1000)) % 1000000) / 1000);
    }else if((((num - (num % 1000)) % 1000000) / 1000) < 100){
      result += "0" + (((num - (num % 1000)) % 1000000) / 1000);
    }else{
      result += (((num - (num % 1000)) % 1000000) / 1000);
    }
    result += ",";
    if((num % 1000) < 10){
      result += "00" + (num % 1000);
    }else if((num % 1000) < 100){
      result += "0" + (num % 1000);
    }else{
      result += (num % 1000);
    }
    return result;
  }else if(num >= 1000){
    var result = "" + ((num - (num % 1000))/ 1000);
    result += ",";
    if((num % 1000) < 10){
      result += "00" + (num % 1000);
    }else if((num % 1000) < 100){
      result += "0" + (num % 1000);
    }else{
      result += (num % 1000);
    }
    return result;
  }
  return num;
}




// {{{ array_keys
function array_keys( input, search_value, strict ) {
    // Return all the keys of an array
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_array_keys/
    // +       version: 804.1712
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: array_keys( {firstname: 'Kevin', surname: 'van Zonneveld'} );
    // *     returns 1: {0: 'firstname', 1: 'surname'}

    var tmp_arr = new Array(), strict = !!strict, include = true, cnt = 0;

    for ( key in input ){
        include = true;
        if ( search_value != undefined ) {
            if( strict && input[key] !== search_value ){
                include = false;
            } else if( input[key] != search_value ){
                include = false;
            }
        }

        if( include ) {
            tmp_arr[cnt] = key;
            cnt++;
        }
    }

    return tmp_arr;
}// }}}



// {{{ explode
function explode( delimiter, string ) {
    // Split a string by string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_explode/
    // +       version: 804.1712
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: kenneth
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}

    var emptyArray = { 0: '' };

    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }

    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }

    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }

    if ( delimiter === true ) {
        delimiter = '1';
    }

    return string.toString().split ( delimiter.toString() );
}// }}}

function strlen( string ){
    // Get string length
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_strlen/
    // +       version: 804.1712
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strlen('Kevin van Zonneveld');
    // *     returns 1: 19

    return string.length;
}// }}}


// {{{ substr
function substr( f_string, f_start, f_length ) {
    // Return part of a string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_substr/
    // +       version: 804.1712
    // +     original by: Martijn Wieringa
    // *         example 1: substr('abcdef', 0, -1);
    // *         returns 1: 'abcde'

    if(f_start < 0) {
        f_start += f_string.length;
    }

    if(f_length == undefined) {
        f_length = f_string.length;
    } else if(f_length < 0){
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }

    if(f_length < f_start) {
        f_length = f_start;
    }

    return f_string.substring(f_start, f_length);
}// }}}
