﻿// Demo使用的JScript文件

///////////////////////////////////////////////
// 关于对话框的脚本
///////////////////////////////////////////////
/// 
/// 显示提醒信息
///
function ShowDialog_Alert(msg)
{
  try
  {
    if (IsShowDialogAlert())
    {
      //alert(document.cookie);
      alert(msg);
      ClearShowDialogAlert();
    }
   }
   catch(e)
   {
   } 
    // 把所有cookie显示出来
    // alert(document.cookie);
}

///
/// 提示输入信息
///
function ShowDialog_Prompt(msg)
{
  return prompt(msg);
}

/// 
/// 确认某信息
/// 
function ShowDialog_Confirm(msg)
{
  return confirm(msg);
}

///
/// 多选删除时的提示信息
///
function ShowDialog_Delete_Confirm()
{
  return confirm("你确认删除所选信息吗？");
}

/// 
/// 确认删除某信息时的提示信息
/// 
function ShowDialog_Delete_Confirm_Msg(msg)
{
  return confirm("你确认删除 " + msg  + " 吗？");
}

///////////////////////////////////////////////
// 关于Cookie相关脚本
///////////////////////////////////////////////

/// 
/// 通过Cookie中的值判断是否应该显示对话框
///
function IsShowDialogAlert()
{
  var cookies = document.cookie;
  var settings = GetKeyValue(cookies,"PageSettings");
  
  // if (settings != "")
  {
    var alerted = GetKeyValue(settings,"alerted");
    var alertedkey = GetKeyValue(cookies,"alerted");
    var alerted = GetKeyValue(cookies,alertedkey);
    if (alerted != "")
    {
      return false;
    }
  }
  
  return true;
}

///
/// 清除Cookie中控制是否显示对话框的标志
///
function ClearShowDialogAlert()
{
  var cookies = document.cookie;
  var settings = GetKeyValue(cookies, "PageSettings");
  
  //if (settings != "")
  {
    //settings = SetKeyValue(settings,"alerted","1");
    //cookies = SetKeyValue(cookies, "PageSettings", settings);
    var alertedkey = GetKeyValue(cookies,"alerted");
    cookies = SetKeyValue(cookies,alertedkey,"1");
  }
  //document.cookie = "";
  document.cookie = cookies;
  //document.cookie = cookies;
}

///
/// 取形如keyname=keyvalue这样的键值对
///
function GetKeyValue(source,key)
{
  key += "=";
  var pos = source.indexOf(key);
  if (pos > -1)
  {
    // 取出key对应的值
    var start = pos + key.length;
    var end = source.indexOf(";",start);
    if (end == -1)
    {
      end = source.length;
    }
    
    var value = source.substring(start,end);
    
    return (value);
  }
  
  return "";
}

///
/// 设置形如keyname=keyvalue这样的键值对
///
function SetKeyValue(source , key, value)
{
  key += "=";
  var pos = source.indexOf(key);
  if (pos > -1)
  {
    // 设置对应的指定值
    var start = pos + key.length;
    var end = source.indexOf(";", start);
    if (end == -1)
    {
      end = source.length;
    }
    
    var value = source.substring(0,pos) + 
      key + (value) +
      source.substring(end,source.length);
    
    return value;
  }
  
  return (key + value);
}


///////////////////////////////////////////////
// 关于按钮相关脚本
///////////////////////////////////////////////

///
/// 回退按钮的点击响应事件
///
function Actions_Button_Back(url)
{
  if (history.length>0)
  {
    window.locaton.href=url;
  }
  else
  {
    window.close();
  }
}

///
/// Demo中按钮命令的默认处理函数
///
function Actions_Button_Close(backLength)
{
  if (history.length>0)
  {
    history.back(backLength);
  }
  else
  {
    window.close();
  }
}

var merge_div_obj=null;
///
/// 显示鼠标移到指定控件后显示选择数据层
///
function Actions_Merge_Mouse_Down(divId,dataId)
{
  // 找到指定的Div对象
  var obj = null;
  var objData =null;
  obj = window.document.getElementById(divId);
  
  if (obj != null)
  {
    // 确定显示位置
    objData = window.document.getElementById(dataId);
    if (null != objData)
    {
      // obj.style = objData.style;
      
    }
    
    
    // 显示在最前面
    obj.style.position = "absolute";// "relative";
    obj.style.display = "block";
    obj.style.left="200px";
    obj.zIndex = "1";
    
    // 把接收结果的数据对象赋给Div对象
    
  }
}

function Actions_Merge_Mouse_Select(sourceId,dataId)
{
  var obj = null;
  var objData = null;
  obj = window.document.getElementById(sourceId);
  objData = window.document.getElementById(dataId);
   
  if (null != obj && null != objData)
  {
    objData.value = obj.outerText;
    // obj.value;
    
    obj.parentNode.style.display = "none";
  }
}


///
/// 对一个对象进行隐藏关闭显示操作
///
function ShowHide_Object_Alternative(divId)
{
  var obj = null;

  obj = window.document.getElementById(divId);
  if (null != obj)
  {
    if (obj.style.display == null || "none" == obj.style.display )
    {
      obj.style.display ="block";
    }
    else
    {
      obj.style.display ="none";
    }
  }
}

///
/// 显示指定的第一个对象，隐藏指定的第二个对象
///
function ShowHide_Object(showId,hideId)
{
  Object_Hide(hideId);
  
  Object_Show(showId);
}

///
/// 显示指定的对象
///
function Object_Show(showId)
{
  var obj = null;

  obj = window.document.getElementById(showId);
  if (null != obj)
  {
    obj.style.display ="block";
  }
}

///
/// 隐藏指定的对象
///
function Object_Hide(hideId)
{
  var obj = null;

  obj = document.getElementById(hideId);
  if (null != obj)
  {
    obj.style.display ="none";
  }
}

///
/// 在给定相对路径的情况下显示选择商品弹出界面
///
function ShowDialog_Select_Product(urlRelatedPath)
{
  window.open(urlRelatedPath+"product/catalog/ProductSelectForm.htm","_blank","width=400px;height=300px");
}

///
/// 显示选择客户行业类别的弹出界面
///
function ShowDialog_Select_Customer_Industry(urlRelatedPath)
{
  window.open(urlRelatedPath+"CustomerIndustrySelect.htm","_blank","width=400px;height=200px");
}

function ShowDialog_View_Product(urlRelatedPath)
{
  window.open(urlRelatedPath+"product/Catalog/ProductInfo.htm","_blank");
}


