/* JP - global stuff */
jQuery.noConflict();


jQuery(document).ready(function(){
    
    jQuery('ul#globalNav').superfish({ 
            delay:       0                                // no delay on mouseout 
        });
    
    jQuery('ul#topNav').superfish({ 
            delay:       0                                // no delay on mouseout 
        });
    
    autoFill(jQuery("#searchfield"), "");
    
    function autoFill(id, v){
		jQuery(id).css({ color: "#b2adad" }).attr({ value: v }).focus(function(){
	    	if(jQuery(this).val()==v){
	    		jQuery(this).val("").css({ color: "#333" });
	    	}
	    }).blur(function(){
	    	if(jQuery(this).val()==""){
	    		jQuery(this).css({ color: "#b2adad" }).val(v);
	    	}
	    });
	    
	}
    
});

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/****************************************** 
 * TELL A FRIEND
 *****************************************/

function tell_a_friend(){
	var WindowSet = 'top=100,left=200,width=490,height=660,resizable=0,scrollbars=0,toolbar=0,menubar=0,location=0,status=0';
	var ServerName = "inet.trendmicro.co.jp";
	var sTitle = window.document.title;
	var sURL = window.document.location;
	window.open("https://" + ServerName + "/tell_a_friend/index.asp?t=" + escape(sTitle) + "&u=" + sURL,"_blank",WindowSet);
}


/****************************************** 
 * TEXT SIZER
 *****************************************/

function textsizer(theSize) {
	if (theSize == 'larger') {
		document.getElementById("textsize").href = "#";
	} else 	if (theSize == "largest") {
		document.getElementById("textsize").href = "#";
	} else if (theSize == "normal") {
		document.getElementById("textsize").href = "#";
	}
	createCookie('TM_TextSizer',theSize,365)
}

function currentSize() {
	var x = readCookie('TM_TextSizer')
	if (x) {
		if (x == 'larger') {
			document.getElementById("textsize").href = "#";
		} else 	if (x == "largest") {
			document.getElementById("textsize").href = "#";
		} else if (x == "normal") {
			document.getElementById("textsize").href = "#";
		}
	} else {
			document.getElementById("textsize").href = "#";
	}
	
}

function expander(theID) {
	spanID = document.getElementById(theID);
	spanID.style.display = (spanID.style.display == 'block') ? 'none' : 'block';
}

function expanderBody(theID,allIDs) {
	// spanID = document.getElementById(theID);
	for (var i = 0; i < allIDs; i++) {
		spanID = document.getElementById('expander_'+i);
		if ('expander_'+i == theID)
			spanID.style.display = (spanID.style.display == 'block') ? 'none' : 'block';
		else
			spanID.style.display = 'none';
	}
}

function expanderBodyOpenAll(allIDs) {
	// spanID = document.getElementById(theID);
	for (var i = 0; i < allIDs; i++) {
		spanID = document.getElementById('expander_'+i);
		spanID.style.display = 'block';
	}
}

function expanderBodyClose(theID) {
	spanID = document.getElementById(theID);
	spanID.style.display = 'none';
}


/****************************************** 
 * IMAGE POPUP
 *****************************************/
function popImg(url,name,width,height,scroller)
{
	width = width + 6;
	height = height + 40;
	var outStr = 'height=' + height + ',width=' + width;
   
	if (scroller != 'true')
	{
		outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,';
	}else {
		outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no';
	}
	
	imageWindow = window.open('', name, outStr);
	imageWindow.document.open();
	imageWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
	imageWindow.document.write("<html><head><title>Trend Micro Japan</title>");
	imageWindow.document.write("<meta http-equiv='content-language' content='ja'/><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/><meta http-equiv='Content-Script-Type' content='text/javascript'/><meta http-equiv='Content-Style-Type' content='text/css'/>");
	imageWindow.document.write("<link rel='stylesheet' href='/css/jp/popup.css' type='text/css' media='screen' /></head>");
	imageWindow.document.write("<body>");
	imageWindow.document.write("<p class='closewindow_rt'><a href='javascript:self.close();'>Close Window</a></p>");
	imageWindow.document.write("<p class='bigimg'><img src='");
	imageWindow.document.write(url);
	imageWindow.document.write("'border='0' alt='Trend Micro Japan' /></p>");
	imageWindow.document.write("</body></html>");
	imageWindow.focus()   
	imageWindow.document.close();
}


/****************************************** 
 * NEW WINDOW POPUP
 *****************************************/
function MM_openBrWindow(theURL,winName,features) {
	var openBrWindow;
	openBrWindow=window.open(theURL,winName,features);
	openBrWindow.focus();
}


/****************************************** 
 * CSS INCLUDE FOR MAC
 *****************************************/
function cssIncludeMac() {
	if(navigator.userAgent.indexOf("Mac")!=-1) {
		document.write('<link rel="stylesheet" type="text/css" href="/global/rfcommon/css/jp/mac.css">');
	}
}


/****************************************** 
 * Run function on window load
 *****************************************/
function loadFunctions() {
	currentSize();
}


window.onload = loadFunctions
