

function selectLocation(pid){ 
    if(document.getElementById('down_popup_div')){
        return ;
    }

    var div_obj = document.createElement("div");
    var background_div = document.createElement("div");

    // 绑定esc取消对话框
    document.onkeydown = function(e){
        if (document.all) {
            key_code = event.keyCode;
        } else {
            key_code = e.keyCode;
        }
        if (key_code==27) {
            cancelPopup();
            return ;
        }		
    }
    
    // 设置对话框的风格
	//getScrollTop()
    background_div.id = 'down_popup_background';
    background_div.style.position = 'absolute';
    background_div.style.left  = 0;
    background_div.style.top = '0px';
    background_div.style.background = '#333';
    background_div.style.height = getWindowLength('h')-4+'px';
    background_div.style.width = getWindowLength('w')-20+'px';
    background_div.style.filter  = 'alpha(opacity=90)';
    background_div.style.opacity = .95;
    background_div.style.MozOpacity  = .95;
    background_div.style.zIndex = '100';
	background_div.style.textAlign='left';
	// 这里需要
	background_div.onclick=cancelPopup;
    div_obj.id = 'down_popup_div';
    
    // 不透明处理
    div_obj.style.position = 'absolute';
	div_obj.style.background = '#FFF';
    div_obj.style.left   = getWindowLength('w')/2 -200+'px';	
    div_obj.style.width  = '400px';
    div_obj.style.color = 'black';
	div_obj.style.padding='0';
    div_obj.style.top = sGetScrollTop()+(window.screen.availHeight*1/4)+'px';
    div_obj.style.zIndex = '2';
    div_obj.style.float = 'left'; 

    var argv   = arguments;
	var argc   = arguments.length;  

    var innerht ='<table width="400" cellspacing=0 cellpadding=0 border=0>'
    innerht += '<tr><td style="height:40px;"><img src="images/SelectYourLocation.jpg" /></td>';
    innerht += '<Td style="text-align:right;vertical-align:top;"><a href="#" ><img src="/images/fileclose.png" title="Close" alt="Close" id="close-icon"   onclick="cancelPopup()" /></a></td></tr>';
    innerht += '<td colspan="2" style="height:40px;;text-align:center"><a href="cart.php?act=add&product_id=' + pid + '&loc=0" target="_self"><img src="images/america.jpg" ></a><span style="width:20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="cart.php?act=add&product_id=' + pid + '&loc=1" target="_self"><img src="images/outamerica.jpg" ></a></td></tr></table>';
      
    div_obj.innerHTML = innerht;
    background_div.appendChild(div_obj);
    document.body.appendChild(background_div);
    var icon = document.getElementById('close-icon'); 
}


function getWindowLength(type,debug) {
    type=(typeof type=='undefined')?'error':type;
    type=type.toLowerCase();
    var w='width';
    var h='height';
    if (w.indexOf(type)===0) {
        type='Width';
    } else if (h.indexOf(type)===0) {
        type='Height';
    } else {
        alert('wrong parameter'+type);
    }
    var attrs=['offset'+type,'scroll'+type,'client'+type,'inner'+type];
    var db=document.body;
    var de=document.documentElement;
    var r=0;
    var tmp_r=0;
    var a='';
    for (var i=0;i<attrs.length;i++) {
        a=attrs[i];
        tmp_r=db[a]>de[a]?db[a]:de[a];
        if (debug) {
            alert(a+':'+tmp_r);
        }
        if (typeof tmp_r == 'undefined' || tmp_r<r)  continue;
        c_attr=a;
        r=tmp_r;
    }
    if (debug) {
        alert(c_attr+':'+r);
    }
    return r;
}


function cancelPopup(){  
	if(document.getElementById('down_popup_background')!=null)
    document.body.removeChild(document.getElementById('down_popup_background'));  
}
function sGetScrollTop()
{
    if (document.documentElement.scrollTop!=0) { 
        return document.documentElement.scrollTop;
    }
    return document.body.scrollTop;
}
function rebuild()
{
	if(document.getElementById('down_popup_background')!=null)
	{
	
    var background_div = document.getElementById('down_popup_background');
    background_div.style.position = 'absolute';
    background_div.style.left  = 0;
    background_div.style.top = '0px';
    background_div.style.background = '#333';
    background_div.style.height = getWindowLength('h')-4+'px';
    background_div.style.width = getWindowLength('w')-20+'px';
    background_div.style.filter  = 'alpha(opacity=90)';
    background_div.style.opacity = .95;
    background_div.style.MozOpacity  = .95;
    background_div.style.zIndex = '100';
	background_div.style.textAlign='left';
	
	var div_obj = document.getElementById('down_popup_div');
    
    // 不透明处理
    div_obj.style.position = 'absolute';
	div_obj.style.background = '#FFF';
    div_obj.style.left   = getWindowLength('w')/2 -200+'px';	
    div_obj.style.width  = '400px';
    div_obj.style.color = 'black';
	div_obj.style.padding='0';
    div_obj.style.top = sGetScrollTop()+(window.screen.availHeight*1/4)+'px';
    div_obj.style.zIndex = '2';
    div_obj.style.float = 'left'; 

	}
}

window.onresize=function () {
    rebuild();
}
window.onload=function(){
var i=new Image()
	i.src="images/outamerica.jpg";
	
	i.src="images/america.jpg";
	
	i.src="images/SelectYourLocation.jpg";
	
}
