﻿var www_default_domain = "http://www.958shop.com/";
function ADS_SHOW_958SHOP(ads_id){
    var tt = new Date();    
    var rndQs = tt.getMilliseconds() + '_' + tt.getSeconds();    
    var span_id = "span_" + tt.getHours()+ "_" + tt.getMinutes() + "_" + tt.getSeconds()  + "_" + tt.getMilliseconds() + "_" + ads_id;
    document.write("<span id='"+ span_id +"'></span>");
    load_ads_script(www_default_domain + "ajax/ajax_www_common.aspx?Module=ADS_SHOW_958SHOP" + "&ads_id=" + ads_id + "&container=" + span_id + "&" + rndQs,ads_render,ads_id.toLowerCase());     
}
function ads_render(ads_result,div_container){
    if(typeof(ads_result) != 'undefined'){
        if(ads_result.indexOf("201 ex:") < 0){
            if(document.getElementById(div_container))
                document.getElementById(div_container).innerHTML = unescape(ads_result);                       
        }
    }
}
function load_ads_script(scriptUrl,callback,ads_id){
    var scp = document.createElement("script");
	scp.type = "text/javascript";
	scp.id = "js_" + ads_id;
	scp.src = scriptUrl;
 
	document.getElementsByTagName("head")[0].appendChild(scp);
	
	if(scp.readyState)
	{
		scp.onreadystatechange = function()
		{ 
			if(scp.readyState == "loaded")
			{
			    try{
			        if(callback && 'function' == typeof callback)callback(eval('ads_' + ads_id),eval('container_' + ads_id));
			    }catch(ex){}
			    dispose_ads_js(scp.id);			
			}
		}
	}	
	else
	{
		scp.onload = function()
		{
		    try{
			    if(callback && 'function' == typeof callback)callback(eval('ads_' + ads_id),eval('container_' + ads_id));
			}catch(ex){}
			dispose_ads_js(scp.id);
		}
	}
}
function dispose_ads_js(ele_id){
	var eleObj = document.getElementById(ele_id);
	if(eleObj && eleObj.parentNode){
		eleObj.parentNode.removeChild(eleObj);
	}
}

function setCookie_1(name,value,time){
    //time:以小时为单位
      var exp = new   Date();
      if(time != undefined)
         exp.setTime(exp.getTime() + 60*60*1000*parseFloat(time));   
      else
         exp.setTime(exp.getTime() + 60*60*1000);   
      document.cookie   = name + "="+   escape(value)   +";expires="+   exp.toGMTString();   
}   
function getCookie_1(name){ 
   var search;
   search = name + "="
   offset = document.cookie.indexOf(search) 
   if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
     return "0";
}  
function deleteCookie_1(name){ 
    var expdate = new Date(); 
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
    setCookie_1(name, "", expdate); 
}
function initStorePopAds()
{
	/*if(getCookie_1("StorePopAds20091229") != "1"){
		var link_url = "http://b2c.958shop.com/iocean/ousheng/m55.html";
		var link_title = "欧盛M55";
		var width = window.screen.width;
        var height = window.screen.height - 20;
		window.document.body.onclick  = function(){window.document.body.onclick="";window.open(link_url, "","toolbar=no,location=yes,directories=no,menubar=yes,scrollbars=yes,resizable=yes,status=yes,top=0,left=0,width="+ width  +",height=" + height);}
		setCookie_1("StorePopAds20091229","1",1);
	}*/
}

function AutoChangeSizeForImage(obj,max_width,max_height){    
	if(typeof(isneed_pop) == 'undefined')
        isneed_pop = true;
    var IsChangeSize = false;
    var obj_width = obj.width;
    var obj_height = obj.height;    
    if(obj_width - obj_height == 2) {
        obj.height = max_height;
        obj.width = obj_width * max_height / obj_height;
        return;
    }
    if(obj_width <= max_width && obj_height <= max_height) 
        return;
    if(obj_height > obj_width){//以最大的高度为准
        if(obj.height > max_height){        
            obj.height = max_height;
            IsChangeSize = true;
            obj.width = obj_width * max_height / obj_height;
        }else if(obj.width > max_width){
            IsChangeSize = true;
            obj.width = max_width; 
            obj.height = obj_height * max_width / obj_width;
        }
    }else if(obj_width > obj_height){//以最大的宽度为准
        if(obj.width > max_width){
            IsChangeSize = true;
            obj.width = max_width; 
            obj.height = obj_height * max_width / obj_width;
        }else if(obj.height > max_height){
            obj.height = max_height;
            IsChangeSize = true;
            obj.width = obj_width * max_height / obj_height;
        }
    }
}