function $(id)
{
  return document.getElementById(id);	
}
function $n(name)
{
  return document.getElementsByName(name);	
}
function Alert(s)
{
  alert(s);	
}
function login(o)
{
  if(o.email.value.replace(/^\s*/,'') == '')
  {
	 Alert("邮箱不能为空");
	 o.email.focus();
	 return false;
   }
   if(o.pwd.value.replace(/^\s*/,'') == '')
   {
	 Alert("密码不能为空");
	 o.pwd.focus();
	 return false;
   }
   return true;
}

function createXMLHttpRequest()
{
	var xmlHttp;

	if (window.XMLHttpRequest){

				var objXMLHttp = new XMLHttpRequest();

			}else{

				var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];

				for(var n=0; n<MSXML.length; n++){

					try{

						var objXMLHttp = new ActiveXObject(MSXML[n]);

						break;

					}catch(e){}

				}

			}
	return objXMLHttp;
}

function getcity(o)
{	
	v = o.value;
	ajax = createXMLHttpRequest();
	ajax.open("GET","/linc/city.php?coid=" + v,true);
	ajax.onreadystatechange = lcity;
	ajax.setRequestHeader("If-Modified-Since","0");
	ajax.send(null);
}

function lcity()
{
	if(ajax.readyState==4)
	{
		if(ajax.status==200)
		{  
			if(ajax.responseText.replace(/^s*/,'') !='')
			 $('cityd').innerHTML = ajax.responseText;
		}
	}	
}

function fullcheck(o,n)
{
  var na = $n(n);
  for(var i=0;i<na.length;i++)
  {
	na[i].checked = o.checked;  
  }
}

function getcheckvalue(o)
{
  var na = $n(o);
  var id ='';
  for(var i=0;i<na.length;i++)
  {
	if(na[i].checked == true)
	id += (id=="")?na[i].value:"," + na[i].value;
  }
  return id;
}
function chaddress(pid,id)
{   
	var rid = -1;
	var rs = $(id);
	var j =0;
	rs.length =0 ;
	try{
	eval('var arr = address' + pid);
	}
	catch(e){return -1;}
	//rs.options[0] = new Option('==请选择==','');
	for(var i=0;i<arr.length;i++)
	{   if(i==0) rid = arr[i][1];
		rs.options[i] = new Option(arr[i][2],arr[i][1]);
	}
	return rid;
}

function chadrs(pid,il)
{
 var ia = il.split(',');
 for(var i=0;i<ia.length;i++)
 {
  pid =	chaddress(pid,ia[i]);
 }
}

function chdiv(o,n,f,id)
{
	for(i=0;i<n;i++)
	{
	  if($(f + i))
	  {
	   $(f + i).className ='city_l2 l';
	   $(f + i + '_div').style.display ='none';
	   if(i==0)
	   {   
		   $(f + i).className = 'city_l1 l';
	   }
	  }
	}
	if(o.id.replace(f,'') == '0')
	  o.className ='city_l1_f l';
	else
	o.className ='city_l2_f l';
	$(o.id +'_div').style.display ='block';
	$('avcity_a').href='/arc/list.php?id='+id;
}
function chdiv_c(o,n,f,id,w)
{
	for(i=0;i<n;i++)
	{
	  if($(f + i))
	  {
	   $(f + i).className ='country2_2_2_1_11';
	   $(f + i + '_div').style.display ='none';
	  }
	}
	o.className ='country2_2_2_1_1';
	$(o.id +'_div').style.display ='block';
	if(w=='co')
	$(f+'_a').href='/arc/countrylist.php?id='+id;
	else
	$(f+'_a').href='/arc/list.php?id='+id;
}
function w_flv(url,w,h)
{
 document.write('<object type="application/x-shockwave-flash" width="'+w+'" height="'+h+'" wmode="transparent" data="/image/flvplayer.swf?file='+url+'&image=/image/p1.jpg&autostart=false"> <param name="movie" value="/image/flvplayer.swf?file='+url+'&image=/image/p1.jpg&autostart=false" /> <param name="wmode" value="transparent" /> </object>');		
}
function w_flash(str,w,h)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'"> <param name="movie" value="'+str+'"><param name="quality" value="high">  <param name="wmode" value="transparent">          <embed src="'+str+'" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"  type="application/x-shockwave-flash" width="'+w+'" height="'+h+'" ></embed></object>');
	
}

function copy_clip($v)
{ var meintext = $v;
 if (window.clipboardData) 
   {
   window.clipboardData.setData("Text", meintext);
   }
   else if (window.netscape) 
   { 
   
    try { 
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
	} 
	catch (e) 
	{ 
		alert("你的复制功能被浏览器拒绝！\n请在浏览器地址栏输入’about:config’并回车\n然后将’signed.applets.codebase_principal_support’设置为’true’"); 
	} 
   
   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   trans.addDataFlavor('text/unicode');
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=meintext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   Alert("地址复制已到粘贴板!");
}

function addfriend(id)
{   
	if(typeof(id) == 'undefined'){id=uid;}
	ajax = createXMLHttpRequest();
	ajax.open("GET","/linc/friend.php?work=add&fid=" + id,true);
	ajax.onreadystatechange = friendstatus;
	ajax.setRequestHeader("If-Modified-Since","0");
	ajax.send(null);
}
function delfriend(id)
{   var is = false;
	if(typeof(id) == 'undefined'){id=uid;is = true;}
    ajax = createXMLHttpRequest();
	ajax.open("GET","/linc/friend.php?work=del&fid=" + id,true);
	if(!is)
	ajax.onreadystatechange = friendstatusag;
	else
	ajax.onreadystatechange = friendstatus;
	ajax.setRequestHeader("If-Modified-Since","0");
	ajax.send(null);
}
function agfriend(id)
{
    ajax = createXMLHttpRequest();
	ajax.open("GET","/linc/friend.php?work=ag&fid=" + id,true);
	ajax.onreadystatechange = friendstatusag;
	ajax.setRequestHeader("If-Modified-Since","0");
	ajax.send(null);
}
function tomessage()
{
  var str = '<table width="100%" border="0" cellspacing="3" cellpadding="0" style="margin-top:5px;"> <tr> <td align="center"><textarea name="tom_text"  id="tom_text" class="creatediv_input" style="width:250px;height:150px;"  ></textarea></td></tr><tr><td align="center"><input type="button" value="发 送" id="tombutton" onclick="tom_go()" class="creatediv_input" style="height:20px;line-height:20px;"/> &nbsp;&nbsp;<input type="button" value="取 消" class="creatediv_input" style="height:20px;line-height:20px;" onclick="$(\'tomessage\').style.display=\'none\';"/></td></tr></table>';
  if(!$('tomessage')) creatediv('tomessage',300,200,str);
  var x = document.documentElement.scrollLeft + 350;
  var y = document.documentElement.scrollTop + 250;
  $('tomessage').style.top = y +'px'; 
  $('tomessage').style.left = x + 'px'; 
  $('tomessage').style.display = 'block'; 
  
}
function tom_go()
{
	var c = $('tom_text');
    if(c.value == '')
	{
	   Alert('发送的内容不能为空');
	   return;
	}
	if(c.value.length > 200)
	{
		Alert('信息内容在200个字符内');
	   return;
		}
	$('tombutton').disabled =true;
	$('tomessage').style.display = 'none'; 
	ajax = createXMLHttpRequest();
	ajax.open("GET","/linc/message.php?work=to&fid=" + uid +'&c='+ encodeURI(c.value),true);
	ajax.onreadystatechange = friendstatus;
	ajax.setRequestHeader("If-Modified-Since","0");
	ajax.send(null);
	
}
function friendstatus()
{
	if(ajax.readyState==4)
	{
		if(ajax.status==200)
		{  
			 Alert(ajax.responseText);
			 if($('tombutton'))
			 {
			  if($('tombutton').disabled ==true) $('tombutton').disabled =false;	 
			 }
		}
	}	
}
function friendstatusag()
{
	if(ajax.readyState==4)
	{
		if(ajax.status==200)
		{  
		    self.location.reload();
		}
	}	
}
function creatediv(id,w,h,c)
{
	var div = document.createElement('div'); 
	div.id = id;
	div.style.width = w +'px';
	div.style.height = h  +'px';
	div.style.display = 'none';  
	div.className = 'creatediv'; 
	document.body.appendChild(div); 
	div.innerHTML = c;
}
function colla(id,t)
{
	ajax = createXMLHttpRequest();
	ajax.open("GET","/arc/ajaxcoll.php?work="+t+"&id=" + id,true);
	ajax.onreadystatechange = friendstatus;
	ajax.setRequestHeader("If-Modified-Since","0");
	ajax.send(null);
}
function addcar(id)
{
    ajax = createXMLHttpRequest();
	ajax.open("GET","/shop/addcart.php?id=" + id,true);
	ajax.onreadystatechange = friendstatus;
	ajax.setRequestHeader("If-Modified-Since","0");
	ajax.send(null);
}
function SetHome(obj,vrl){
         try{
                 obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
         }
         catch(e){
                 if(window.netscape) {
                         try {
                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                         }
                         catch (e) {
                                 alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
                         }
                         var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                         prefs.setCharPref('browser.startup.homepage',vrl);
                  }
         }
 }
 
