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 setCookie( cookieName, cookieValue, expireDate )
{
	var ExpDate = new Date();
	ExpDate.setTime(ExpDate.getTime() + parseInt( expireDate ) ); 

	document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + ExpDate.toGMTString() + ";";
}



var urlBuffer = location.pathname;

var uAgent = navigator.userAgent.toLowerCase();
var mFlag = false;

//alert(uAgent);
var rDomain = "http://devm.corp.doosan.com";	//개발
rDomain = "http://m.doosan.com";	//리얼
//rDomain = "http://m.doosan.com";	//리얼

//pc버전으로 보기일 경우  쿠키에 정보 저장
if(location.search.indexOf('pcVer=Y')!=-1){
	setCookie( "pcVer", "Y", 1000*60*60*1 );
}

var cookiValue = getCookie("pcVer");

// 쿠키에 Y 값이 있거나 pc버전으로 보기이면 pass
if(cookiValue=='Y' || location.search.indexOf('pcVer=Y')!=-1){
	;
}else{
	var mobilePhones = new Array('iphone','ipod','android','blackberry','windows ce','nokia','webos','opera mini','sonyericsson','opera mobi','iemobile');
	
	// mobile=Y 라는 값(모바일에서 404로 떨어짐)이 없으면
	if( uAgent!=null && location.search.indexOf('mobile=Y')==-1 ){
		for(var i=0;i<mobilePhones.length;i++){
			if(uAgent.indexOf(mobilePhones[i]) != -1){
				document.location = rDomain + location.pathname + location.search;
			}
		}
	}
}
