﻿// JScript File
var cookieName = "showCategoryPane";
var ResultPaneCookieName = "showResultPaneCookie";

function toggleDivDisplay(checkboxID,divToChangeID)
{
  checkbox=getElem(checkboxID);
  divToChange=getElem(divToChangeID);
  toggleElemDisplay(checkbox,divToChange);
}
function toggleElemDisplay(checkbox,divToChange)
{
  if(checkbox.checked)
    showDiv(divToChange);
  else
    hideDiv(divToChange);
}

function showDiv(divToChange)
{
  var divStyle = getDivStyle(divToChange);
  /* align span inline, other block*/
  if(divToChange.tagName != 'SPAN'){
        divStyle.display='block';
    }
  else{
        divStyle.display='inline';
    }
  divStyle.visibility='visible';
}
//function showDivInline(divToChange)
//{
//  getDivStyle(divToChange).display='inline';
//}
function hideDiv(divToChange)
{
  var divStyle = getDivStyle(divToChange)
  divStyle.display='none';
  divStyle.visibility='hidden';
}
function getDivStyle(divToChange)
{
  var elem, vis;
//  var divName = "__outerCategoryDiv"
//  if( document.getElementById ) // this is the way the standards work
//    elem = document.getElementById( divName );
//  else if( document.all ) // this is the way old msie versions work
//    elem = document.all[divName ];
//  else if( document.layers ) // this is the way nn4 works
//    elem = document.layers[divName ];
//  vis = elem.style;
  vis = divToChange.style;
  return vis;
}
//function test(){
//    alert("test");
//}
function ShowStoreDetail()
{   
    var checkbox=getElem("__ChkShowStoreDetail")
    var id=gup('id');
    if (id!="")
      checkbox.checked=true;
    else
      checkbox.checked=false;
    var span = getElem("__spanShowStoreDetail");  
    span.style.display = (checkbox.checked)?"inline":"none";
    showRightBar();
}
function getElem(name){
    var elem;
    if( document.getElementById ) // this is the way the standards work
      elem = document.getElementById( name );
    else if( document.all ) // this is the way old msie versions work
      elem = document.all[name ];
    else if( document.layers ) // this is the way nn4 works
      elem = document.layers[name ];
    return elem;
}
function showRightBar()
{
  var checkbox=getElem("__ChkShowStoreDetail");
  var ParentContainer=getElem("__outterMapResultPane");
  var leftDiv=getElem("__Map");
  var rightDiv=getElem("__storeDetail");
  toggleElemDisplay(checkbox,rightDiv)
  var new_width = 0;
  if(checkbox.checked)
    new_width =(parseInt(ParentContainer.style.width) - parseInt(rightDiv.style.width)) + 'px';
  else
    new_width = ParentContainer.style.width;
  leftDiv.style.width=new_width
}

function gup( name )
{  
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS );  
    var results = regex.exec( window.location.href );  
    if( results == null )    
      return "";  
    else    
      return results[1];
}

function CopyDivContent(fromID,toID)
{
    getElem(toID).innerHTML = getElem(fromID).innerHTML;
}


function Get_ShowCategory_status(name)
{
    var checkbox=getElem(name);
    var value=Get_Cookie(cookieName);
    var result=true;
    if (value==null || value!="1")
      result=false; 
    checkbox.checked=result;
}

function Get_ShowResultPane_status(name)
{
    var checkbox=getElem(name);
    var value=Get_Cookie(ResultPaneCookieName);
    var result=false;
    if (value==null || value=="1")
      result=true; 
    checkbox.checked=result;
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		// cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		cookie_name = trim(a_temp_cookie[0]);
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				// cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				cookie_value = unescape( trim(a_temp_cookie[1]) );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function trim(value)
{
    return value.replace(/^\s+|\s+$/g, '');
}

function Set_ShowCategory(value)
{
     //alert("Set_ShowCategory");
     Set_Cookie(cookieName,value);
}
function Set_ShowResultPane(value)
{
     //alert("Set_ShowResultPane");
     Set_Cookie(ResultPaneCookieName,value);
}

function Set_Cookie(name,value) 
{
    var numValue=0;
    if(value)
      numValue=1;
    document.cookie = (name + "=" +escape( numValue ));
}
	