﻿/*------------------------------------------------------------------------------
* 함수명 : get_param()
* 처리내용 : 파라미터값 가져오기 : get_param("파라미터변수");
------------------------------------------------------------------------------*/
function get_param(inum, purl) {
	//var param = location.href; 
	var param = purl; 
	param = param.substring(param.lastIndexOf("?")+1, param.length);
	if (param.indexOf(inum+"=") == -1) {
		//param = false; 
		param = 1; 
	}
	else {
		param = param.split(inum+"=")[1]; 
		if (param.indexOf("&") != -1) {
			param = param.split("&")[0];
		}
		else if (param.indexOf("%26") != -1) {
			param = param.split("%26")[0];
		}
	}
	return param;
}


function get_param_count(url) {
	var param = url; 
	var count = 0;
	param = param.substring(param.lastIndexOf("?")+1, param.length);
	if (param.indexOf(inum+"=") == -1) {
		count = 0; 
	}
	else {
		count = 1;
	}
	return count;
}
/*----------------------------------------------------------------------------*/









// 140바이트 크리로 맞추기 - 넘치는 경우 삭제
function CutChar(){
	var str,msg;
	var len=0;
	var temp;
	var count;
	count = 0;

	//msg = document.frm.sms_contents.value;
	msg = document.getElementById("tweet_textarea").value;
	str = new String(msg);
	len = str.length;

	for(k=0 ; k<len ; k++) {
		temp = str.charAt(k);

		if(escape(temp).length > 4) {
			count += 2;
		}
		else if (temp == '\r' && str.charAt(k+1) == '\n') { // \r\n일 경우
			count += 2;
		}
		else if(temp != '\n') {
			count++;
		}
		if(count > 200) {
			str = str.substring(0,k);
			break;
		}
	}
	//document.frm.sms_contents.value = str;
	 document.getElementById("tweet_textarea").value = str;
	CheckMsg(str);
}


// 사용 가능한 SMS메시지인가 검사
function CheckMsg(){
	var str,msg;
	var len = 0;
	var temp;
	var count = 0;

	//msg = document.frm.sms_contents.value;
	msg = document.getElementById("tweet_textarea").value;
	str = new String(msg);
	len = str.length;

	//deleteTextarea();

	for (k=0 ; k<len ; k++){
		temp = str.charAt(k);

		if (escape(temp).length > 4) {
			count += 2;
		}
		else if (temp == '\r' && str.charAt(k+1) == '\n') { // \r\n일 경우
			count += 2;
		}
		else if (temp != '\n') {
			count++;
		}
	}

	document.getElementById("Reply_Count").innerHTML = count+"byte 입력" + "&nbsp;&nbsp;&nbsp;";

	if(count > 200) {
		//document.frm.sms_contents.blur();
		//document.frm.sms_contents.focus();
		msg = document.getElementById("tweet_textarea").blur();
		msg = document.getElementById("tweet_textarea").focus();
		alert("메시지 내용은 200바이트까지만 전송이 가능합니다.");
		CutChar();
	}
}








// 140바이트 크리로 맞추기 - 넘치는 경우 삭제
function CmtCutChar(cno){
	var str,msg;
	var len=0;
	var temp;
	var count;
	count = 0;

	//msg = document.frm.sms_contents.value;
	msg = document.getElementById("comment_reply"+cno).value;
	str = new String(msg);
	len = str.length;

	for(k=0 ; k<len ; k++) {
		temp = str.charAt(k);

		if(escape(temp).length > 4) {
			count += 2;
		}
		else if (temp == '\r' && str.charAt(k+1) == '\n') { // \r\n일 경우
			count += 2;
		}
		else if(temp != '\n') {
			count++;
		}
		if(count > 180) {
			str = str.substring(0,k);
			break;
		}
	}
	//document.frm.sms_contents.value = str;
	 document.getElementById("comment_reply"+cno).value = str;
	CmtCheckMsg(str);
}


// 사용 가능한 SMS메시지인가 검사
function CmtCheckMsg(cno){
	var str,msg;
	var len = 0;
	var temp;
	var count = 0;

	//msg = document.frm.sms_contents.value;
	msg = document.getElementById("comment_reply"+cno).value;
	str = new String(msg);
	len = str.length;

	//deleteTextarea();

	for (k=0 ; k<len ; k++){
		temp = str.charAt(k);

		if (escape(temp).length > 4) {
			count += 2;
		}
		else if (temp == '\r' && str.charAt(k+1) == '\n') { // \r\n일 경우
			count += 2;
		}
		else if (temp != '\n') {
			count++;
		}
	}

	//document.getElementById("Reply_Count").innerHTML = count+"byte 입력";

	if(count > 180) {
		//document.frm.sms_contents.blur();
		//document.frm.sms_contents.focus();
		msg = document.getElementById("tweet_textarea").blur();
		msg = document.getElementById("tweet_textarea").focus();
		alert("메시지 내용은 180바이트까지만 전송이 가능합니다.");
		CmtCutChar(cno);
	}
}










 function getCookie( cookieName )
 {
  var search = cookieName + "=";
  var cookie = document.cookie;
  // 현재 쿠키가 존재할 경우
  if( cookie.length > 0 )
  {
   // 해당 쿠키명이 존재하는지 검색한 후 존재하면 위치를 리턴.
   startIndex = cookie.indexOf( cookieName );
   // 만약 존재한다면
   if( startIndex != -1 )
   {
    // 값을 얻어내기 위해 시작 인덱스 조절
    startIndex += cookieName.length;
    // 값을 얻어내기 위해 종료 인덱스 추출
    endIndex = cookie.indexOf( ";", startIndex );
    // 만약 종료 인덱스를 못찾게 되면 쿠키 전체길이로 설정
    if( endIndex == -1) endIndex = cookie.length;
    // 쿠키값을 추출하여 리턴
    return unescape( cookie.substring( startIndex + 1, endIndex ) );
   }
   else
   {
    // 쿠키 내에 해당 쿠키가 존재하지 않을 경우
    return false;
   }
  }
  else
  {
   // 쿠키 자체가 없을 경우
   return false;
  }
 }
 



function goProfile(type,uid) {
	var url = "";
	if(type == 1) {
		url = "http://twitter.com/" + uid;
	} else if(type == 2) {
		url = "http://www.facebook.com/profile.php?id=" + uid;
	} else if(type == 3) {
		url = "http://me2day.net/" + uid;
	} else if(type == 4) {
		url = "http://yozm.daum.net/" + uid;
	} else if(type == 5) {
		url = "http://c.cyworld.com/home?id=" + uid;
	}
	window.open(url, "sns");
}
 



function loginMe2day() {
	var url = "http://me2day.net/api/start_auth?token=6ad0854c4729e936fb43d86f98defc0b";
	window.open(url, "Me2day", "width=980,height=560,location=no,directoryies=no,resizable=no,status=no");
}  
 
function loginYozm() {
	var url = "http://www.reecho.net/include/reecho/reechoSNS_yozm.php?site=" + window.location.href;
	window.open(url, "yozm", "width=500,height=350,location=no,directoryies=no,resizable=no,status=no");
}  
 
function loginClog() {
	var url = "http://www.reecho.net/include/reecho/reechoSNS_clog.php?site=" + window.location.href;
	window.open(url, "clog", "width=500,height=350,location=no,directoryies=no,resizable=no,status=no");
}  


var fwin2;

function loginFacebook(apiKey) {
	var url = "http://www.facebook.com/login.php?api_key="+apiKey+"&connect_display=popup&v=1.0&next=http://www.reecho.net/oAuthASP2/fb_return.asp&fbconnect=true&req_perms=email,user_checkins,status_update,offline_access,publish_stream,read_stream,video_upload,share_item";
	fwin2 = window.open(url, "Facebook", "width=760,height=340,location=no,directoryies=no,resizable=no,status=no");

	checkChildFacebook();
}



function checkChildFacebook(){
	if(fwin2.closed){
		window.location.reload(true);
	}
	else{
		setTimeout("checkChildFacebook()",1);
	}
}



var fwin1;

function loginTwitter() {
	var url = "http://www.reecho.net/include/reecho/reechoSNS_twitter.asp?uid=" + window.location.href;
	fwin1 =  window.open(
			'/oAuthASP/twitter/authenticate.asp',
			'signIn',
			'width=800,height=420,left=' + ((screen.width/2) - 420) + ',top=' + ((screen.height/2) - 210) + ',location=0,toolbar=0,menubar=0,scrollbars=0,resizable=1'
			);
	checkChildTwitter();
}          
 
 





 function JS_requestQueryString(url){
    var currentUrl = url; //document.location.href;
    currentQueryString = url.split("?"); //document.location.search.split("?");
    //alert(currentQueryString);

    if (currentQueryString != null && currentQueryString != "") {   //쿼리스트링이 null이거나 공백이면 실행하지 않는다.
        Query = currentQueryString[1].split("%26");
        arrCount = Query.length;
        arrKeys = new Array(arrCount);  //key값 배열
        arrValues = new Array(arrCount);//value값 배열

        //Key값만큼 돌려줌
        for(i=0;i<=arrCount-1;i++){
            param = Query[i].split("=");
            arrKeys[i] = param[0];    //앞에값은 키
            arrValues[i] = param[1];  //뒤에값은 값            
        }
    }
}


