
//Google 통계


//init

$(document).ready(function($){
	
	//loading 
	
	$('<div id="Loading" style="width:32px;height:32px"><img src="/images/ajax-loader.gif"></div>').css({
		'display':'none'
		,'position':'absolute'
		,'opacity':'0.9'
		,'left':$(document).width()/2 - 18
		,'top':$(document).height()/2 - 18
	}).appendTo(document.body);
	
	$(document).ajaxStart(function(){
		$('#Loading').css('display', 'block');
	}).ajaxStop(function(){
		$('#Loading').css('display', 'none');
	});
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-27211194-1']);
_gaq.push(['_setDomainName', 'ghpark.com']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


// flash
function flashWrite(url,w,h,id,bg,vars,win){

	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
	"<param name='allowScriptAccess' value='always' />"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='FlashVars' value='"+vars+"' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='menu' value='false' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";

	document.write(flashStr);
}



// right scroll image
function firstClass(elID,tagName) {
	try{
		var el = document.getElementById(elID).getElementsByTagName(tagName);
		el.item(0).className = el.item(0).className + " first";
	}catch(E){}
}


function initMoving(target, topPosition, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;

	obj.initTop = topPosition;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;
	obj.style.top = obj.top + "px";

	obj.getTop = function() {
		if (document.documentElement.scrollTop) {
			return document.documentElement.scrollTop;
		} else if (window.pageYOffset) {
			return window.pageYOffset;
		} else {
			return 0;
		}
	}
	
	obj.getHeight = function() {
		if (self.innerHeight) {
			return self.innerHeight;
		} else if(document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		} else {
			return 500;
		}
	}

	obj.move = setInterval ( function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30);
}

// namecheck selection


function changeMod(opt){
	
	if(opt === "name"){
		document.getElementById('num_check').style.display = "block";
		document.getElementById('ipin_check').style.display = "none";
	}else{
		document.getElementById('ipin_check').style.display = "block";
		document.getElementById('num_check').style.display = "none";
	}
}

//시작 페이지로
function setHomepage(){

	
	if (document.all){
        document.body.style.behavior='url(#default#homepage)';
  		document.body.setHomePage('http://www.ghpark.com');

    }
    else if (window.sidebar){
    	if(window.netscape){
        	try{  
         		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         	}  
         	catch(e){  
            	//alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");  
            	alert("지원되지 않는 브라우져 입니다.");  
         	}
    	} 
    	var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    	prefs.setCharPref('browser.startup.homepage','http://www.kerala.in');
 	}else{
 		alert("지원되지 않는 브라우져 입니다.");  
 	}
}

function check_registno(registno1, registno2) {                     // 주민번호 유효성 체크
    var yy = registno1.substr(0, 2);            // 년
    var mm = registno1.substr(2, 2);            // 월
    var dd = registno1.substr(4, 2);            // 일
    var gender = registno2.substr(0, 1);        // 성별

    // 앞자리 체크
    if (registno1 == "") {
        return false;
    }
    if (registno1.length != 6) {
        return false;
    }
    for (var i = 0; i < registno1.length; i++) {
		if (registno1.charAt(i) < "0" || registno1.charAt(i) > "9") {
			return false;
		}
	}

	// 뒷자리 체크
	if (registno2 == "") {
        return false;
    }
    if (registno2.length != 7) {
        return false;
    }
    for (var i = 0; i < registno2.length; i++) {
		if (registno2.charAt(i) < "0" || registno2.charAt(i) > "9") {
			return false;
		}
	}

	// 앞자리 년월일 형식
	if (yy < "00" || yy > "99" || mm < "01" || mm > "12" || dd < "01" || dd > "31") {
	    return false;
	}

	// 성별체크
	if (gender < "1" || gender > "4") {
	    return false;
	}

	// 세기(century)별 날짜 유효성 체크
	if (gender == "1" || gender == "2") {
	    cc = "19";
	}
    else {
        cc = "20";
    }

    // if (check_date(parseInt(cc+yy), parseInt(mm), parseInt(dd)) == false) {
    //     return false;
    // }

    // check digit
    n = 2;
    sum = 0;

    for (i = 0; i < registno1.length; i++) {
        sum += parseInt(registno1.substr(i, 1)) * n++;
    }
    for (i = 0; i < registno2.length - 1; i++) {
        sum += parseInt(registno2.substr(i, 1)) * n++;
        if (n == 10) {
            n = 2;
        }
    }

    c = 11 - (sum % 11);
    if (c == 11) {
        c = 1;
    }
    if (c == 10) {
        c = 0;
    }

    if (c != parseInt(registno2.substr(6, 1))) {
        return false;
    }
    else {
        return true;
    }
}

function check_string_length(str, min, max) { 	// 텍스트 길이 체크
	if (str.length < min || str.length > max) {
        return false;
    }
    return true;
}

function check_lowercase_number(str) { 			// 영문소문자/숫자 체크
	var pattern = /[a-z0-9]/;
	for (var i = 0; i < str.length; i++) {
		if (pattern.test(str.charAt(i)) != true) {
			return false;
		}
	}
    return true;
}

function check_number(str) { 					// 숫자 체크
	var pattern = /[0-9]/;
	for (var i = 0; i < str.length; i++) {
		if (pattern.test(str.charAt(i)) != true) {
			return false;
		}
	}
    return true;
}

function window_open(url, name, width, height, scrollbars) {
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;

    var features = "left=" + left + ", top=" + top + ", width=" + width + ", height=" + height + ", scrollbars=" + scrollbars;
    window.open(url, name, features);
}


/**
 * 우편번호 찾기
 *gSearchPost({
		"zip1":$('#zip01').get(0),
		"zip2":$('#zip02').get(0),
		"adress1":$('#adress1').get(0),
		"adress2":$('#adress2').get(0),
	});
 */
function gSearchPost(obj){
	window_open("/user/searchZip.php?zip1="+obj.zip1+"&zip2="+obj.zip2+"&address1="+obj.address1+"&address2="+obj.address2, "zip_search", 503, 480, "yes");
	
}

function gRt_replace(rt_content){
	var content = rt_content;
	content = content.replace("'","\'");
	content = content.replace("\"","\\\"");
	return content;
}

//SNS 로 보내기
//sns_name, query, id
function sendSNS(obj){
	var url = "";
	
	alert(obj.query);
	if(obj.sns_name === "twitter"){
		
		
		url = "http://twitter.com/share?url=";
		
		if(obj.query) url +="&text="+obj.query;
		if(obj.id) url += escape(" http://www.ghpark.com/main/article_view.php?id="+obj.id);
		
	}else if(obj.sns_name === "facebook"){
		url = "http://www.facebook.com/share.php?v=4&src=bm";
		
		if(obj.id) url += "&u=http://www.ghpark.com/main/article_view.php?id="+obj.id;
		else url += "&u=www.ghpark.com";
			
		url += "&t="+obj.query;
		
	}else if(obj.sns_name === "me2day"){
		url = "http://me2day.net/posts/new?new_post[body]="+obj.query+" ";
		
		if(obj.id) url += "http://www.ghpark.com/main/article_view.php?id="+obj.id;
		
	}else{
	}
	
	url += " @GH_PARK";
	
	window_open(url, "sns_pop", $(document).width(), $(document).height(), "yes");
	
	
}

//계정기부하기
function account_dona(obj){
	
	window_open("/account_dona.php", "account_dona", 730, 600, "yes");
}

//Send Wiki
function gSendWiki(ar_id){
	if(ar_id === ""){
		alert("기사 코드가 존재하지 않습니다.");
		return;
	}
	window_open("/main/sendWikiProcess.php?ar_id="+ar_id, "sns_pop", "734px", $(document).height(), "yes");
}




