﻿//By xingcai zhang

var xmlHttp;
var codeUrl="/Include/ValidateCode.aspx?";//window.location.href;
//init;
function createXMLHttpRequest()
{
	if(window.ActiveXObject)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else 
	{
		xmlHttp=new XMLHttpRequest();
	}
}
//验证验证码是否正确
function ValidateCode(source,arguments)
{
	var flag = false;
	var code=arguments.Value;
	var postParam="ckvcode="+code;
	createXMLHttpRequest();	
	xmlHttp.open("POST",codeUrl,false);
	xmlHttp.onreadystatechange=function()
	{	
	    if(xmlHttp.readyState==4)
	    {	
		    if(xmlHttp.status==200)
		    {	
			    var result=xmlHttp.responseText;
			    if(result=='true'){flag=true;}
		    }
	    }
	};
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");	
	xmlHttp.send(postParam);
	arguments.IsValid=flag;
}
function $(obj)
{
	return typeof(obj)=="string"?document.getElementById(obj):obj;
}
//获得新的验证码
function getNewCode(o)
{
	var obj=$(o);
	obj.src="/Include/ValidateCode.aspx?"+Math.random();
	
}
function disableBtn(obj)
{
	obj.disabled='disabled';
	
}
function goUrl(url)
{
	window.location.href=url;
	
}
//替换Url QueryString
function RegularUrl(url,key,value)

{
	var fragPos=url.lastIndexOf("#");
	var fragment="";	
	if(fragPos>-1)
	{
		fragment=url.substring(fragPos);
		url=url.substring(0,fragPos);
		
	}
	var querystart=url.indexOf("?");	
	if(querystart<0)
	{
		url+="?"+key+"="+value;
		
	}
	else if(querystart==url.length-1)
	{
		url+=key+"="+value;
		
	}
	else 
	{
		var Re=new RegExp(key+"=[^\\s&#]*","gi");		
		if(Re.test(url))url=url.replace(Re,key+"="+value);		
		else url+="&"+key+"="+value;
		
	}
	return url+fragment;
	
}
//防止按钮重复提交
function onceSubmit(obj)
{
	if(typeof(Page_ClientValidate)=='function')
	{
		if(Page_ClientValidate()==false)
		{
			return false;
		}
	}obj.disabled='disabled';
}

//验证码验证
function ValidateCode1(code)
{
	var flag = false;
	var postParam="ckvcode="+code;
	createXMLHttpRequest();	
	xmlHttp.onreadystatechange=function()
	{
	    if(xmlHttp.readyState==4)
	    {
		    if(xmlHttp.status==200)
		    {
			    var result=xmlHttp.responseText;
			    if(result=='true'){flag=true;}
		    }
	    }
	};
	xmlHttp.open("POST",codeUrl,false);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");	
	xmlHttp.send(postParam);
	return flag;
}

//编码字符串
function encodeUrl(str)
{
    return escape(str);
}
//获得TreeView选择的值，并以;隔开
function getTreeViewValue(obj)
{
    var checkValue="";
	var TreeView=obj;//"";
	var checkNode=document.getElementById("CheckedNode");
	var checkboxs=document.getElementById(TreeView).getElementsByTagName("input");
	for(i=0;i<checkboxs.length;i++)
	{
		if(checkboxs[i].type=="checkbox"
		&&checkboxs[i].name.substr(0,TreeView.length)==TreeView
		&&checkboxs[i].checked)
		{
			checkValue+=checkboxs[i].title+";";
		}
	}
	return checkValue;
}

//弹出选择框
function showWindow(url,width,height)
{	
    return window.showModalDialog(url,"newform",
    "dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;scroll:no");
}

//javascript utils
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g,"");
}
var Utils = new Object();
Utils.addEventHandler = function (oTarget, sEventType, fnHandler) {
     if (oTarget.addEventListener) {
         oTarget.addEventListener(sEventType, fnHandler, false);
     }
     else if (oTarget.attachEvent) {
         oTarget.attachEvent("on" + sEventType, fnHandler);
     }
     else {
         oTarget["on" + sEventType] = fnHandler;
     }
};   
Utils.removeEventHandler = function (oTarget, sEventType, fnHandler) {
     if (oTarget.removeEventListener) {
         oTarget.removeEventListener(sEventType, fnHandler, false);
     } else if (oTarget.detachEvent) {
         oTarget.detachEvent("on" + sEventType, fnHandler);
     } else {
         oTarget["on" + sEventType] = null;
     }
};
Utils.delegate=function(caller, fnc)
{
    var delegate = function()
    {
        fnc.apply(caller, arguments);
    }
    return delegate;
};
Utils.$=function(s)
{
    var obj;
    if(typeof(s)=="string")
    {
        obj= document.getElementById(s);
    }
    else
    {
        obj=s; 
    }
    return obj;
};
 Utils.GetElemWidth=function(elem)
 {
  var xPos = elem.style.pixelWidth|elem.offsetWidth;
  return xPos;
 }
 Utils.GetElemHeight=function(elem)
 {
  var yPos = elem.style.pixelHeight|elem.offsetHeight;
  return yPos;
 }
  Utils.changeOpac=function(objT,opacity) {
    var obj=objT.style; 
    obj.opacity = (opacity / 100);
    obj.MozOpacity = (opacity / 100);
    obj.KhtmlOpacity = (opacity / 100);
    obj.filter = "alpha(opacity=" + opacity + ")";
}

//----------------Js获取URL参数值 开始--------------- 
function Request(paras){
var url = location.href;
var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
var paraObj = {}
for (i=0; j=paraString[i]; i++){
paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
}
var returnValue = paraObj[paras.toLowerCase()];
if(typeof(returnValue)=="undefined"){
return "";
}else{
return returnValue;
}
} 
//----------------Js获取URL参数值 结束--------------- 
//QQ
function OpenQQ(n){
    if(IsInstallQQ()==true){ 
        location.href='Tencent://Message/?menu=yes&exe=&uin=' + n + '&websiteName=九网信息电子商务&info=预订交流';
    }
}
function IsInstallQQ(){
    try{
        var xmlhttp=new ActiveXObject("TimwpDll.TimwpCheck");
        return true;
    }catch(e){
        return false;
    }
    return false;
}