keyandvalues = null;

// for pc top page
function main_pc(){
	if(is_useragent_iphone() && !is_pc_btn_clicked()){
		redirect_to_iphone();
	
	}else if(is_useragent_android() && !is_pc_btn_clicked()){
		redirect_to_android();
	}
}	

// for iphone top page
function main_iphone(){
	hide_url();
	if(is_useragent_pc() || (is_useragent_iphone() && is_pc_btn_clicked())){


		redirect_to_com();
	} else if(is_useragent_android()){
		redirect_to_android();
	}else {

	
	}
}
//for android top page
function main_android(){
	hide_url();
	if(is_useragent_pc() || (is_useragent_android() && is_pc_btn_clicked())){

		redirect_to_com();
	}else if(is_useragent_iphone()){
		redirect_to_iphone();
	}
}

//for smartphone help page
function main_smartphone_help(){
	if(is_useragent_iphone() || is_useragent_android()){
		redirect_to_smartphone_help();
	}

}

function is_useragent_iphone(){
	
	agent=navigator.userAgent;
	if((agent.indexOf('iPhone')>0 && agent.indexOf('iPad') == -1)||
   		agent.indexOf('iPod')>0){
	
		
		return true;
	}
	else {
	
		return false;
	}
}

function is_useragent_android(){
	agent=navigator.userAgent;
	if(agent.indexOf('Android')>0 && agent.indexOf('Mobile')>0){
		return true;
	}
	else {
		return false;
	}
}


function is_useragent_pc(){
	if(is_useragent_iphone() || is_useragent_android()){
		return false;
	}
	else{
		return true;
	}
}


function redirect_to_iphone(){

	location.href = '/smartphone/iphone/index.html';

}
function redirect_to_android(){
	location.href = '/smartphone/android/index.html';
}

function redirect_to_com(){


	location.href = '/index.html';
}

function redirect_to_smartphone_help(){
	location.href = '/support/faq/smartphone/tool/main/iphone/index.html';
}

function set_cookie(key, value){



//cookie hold 10minutes
	var d = new Date();
	d.setTime(d.getTime() + (1000*60*10)); 
	var expires = d.toGMTString();
	data =  key + "=" + escape(value) + "; " + "expires=" + expires + "; " + "path=/";
//	data =  key + "=" + escape(value) + "; " + "path=/";
	document.cookie =  data;

}

function get_cookie(key){
   keyandvalues = document.cookie;

   keyandvalues = keyandvalues.split("; ");
   var rvalue=null;
   for(i = 0; i<keyandvalues.length;i++){
	var nandv = keyandvalues[i].split("=");
	if(nandv[0]==key)rvalue=nandv[1];
   }
   return rvalue;
}
sbtn="smartphone_btn";
sclicked="clicked";
isCookie=null;

//for iphone top page and android top page
function to_pc_btn_click(){

/*
	if(!navigator.cookieEnabled && is_useragent_iphone()){
		alert("PCサイトを表示する場合は、お手数ですがCookieを有効にしてください。");
	}else{
*/
		set_cookie(sbtn,sclicked);
		redirect_to_com();
//	}
}


function is_pc_btn_clicked(){
	isCookie=get_cookie(sbtn);
	if(isCookie==sclicked){
		
		return true;
	}
	else{
		return false;
	}
}
function hide_url(){
	window.scrollTo(0,1);
}
function smapholink(){

        if(is_useragent_iphone() || is_useragent_android()){

	p=document.getElementById("tosmapholink");
	
	var slink="<div><a href=\"javascript:void(0)\" onClick=\"to_smapho_btn_click(); javascript:urchinTracker(\'/outlinksfromTop/toSmapho\');\">> スマートフォン版に切り替え</a></div>";

	p.innerHTML = slink;


	}

}

function delete_cookie(key){
    var d = new Date();
    d.setYear(d.getYear() -1);
    var expires = d.toGMTString();
    data = key + "=" + ";expires=" + expires + "; " + "path=/";
    document.cookie = data;
}


function to_smapho_btn_click(){
		delete_cookie(sbtn);
		redirect_to_iphone();
}



