﻿var GouLong = {
vfrm : null,
isEMail:function(text)
{
var regChar = new RegExp("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
return regChar.test(text.trim());
},
isMobilePhone:function(text)
{
var regChar = new RegExp("^(13|15)\\d{9}$");
var regChar1 = new RegExp("^([0-9]{1,5}\-)?([0-9]{1,5}\-)?[0-9]{6,12}(\-[0-9]{1,})?$");
return ( regChar.test(text.trim())  || regChar1.test(text.trim())   );
},
isTelphone:function(text)
{
var regChar = new RegExp("^([0-9]{1,5}\-)?([0-9]{1,5}\-)?[0-9]{6,12}(\-[0-9]{1,})?$");
return regChar.test(text.trim());
},
checkNull:function(objName,msgName)
{
if (document.getElementById(objName).value.trim() == "")
{
alert(msgName + "不可为空！");
return false;
}
return true;
},
checkLen:function(objName,msgName,len)
{
if ( document.getElementById(objName).value.length > parseInt(len)  )
{
alert(msgName + "过长，请不要超出" + len + "个字符！");
return false;
}
return true;
},
checkEMail:function(objName,msgName)
{
if ( ! GouLong.isEMail(document.getElementById(objName).value)  )
{
alert(msgName + "格式错误，请重新输入！");
return false;
}
return true;
},
checkTelphone : function (objName,msgName)
{
if ( ! Hotsales.isTelphone(document.getElementById(objName).value) )
{
alert(msgName + "格式错误，请重新输入！");
return false;
}
return true;
},
checkStringLen: function (objName,msgName,len)
{
var s = document.getElementById(objName).value.trim();
var j= 0;
var hanzi = 0;

for (var i=0; i<s.length; i++)   
{
if (s.charCodeAt(i) > 255)
{
j=j+2;
hanzi++;
}   
else
{
j++;
}
}
if(j > parseInt(len))
{
alert(msgName + "不能超过"+parseInt(len/2)+"个中文字符或"+ len +"英文字符！");
return false;
}
return true;
},
//添加收藏夹
AddFavorite:function(addName)
{
if(navigator.appName.indexOf("Microsoft Internet Explorer")>=0)
{
eval("window.external.addFavorite(document.location.href,'" + addName + "');");
}
else if(navigator.appName.indexOf("Netscape")>=0)
{
eval("window.sidebar.addPanel('" + addName + "',document.location.href,'');");
}
},
//设置为主页
SetHomePage:function(url)
{
try
{
if(window.netscape)
{
try 
{  
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
}  
catch (e) 
{
alert("error");
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage',url);
}
else
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(url);
}
}
catch(e){}
},
//自己实现回调
CallbackMethod:function(paramList)
{
var result = new Object(); 
var xmlhttp = null;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();                
}else if(window.ActiveXObject){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
result.status = -1;
result.errmsg = "浏览器不支持 XMLHttpRequest.";
result.value = "";
return result;
}

var params = paramList;
if (params == undefined || params == null)
params = "";
var url = document.location.href;
var ipos = url.indexOf("?");
if (ipos > 0)
url = url.substring(0, ipos);
url = url + "?callback=1";
xmlhttp.open("POST", url, false);
xmlhttp.setRequestHeader("Content-Length", params.length);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(params);
if (xmlhttp.status != 200 && xmlhttp.status != 0)
{
result.status = -2;
result.errmsg = xmlhttp.statusText;
result.value = "";
}
else
{
result.status = xmlhttp.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue;
result.errmsg = xmlhttp.responseXML.getElementsByTagName("errmsg")[0].firstChild.nodeValue;
result.errmsg = unescape(result.errmsg);
result.value = xmlhttp.responseXML.getElementsByTagName("value")[0].firstChild.nodeValue;
result.value = unescape(result.value);
}
return result;
}
};


/*去空格 */
String.prototype.trim = function()
{
return this.replace(/(^\s*)|\s*$/g,"");
}

/*按字节计算字符串长度，注：一个汉字两个字节，一个英文一个字节*/
String.prototype.BitLength=function(){return this.replace(/[^\x00-\xff]/g,"**").length;}

/*根据ID获取对象  */
function $id(objId)
{
return 	document.getElementById(objId);
}

var global_doc = document;
function getViewportHeight() {
if (window.innerHeight!=window.undefined) return window.innerHeight;
if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
if (document.body) return document.body.clientHeight; 
return window.undefined; 
}
function getViewportWidth() {
if (window.innerWidth!=window.undefined) return window.innerWidth; 
if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
if (document.body) return document.body.clientWidth; 
return window.undefined; 
}

function setDivCenter() {
var width, height;
if(!isNaN(parseInt($id("procomm").style.width)))
width = parseInt($id("procomm").style.width);
else
width =$id("procomm").offsetWidth;
//height = parseInt(gid("tgpopup").offsetHeight);
height = 230;
var fullHeight = getViewportHeight();
var fullWidth = getViewportWidth();
var scLeft,scTop;
if (self.pageYOffset) {
scLeft = self.pageXOffset;
scTop = self.pageYOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {
scLeft = document.documentElement.scrollLeft;
scTop = document.documentElement.scrollTop;
} else if (document.body) {
scLeft = document.body.scrollLeft;
scTop = document.body.scrollTop;
}
var topMargin = scTop + ((fullHeight - height) / 2);
if (topMargin < 0) { topMargin = 0; }
$id("procomm").style.top = topMargin + "px";
$id("procomm").style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
}

function ShowGroupBuying2(Id,str)
{
$id("Text_PingFlag").value=Id+','+str;
if(str=="1")
{
$id("strong_disply").innerHTML="您顶了一下，发表一点自己的看法";
}
else
{
$id("strong_disply").innerHTML="您踩了一脚，发表一点自己的看法";
}
$id("procomm").style.display = "";
}
function HideGroupBuying(){
$id("procomm").style.display = "none";
$id("Textarea_Content2").value="";
$id("Text_CheckCode2").value="";
//$id("img1").src="/checkcode.aspx??";
}
function ShowGroupBuying(str)
{
$id("Textarea_Content2").value="";
$id("Text_CheckCode2").value="";
//$id("img1").src="/checkcode.aspx?";
if(str=="1")
{
$id("strong_disply").innerHTML="您顶了一下，发表一点自己的看法";
}
else
{
$id("strong_disply").innerHTML="您踩了一脚，发表一点自己的看法";
}
$id("procomm").style.display = "";
}
//关键字搜索
function SearchTop()
{
if($id("Topsearch").value.trim() =="" )
{
alert("搜索关键字不能为空！");
$id("Topsearch").focus();
return;
}
if($id("Topsearch").value.trim().BitLength() <= 2 )
{
alert("搜索关键字不能少于2个字符！");
$id("Topsearch").focus();
return ;
}
var s=$id("Topsearch").value.trim().replace(/\s+/g," ");
window.location.href='http://search.goulong.com/'+s+'/';
}
function SearchFoot()
{
if($id("footSearch").value.trim() =="" )
{
alert("搜索关键字不能为空！");
$id("footSearch").focus();
return false;
}
if($id("footSearch").value.trim().BitLength() <= 2 )
{
alert("搜索关键字不能少于2个字符！");
$id("footSearch").focus();
return false;
}
var s=$id("footSearch").value.trim().replace(/\s+/g," ");
window.location.href='http://search.goulong.com/'+s+'/';
return true;
}
function moveCompare(strUrl)
{
if(!confirm("您确认要移除该商品吗？"))
return;
window.location.href='http://product.goulong.com'+strUrl;
}
function killErrors() {
return true;
}
window.onerror = killErrors;