﻿var ICExpat = function(custId, divId) {
    this.custId = custId;
    this.refId = "";
    this.cnName = "";
    this.enName = "";
    this.cnAddress = "";
    this.enAddress = "";
    this.searchKey = "";
    this.tel = "";
    this.host = "http://www.icexpat.com";

    this.img = "";
    this.desc = "";

    this.divId = divId;
    this.debug = false;

    this.mid = "";
    this.name = "";
    this.addr = "";
}
 
ICExpat.prototype.SetRefId=function(refId)
{
	this.refId = refId;
}
ICExpat.prototype.SetChineseName=function(cnName)
{
	this.cnName = cnName;
}
ICExpat.prototype.SetEnglishName=function(enName)
{
	this.enName = enName;
}
ICExpat.prototype.SetChineseAddress=function(cnAddress)
{
	this.cnAddress = cnAddress;
}
ICExpat.prototype.SetEnglishAddress=function(enAddress)
{
	this.enAddress = enAddress;
}
ICExpat.prototype.SetTel=function(tel)
{
	this.tel = tel;
}
ICExpat.prototype.SetHost=function(host)
{
	this.host = host;
}
ICExpat.prototype.SetSearchKey=function(key)
{
	this.searchKey = key;
}
ICExpat.prototype.SetImg=function(img)
{
	this.img = img;
}
ICExpat.prototype.SetSearchKey=function(desc)
{
	this.desc = desc;
}
ICExpat.prototype.SetDebug=function(debug)
{
	this.debug = debug;
}

ICExpat.prototype.LogFile = function(content,fileName) 
{   
    if(!fileName)
	 {
	 	fileName="c:\\icexpat.txt";
	 }
	var  fso,f,r ;  
	var ForReading=1;  
	var ForWriting=2;   
	fso = new ActiveXObject("Scripting.FileSystemObject");
	f = fso.OpenTextFile(fileName,   ForWriting,   true);   
	f.Write(content);   
	f.Close();   
	fso=null;
}

function CheckResize(frmObj) {
    if (frmObj == null) {
        return;
    }
    if (frmObj && !window.opera) {
        if (frmObj.contentDocument && frmObj.contentDocument.body.offsetHeight) {
            frmObj.height = frmObj.contentDocument.body.offsetHeight;
        }
        else if (frmObj.Document && frmObj.Document.body.scrollHeight) {
            frmObj.height = frmObj.Document.body.scrollHeight;
        }
    }
};

ICExpat.prototype.Render = function()
{
   var divDom = document.getElementById(this.divId);
   if (divDom == null) {
   	alert(this.divId + " dose not exists.");
   	return;
   }
   var height= divDom.style.height+2;
   var width = divDom.style.width+1;
   var queryString ="";
   queryString =this.host+"/OuterPage/ExpatMapPage.aspx?cid=" + this.custId +
                "&refId=" + this.refId +
				"&cnName=" + encodeURIComponent(this.cnName) +
				"&enName=" + encodeURIComponent(this.enName) +
				"&cnAddr=" + encodeURIComponent(this.cnAddress) +
				"&enAddr=" + encodeURIComponent(this.enAddress)+
				"&tel=" + encodeURIComponent(this.tel)+
				"&rd=" + 50000*Math.random();
   if(this.debug==true)
   {
	  alert(queryString);
   }
   queryString =queryString.replace(/\'/g,"_XX_");
   var iframe = "<iframe onload='CheckResize(this)' id='F" + this.custId + "' frameborder=0" + " scrolling='no' height='" + height + "' width='100%' src='" + queryString + "' style='z-index:600px' ></iframe>";
   divDom.innerHTML = iframe;
}
 
ICExpat.prototype.RenderDistrict = function(districtId)
{
  if(districtId==null)
	districtId="";
   var divDom = document.getElementById(this.divId);
   if (divDom == null) {
     	alert(this.divId + " dose not exists.");
     	return;
   }
   var height= divDom.style.height;
   var width = divDom.style.width;
   var queryString = this.host+"/OuterPage/ExpatMapDistrict.aspx?cid=" + this.custId +
                "&district=" +districtId ;
   if(this.debug==true)
   {
	  alert(queryString);
   }
   var iframe = "<iframe onload='CheckResize(this)' id='F" + this.custId + "' frameborder=0" + " scrolling='no' height='" + height + "' width='100%' src='" + queryString + "' style='z-index:600px' ></iframe>";
   divDom.innerHTML = iframe;}
/*-----------------------------------------------------*/
ICExpat.prototype.SetName = function(name) {
    this.name = name;
}
ICExpat.prototype.SetMid = function(mid) {
    this.mid = mid;
}
ICExpat.prototype.SetAddr = function(addr) {
   this.addr = addr;}

ICExpat.prototype.RenderSubMap = function(channel) {
    var divDom = document.getElementById(this.divId);
    if (divDom == null) {
        alert(this.divId + " dose not exists.");
        return;
    }
    var height = divDom.style.height;
    var width = divDom.style.width;
    var queryString = this.host + "/MapChannel.aspx?cid=" + this.custId +
                      "&channel=" + channel +
                      "&mid=" + encodeURIComponent(this.mid) +
                      "&name=" + encodeURIComponent(this.name) +
                      "&key=" + encodeURIComponent(this.desc) +
                      "&addr=" + encodeURIComponent(this.addr); 
    if (this.debug == true) {
        alert(queryString);
    }
    if (height == null || height < 100)
        height = 100;
    queryString = queryString.replace(/\'/g, "_XX_");
    var iframe = "<iframe onload='CheckResize(this)' id='F" + this.custId + "' frameborder=0" + " scrolling='no' height='" + height + "' width='100%' src='" + queryString + "' style='z-index:900px' ></iframe>";
    divDom.innerHTML = iframe;
}
 