var browser=0;if (window.opera) browser=4;else{if (document.all){browser=3;}else{if (document.getElementById){browser=1;}else {if (document.layers) browser=2;}}}

var infoAr = {
    referer : document.referrer,
    current : document.URL
};

var getPara = '?id=' + user;
for (var i in infoAr) {
    getPara += '&' + i + '=' + escape(infoAr[i]);
}
var hostName = location.hostname;
var st=hostName.match(/([^.。]*?)\.?([^.。]+?)\.([.a-z]{2,5})$/);
if (st.length - 2 >= 0){
	domainName = st[st.length-2] + '.' + st[st.length-1];
}else{
	domainName = hostName;
}
getPara += '&domainName=' + domainName;
if(typeof conv != 'undefined'){
getPara += '&conv=1';
}
if(typeof item != 'undefined' && item != '[object Window]' && item != '[object]'){
	getPara += '&item=' + item;
}
var connectType="http://";
if(infoAr.current.substr(0,5)=="https"){
    var connectType = "https://";
}
var receiveUrl = 'www.keyword-stock.com/receive.php';
   
var incScriptTag='<script type="text/javascript" src="'+connectType+receiveUrl+getPara +'"></scri'+'pt>';

document.write(incScriptTag);
document.write('<div id="ad_icon" style="display:none;" onMouseover="dispAdWindow()" onMouseOut="closeAdWindow()"><img src="http://www.keyword-stock.com/images/ad_icon.gif"></div>');
document.write('<div id="ad_window" style="display:none;" onMouseover="dispAdWindow()" onMouseOut="closeAdWindow()"></div>');


window.onload = createAd;
closeCountDown = 0;
//}
function createAd(){
var ad_window = document.getElementById("ad_window");
if(document.all){
pCs = document.charset;
}else{
pCs = document.characterSet;
}

var out = document.createElement('script');	
out.src='http://www.keyword-stock.com/getAd/us/'+user+'/pCs/'+pCs+'/';
ad_window.appendChild(out);

var screenSize = getScreenSize();
var scrollPos = getScrollPosition();
var default_pos = scrollPos.y + screenSize.y - ad_window.offsetHeight -2;
ad_window.style.position="absolute";
ad_window.style.backgroundColor="white";
ad_window.style.border="solid #333 1px";
ad_window.style.left = "0px";
ad_window.style.top = default_pos + "px";
ad_window.style.overflow = "hidden";
ad_window.style.zIndex = "10000";
ad_window.style.display = "none";
var ad_icon = document.getElementById("ad_icon");
var icon_pos = scrollPos.y + screenSize.y - ad_icon.offsetHeight -2;
ad_icon.style.position="absolute";
ad_icon.style.backgroundColor="white";
ad_icon.style.left = "0px";
ad_icon.style.top = icon_pos + "px";
ad_icon.style.display="none";
ad_icon.style.overflow = "hidden";
ad_icon.style.zIndex = "10000";

ad_icon.style.top = document.body.offsetHeight - ad_icon.offsetHeight - 2;
	  
interval = setInterval('moveAd()', 20);

}


function dispAdWindow(){
var ad_window = document.getElementById("ad_window");
var ad_icon = document.getElementById("ad_icon");
ad_window.style.display = 'block';
ad_window.style.top = (parseInt(ad_icon.style.top) - ad_window.offsetHeight) + 'px';


if(typeof cdid !== "undefined"){
	clearTimeout(cdid);
}
closeCountDown = 10;

}

function closeAdWindow(){
	closeCountDown --;
	if(closeCountDown < 0){
		var ad_window = document.getElementById("ad_window");
		ad_window.style.display = 'none';
	}
	cdid = setTimeout('closeAdWindow()', 100);
}

function moveAd(){
var ad_icon = document.getElementById("ad_icon");
var screenSize = getScreenSize();
var scrollPos = getScrollPosition();
var target_pos = scrollPos.y + screenSize.y - ad_icon.offsetHeight -2;
var target_pos =  document.body.offsetHeight - ad_icon.offsetHeight - 2;
var current_pos = parseInt(ad_icon.style.top);

var speed = 20;
var offset = Math.abs(target_pos - current_pos);

if(offset < speed){
	speed = offset;
}
	if(current_pos > target_pos){
			speed *= -1;
	}else{
			speed *= 1;
	}
ad_icon.style.top = (current_pos + speed) + 'px';
}

function setMail(){
    customElementAr = document.getElementsByTagName("input");
    var customElementName; 
    var mailAddress = '';
    for(i=0;i<customElementAr.length;i++){
	if(customElementAr[i].name == mailName){
	    customElementName = customElementAr[i].name;
	    mailAddress = customElementAr[i].value;
	}
    }

    if (mailAddress){
	document.cookie = "mail=" + escape(mailAddress) + ";path=/";
    }
}

window.onunload = setMail; 


function getScrollPosition() {
    var obj = new Object();
    obj.x = document.documentElement.scrollLeft || document.body.scrollLeft;
    obj.y = document.documentElement.scrollTop || document.body.scrollTop;
    return obj;
}
function getScreenSize() {
    var obj = new Object();
  if (window.innerWidth){
  obj.x = window.innerWidth;
  obj.y = window.innerHeight;
  }else{
  obj.x = document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth;
  obj.y = document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
  }
    obj.mx = parseInt((obj.x)/2);
    obj.my = parseInt((obj.y)/2);
    return obj;
}

