function doCancel() {
    self.close();
}

function FetchDirection() {
    document.getElementById('hiddenFiled').click();
}

function storeresultprint()
{
	var expandedStore = document.getElementById("selectedStore").value;
    window.open("storefinderresultsprint.jsp?storeIndex="+expandedStore,"printjsp","resizable=no,menubar=no,status=no,toolbar=no,width=705,height=680,scrollbars=yes"); 
}

function IsEmpty(){
   var error="";
   if ((document.getElementById('nickname').value.length==0) ||
   (document.getElementById('nickname').value==null) ||
   (document.getElementById('nickname').value=='e.g., Work, Home')) {
       //alert("Please specify the Nick Name");
        error="Please specify the Nickname";
        document.getElementById('mylabel').innerHTML = error;
            return false;
   }
   else{ 
       setTimeout('window.close()',2000);
       return true; 
   }
}

function displaykey(){
   
    if(event.keyCode==13){
        	document.getElementById('image211').click();
        	return false;
    }
     return true;
}


function displayAddFavkey(){
    if(event.keyCode==13){
    	document.getElementById('addStoreButton').click();
    	return false;
    }
   return true;
}


function onCheck(closeParam){
    document.getElementById('closeParam').value=closeParam;
    if(!(document.getElementById('closeParam').value=="")){
         if(document.getElementById('closeParam').value=="yes"){
            self.close();
         }
    }
}

function clickEdit(){
    window.name="editStore";
}

 function nameStoreWindow(){
    window.name="addStore";
}

function onEnter( evt, frm ) {
var keyCode = null;
if( evt.which ) {
keyCode = evt.which;
} else if( evt.keyCode ) {
keyCode = evt.keyCode;
}
if( keyCode==13 ) {
	
    document.getElementById(frm).click();
    return false;
}
return true;
}

function onEnterFromCheckout( evt, frm ) {
var keyCode = null;
if( evt.which ) {
keyCode = evt.which;
} else if( evt.keyCode ) {
keyCode = evt.keyCode;
}
if( keyCode==13 ) {
    document.getElementById(frm).click();
    return false;
}
return true;
}

function storeexists() {
	if (window.showModalDialog) {
		window.showModalDialog('alreadyfavorite.jsp',' Store Alreay exists','dialogWidth:480px;dialogHeight:225px;resizable:no;help:no;status:no;scroll:no');
	} else {
		window.open("alreadyfavorite.jsp", " Store Alreay exists", "width=480,height=225,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}
    
function nicknameempty() {
	if (window.showModalDialog) {
		window.showModalDialog('nicknameempty.jsp',' Store Alreay exists','dialogWidth:380px;dialogHeight:225px;resizable:no;help:no;status:no;scroll:no');
	} else {
		window.open("nicknameempty.jsp", " Store Alreay exists", "width=380,height=225,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function nicknameexists() {
	if (window.showModalDialog) {
		window.showModalDialog('nicknameexists.jsp',' Store Alreay exists','dialogWidth:480px;dialogHeight:240px;resizable:no;help:no;status:no;scroll:no');
	} else {
		window.open("nicknameexists.jsp", " Store Alreay exists", "width=480,height=240,scrollbars=no,titlebar=no,alwaysRaised=yes,dialog,modal=yes");
	}
}

function clickAdd(){
    window.name="addStore";
    
}

function clickCheckoutAdd(){
    
    window.name="addCheckoutStore";
}

function selectStoreById(storeId){
    document.getElementById("currentStoreId").value = storeId;     
    document.getElementById("storeIdsubmit").click();
}

function submit(){
    document.getElementById('reverse').value="true";
    document.getElementById("hiddenAddimage").focus=false;
    document.getElementById("hiddenAddimage").click();
}

function submitDirectionsPrint(){
    document.getElementById("submitDirectionsPrintButton").focus=false;
    document.getElementById("submitDirectionsPrintButton").click();
}

function similarAddress(s){
    document.findbyaddress.addressMismatch.value=s;
    document.getElementById('find7').click();
} 

 function newwindow(storeId)
{
    window.open("storedetailsprint.jsp?getStoreID="+storeId,"printjsp","resizable=no,menubar=no,status=no,toolbar=no,width=705,height=680,scrollbars=yes"); 
}

function hidedivs() {
var els = document.getElementsByTagName( 'div' );
var num = els.length;
for( var i = 0; i<num; i++ ) {
if( els[i].id.indexOf( 'win' )==0 ) {
els[i].style.display = 'none';
}
}
}
function hide_window(named)
{
    //get the named window
    var window_element = document.getElementById(named);
    //hide it with a style attribute
    window_element.style.visibility = "hidden";
}

function map_coordinates() {
    var height = 465;
    var width = 465;
    return [height,width];
}

function findPos(obj, named, e) {
    if (navigator.appName=="Netscape") {
        var window_element = document.getElementById(named);
        var curleft = curtop = 0;
        
        curleft = e.clientX - obj.offsetWidth + 5;
        curtop = e.clientY + 10;
    
        var map = map_coordinates();

        if (curtop + window_element.offsetHeight > map[0]) {    
            curtop = map[0] - window_element.offsetHeight;
        }
    
        if (curleft + window_element.offsetWidth > map[1]) {
            curleft = map[1] - window_element.offsetWidth;
        }
    
    }
    
    if (navigator.appName=="Microsoft Internet Explorer") {
        var window_element = document.getElementById(named);
        var curleft = curtop = 0;
        if (obj.offsetParent) {
            curleft = obj.offsetLeft
            curtop = obj.offsetTop
        
            var map = map_coordinates();
    
            if (window_element.offsetHeight > (map[0] - obj.offsetTop)) 
                curtop = curtop - (window_element.offsetHeight - (map[0] - obj.offsetTop));
        
            if (window_element.offsetWidth > (map[1] - obj.offsetLeft))
                curleft = curleft - (window_element.offsetWidth - (map[1] - obj.offsetLeft));
        
            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
            }

        }

    }

    return [curleft,curtop];    
}


    //

//Display a named window, at the position of another object
function display_window(parent,named, e)
{

    //get the named window
    var window_element = document.getElementById(named);
    window_element.style.visibility = "visible";
    //override the 'display:none;' style attribute
    window_element.style.display = "";
    //get the placement of the element that invoked the window...
    var placement = findPos(parent,named, e);
    //document.print(placement[0]);
    //...and put the window there
    window_element.style.left = placement[0] + "px";
    window_element.style.top = placement[1] + "px";
    
}


function close_window(parent,named)
{
    //get the named window
    var window_element = document.getElementById(named);
    //override the 'display:none;' style attribute
    window_element.style.visibility = "hidden";
    //get the placement of the element that invoked the window...
        
}

//Hide a named window
function hide_window(named)
{
    //get the named window
    var window_element = document.getElementById(named);
    //hide it with a style attribute
    window_element.style.display = "none";
}

function onEnterForm( evt, frm ) {
var keyCode = null;
if( evt.which ) {
keyCode = evt.which;
} else if( evt.keyCode ) {
keyCode = evt.keyCode;
}
if( keyCode==13 ) {
    
    document.getElementById(frm).hiddenFiled.click();
    return false;
}
return true;
}

function keyStoreHandler(buttonName)
{
        var keyCode = null;
        if( event.which ) {
        keyCode = event.which;
        } else if( event.keyCode ) {
        keyCode = event.keyCode;
        }
      if (keyCode== 13)
      {
        var obj = document.getElementById(buttonName);
        obj.click();
        return false;
      }
     
      if ((keyCode < 48) || (keyCode > 57)){
      	event.returnValue=false;
      }
     
      return true;
        
}

function expandStore(index){
	if(document.getElementById("selectedStore").value == index) {
		document.getElementById("selectedStore").value = 1;
	} else {
		document.getElementById("selectedStore").value = index;
	}
}
