﻿var intv1;
var intv2;
var intv3;
var cbf;
var domainString;

function crossOver( url ) {

	headElement = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	scriptTag.setAttribute("id", "crossOverScript");
	scriptTag.setAttribute("type", "text/javascript");
	scriptTag.setAttribute("src", url);
	try {
		headElement.appendChild(scriptTag);
	}
	catch(e) {
		viewNoteCount( '0', '0', '0', 0, 0, 0);
	}
}

function getNoteCount( domain, callBackFunction ) {
	cbf = callBackFunction;	
	domainString = domain;
	intv1 = setTimeout(executeGetNoteCount, 1500);
}

function executeGetNoteCount() {
	clearTimeout( intv1 );
	crossOver(domainString + "/main/newcount");
}

function viewNoteCount(noteCount, giftCount, reqCount, alarmNoteCount, alarmGiftCount, alarmReqCount) {
 	if ( $("newNoteCount") ) {
 		if(noteCount == 0) {
	 		$("newNoteCount").innerHTML = "<span class='none'>새로운 쪽지가 없습니다.</span>";
	 	}else {
			$("newNoteCount").innerHTML = "읽지 않은 쪽지가<br /><span><strong><label style=\"cursor:hand\" onclick=\"javascript:openPopup('" + domainString + "/main/',689,459,false,'Message');\">" + noteCount + "</label></strong>개</span> 있습니다.";
		} 		
 	}
	if ( $("newGiftCount") ) {
 		if ( giftCount > 999 ) giftCount = "많음";
		$("newGiftCount").innerHTML = "<label style=\"cursor:hand\" onclick=\"javascript:openPopup('http://message.plaync.co.kr/main/?listType=receive\&msgType=2',689,459,false,'Message');\">" + giftCount + "</label>";
 	}
 	if ( $("newReqCount") ) {
 		if ( reqCount == 0 ) {
			$("newReqCount").innerHTML = "<span class='none'>새 친구신청이 없습니다.</span>";
		}else {
			$("newReqCount").innerHTML = "새로운 친구 신청이<br /><span><strong><label style=\"cursor:hand\" onclick=\"javascript:openPopup('" + domainString + "/main/?listType=request',689,459,false,'Message');\">" + reqCount + "</label></strong>개</span> 있습니다.";
		} 
 	}
	
	try {
		cbf( noteCount>0?true:false, reqCount>0?true:false, giftCount>0?true:false );
	}
	catch(e) {}

}

