﻿// JavaScript Document

var Check_Img = "/images/check.gif";

function CheckStrExist(str,regu1) {
	var regu =   "^" + regu1 + ""     
	var re   = new RegExp(regu);     
	if (str.search(re) != -1)      
	{     
		return 1;   
	}     
	else     
	{   
		return 0;
	} 
}

function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		try {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}catch (e1) {
			http = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	else if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
	}
	return http;
}

function $(id)
{
	return document.getElementById(id);
}

function MM_swapImageSrc(id,src)
{
	$(id).src=src;
}

function CheckMsn(url,mid)
{
	var http = createXMLHttpRequest();	
	
	if(http)
	{		
	  http.open('GET',url,true); //提交方式 GET,POST 
	  http.send("");
	  
	  
	  http.onreadystatechange=function()
	  {
		  alert(http.getResponseHeader("Location"));
		  alert(http.status);	
		 	 if(http.readyState==4){   //xmlhttp对象读取服务器响应结束
				
				if(http.status==200)// 返回后判断时候成功
				{ 
					var val = http.ResponseBody;	

					if(CheckStrExist(val,"Offline")==1)
					{
						MM_swapImageSrc(mid,'/img/support_offline.gif');
					}
					else
					{
						MM_swapImageSrc(mid,'/img/support_online.gif');
					}						 
				}
		   }else{
				MM_swapImageSrc(mid,Check_Img);
		   }
	  } 
	}
}

//提交留言
function CheckFeedbackFrm(d,mid1,mid2,mid3)
{
	if(trim(d.LinkMan.value)=="")
	{	

		$(mid1).innerHTML= " <font color='red'>LinkMan can not be blank, Please re-enter.</font>";	
		return false;
	}
	else
	{
		$(mid1).innerHTML= "";
	}
	
	if(trim(d.Tel.value)=="")
	{	
		$(mid2).innerHTML= " <font color='red'>Tel can not be blank, Please re-enter.</font>";	
		return false;
	}
	else
	{
		$(mid2).innerHTML= "";
	}	
	
	if(isEmail(trim(d.Email.value))==false)
	{
		$(mid3).innerHTML= " <font color='red'>Email is wrong, Please re-enter.</font>";	
		return false;
	}	
	else
	{
		$(mid3).innerHTML= "";
	}
}

function Shop_List_View(ID)
{	
	var http = createXMLHttpRequest();
	if(http)
	{	
	  var url = '../Shop_List_View.asp?ID=' + trim(ID);
	  http.open('POST',url,true); //提交方式 GET,POST 
	  http.send(null);
	  http.onreadystatechange=function()
	  {
		  if(http.readyState==4){   //xmlhttp对象读取服务器响应结束
			if(http.status==200)
			{ // 返回后判断时候成功
			}
		   }else{
		   }
	   } 
	}
}

//显示当前日期
function showdate(obj)
{
  var now_date = new Date();
  var years = now_date.getYear();
  var months = now_date.getMonth()+1;
  var dates = now_date.getDate();
  var days = now_date.getDay();
  var m;
  if (months==1){ m="Jan";}
  if (months==2){ m="Feb";}
  if (months==3){ m="Mar";}
  if (months==4){ m="Apr";}
  if (months==5){ m="May";}
  if (months==6){ m="Jun";}
  if (months==7){ m="Jul";}
  if (months==8){ m="Aug";}
  if (months==9){ m="Sep";}
  if (months==10){ m="Oct";}
  if (months==11){ m="Nov";}
  if (months==12){ m="Dec";}
  if(now_date.getDay()==0) days = "Sunday"
  if(now_date.getDay()==1) days = "Monday"
  if(now_date.getDay()==2) days = "Tuesday"
  if(now_date.getDay()==3) days = "Wednesday"
  if(now_date.getDay()==4) days = "Thursday"
  if(now_date.getDay()==5) days = "Friday"
  if(now_date.getDay()==6) days = "Saturday"
  var today =  m + "&nbsp;"+ dates+ "&nbsp;," + years + "&nbsp;"+days +" ";
  obj.innerHTML=today;
 }

//显示当前时间
function showtime(obj)
{
    var now_time = new Date();
	var hours = now_time.getHours();
	var minutes = now_time.getMinutes();
	var seconds = now_time.getSeconds();
	var timer = hours;
	timer  += ((minutes < 10) ? ":0" : ":") + minutes;
	timer  += ((seconds < 10) ? ":0" : ":") + seconds;
    obj.innerHTML=timer;
	setTimeout("showtime()",1000);
}

//限制输入的内容只能为Refstring
function isNumberString (InString,RefString)
{
if(InString.length==0) return (false);
for (Count=0; Count < InString.length; Count++)  {
	TempChar= InString.substring (Count, Count+1);
	if (RefString.indexOf (TempChar, 0)==-1)  
	return (false);
}
return (true);
}

/**去掉前后空格:包括全角空格*/
function trim(str)
{   
    str += "";
    while( (str.charAt(0)==' ')||(str.charAt(0)=='　')||(escape(str.charAt(0))=='%u3000') )     
         str=str.substring(1,str.length);
    while( (str.charAt(str.length-1)==' ')||(str.charAt(str.length-1)=='　')||(escape(str.charAt(str.length-1))=='%u3000') )  
        str=str.substring(0,str.length-1);
    return str;
}

//弹出式窗口
function openWin(URL) 
{
  window.open(URL,'_blank','toolbar=no,menubar=no,location=no,status=no,scrollbars=no,resizable=no,top=200,left=200,width=600,height=500');
}
//选择日期
function SelectDate(obj) 
{ 
var obj = eval(obj); 
result = window.showModalDialog('../inc/date.htm',obj.value,'help:no;status: no;dialogWidth=184px;dialogHeight=220px');
if (result!=null) { obj.value = result; } 
}
//网页对话框
function openDialog(URL)
{
var val=document.addform.myname.value;
window.showModalDialog(URL,val,"dialogWidth=400px;dialogHeight=500px;dialogTop=0;center=yes;help=no;resizable=no;status=yes;scroll=yes");
}
//添加到收藏夹
function addfav(url,name)
{
	window.external.addFavorite(url,name)
}
//把网站设为首页
function sethome(id,url)
{
	id.style.behavior='url(#default#homepage)';id.sethomepage(url);return false;
}

//onMouseOver事件
function over(id)
{
	for(var i=1;i<=6;i++)
	{
		document.getElementById("tb"+i).style.display="none";
		}
		document.getElementById(id).style.display="";
}

var mark; //标记当前显示ID
//显示层
function showCProduct(id)
{
	if($(id).style.display=='none')
	{
		if(mark!="")$(mark).style.display='none';
		$(id).style.display='';	
		mark=id;
	}
	else
	{	
			
		$(id).style.display='none';
	}
}

//显示层
function showLayer(id)
{
	id.style.visibility="visible";	
	}
	
//隐藏层
function hiddenLayer(id)
{	
	id.style.visibility="hidden";	
}

/** 
* 此函数进行Email格式检测. 
* @param str 待检测字符串. 
* @return 是Email格式返回真. 
*/ 
function isEmail(str){ 
	res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/; 
	var re = new RegExp(res); 
	return !(str.match(re) == null); 
} 

function exist(id)
{
	var obj=document.getElementById(id);
	if(obj){return true;}
	else{return false;}
}
