﻿// set the ie or firefox flag
var ieFlag = (navigator.appVersion.indexOf("MSIE")!=-1);
var ffFlag = (navigator.userAgent.indexOf("Firefox")!=-1);
var speed = 1000; //速度
var wait = 10; //停留时间
var wait = 5; //停留时间

	function fGetXY(aTag){
	
	  var oTmp = aTag;
	
	  var pt = new Point(0,0);
	
	  do {
		pt.x += oTmp.offsetLeft;
		pt.y += oTmp.offsetTop;
		
		oTmp = oTmp.offsetParent;
		
	  } while(oTmp.tagName!="BODY");
	  
	  
	  return pt;
	}
	function Point(iX, iY){
		this.x = iX;
		this.y = iY;
	}
	
	function chFont(el){
        try{
            var e = el.options[el.selectedIndex];
            $('fontImg').src = "../Material/Font/" + e.value + ".jpg";    
        }   catch(e){}
    }
	function chFont2(el){
        try{
            var e = el.options[el.selectedIndex];
            $('fontImg2').src = "../Material/Font/" + e.value + ".jpg";    
        }   catch(e){}
    }
    	function chFont3(el){
        try{
            var e = el.options[el.selectedIndex];
            $('fontImg3').src = "../Material/Font/" + e.value + ".jpg";    
        }   catch(e){}
    }
    function setcustomsize(el){
        try{
            var e = el.options[el.selectedIndex];
            $('txtWidth').value = e.value.split('*')[0];
            $('txtHeight').value = e.value.split('*')[1];
     
        }   catch(e){}
    }
    
    function searchMenu(iCur,objId){

	var   menu=$(objId);   
	var   menuN=menu.getElementsByTagName("li");
	
	for (i=0; i<menuN.length; i++)
	{
		menuN[i].className=objId + 'off';
	}
	menuN[iCur].className=objId + 'on';
	
	for(i=0;i<menuN.length;i++) 
	{
		if(i == iCur){$(objId + "_so"+i).style.display = "block";}
		else{$(objId + "_so"+i).style.display = "none";}
	}
	//$("sType").value = objId;
    }
	
	// Save the image to Local disk
	function SaveImage(img)
	{
		var win = document.getElementById('genFrm').contentWindow;
		if (!win || img.tagName != 'IMG') return;
		win.location.href = img.src;
		setTimeout(function() { win.document.execCommand("SaveAs"); }, 200);
	}
	
	// 复制图片到剪贴版
	function CopyImage(img)
	{
	  if (img.tagName != 'IMG') return;
	  if (typeof img.contentEditable == 'undefined' || !document.body.createControlRange)
	  {
		alert('抱歉，浏览器不支持直接复制图片！\n请将鼠标移到图片上方，单击鼠标右键在弹出菜单中选择“复制”');
	  }
	  else
	  {
		var ctrl = document.body.createControlRange();
		img.contentEditable = true;
		ctrl.addElement(img);
		ctrl.execCommand('Copy');
		img.contentEditable = false;
		alert('复制完成，到QQ对话框里按Ctrl-V就可以啦！\n\n若不能粘贴请重复尝试或用鼠标右键选复制');
	  }
	}
	
	function copy(inElement) {
      if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range && range.execCommand)
          range.execCommand('Copy');
      } 
      else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
          var divholder = document.createElement('div');
          divholder.id = flashcopier;
          document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="../js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//flash 鍦板潃
        document.getElementById(flashcopier).innerHTML = divinfo;
      }
      alert('已成功复制到剪切板，按 Ctrl-V 即可粘贴送出！');
    }

	function BbsImage(inElement,mImg) {
	  inElement.value = '[img]' + mImg.src + '[/img]';
      if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range && range.execCommand)
          range.execCommand('Copy');
      } 
      else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
          var divholder = document.createElement('div');
          divholder.id = flashcopier;
          document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="../js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//flash 鍦板潃
        document.getElementById(flashcopier).innerHTML = divinfo;
      }
      alert('已成功复制到剪切板，按 Ctrl-V 即可粘贴送出！');
    }
	
	function WebImage(inElement,mImg) {
	  inElement.value = '<img src=' + mImg.src + ' border=0>';
      if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range && range.execCommand)
          range.execCommand('Copy');
      } 
      else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
          var divholder = document.createElement('div');
          divholder.id = flashcopier;
          document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="../js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//flash 鍦板潃
        document.getElementById(flashcopier).innerHTML = divinfo;
      }
      alert('已成功复制到剪切板，按 Ctrl-V 即可粘贴送出！');
    }	
       
		function copy_url(msgtitle) 
		{ 
		  var __furl = window.location.href;
		  var msg = '你好！我推荐给你一个在线生成' + msgtitle + '的例子，网址是：' + __furl;
		  window.clipboardData.setData("text", msg);
		  alert("已成功复制到剪切板，按 Ctrl-V 即可粘贴送出！"); 
		}
		
  function addfav()
  {
	  window.external.AddFavorite(window.location, document.title)
  }

	
	// 发送到手机
	function MmsImage(img)
	{
	  // mmslink
	  var url = img.src;
	  var pos = url.indexOf('?');
	  if (pos > 0) url = url.substring(0, pos);
	  //window.open('http://tlt.7town.com/ZComImgDIY/step2.asp?imageUrl=' + encodeURIComponent(url) + '&uid=20398&a=&b=&c=&d=&e=&f=', '_blank');
	 // window.open('http://www.zhangxiu.com/mms/diy.html?IsLogo=&imgurl=' + encodeURIComponent(url) + '&f=13746','_blank');
	}
		
	function checkForm(form, check_string)
	{
		with(form)
		{
			for(var j = 0; j < check_string.split("|").length;j++)
			{
				for(var i=0;i<elements.length;i++)
				{
					
					if(check_string.split("|")[j].split("@")[0] == elements[i].name)
					{
						if (check_string.split("|")[j].split("@")[1] == "null" && elements[i].value == "")
						{
							alert("必填项目不能为空！");
							elements[i].focus();
							return false;
						}
						else if (check_string.split("|")[j].split("@")[1] == "int" && !IsNum(elements[i].value))
						{
							alert("数据格式不正确，应为整型！");
							elements[i].focus();
							return false;
						}
					}
				}
					

			}
			return true;
		}
	}
		

	//判断是否正确EMAIL
	function IsEmail(val)
	{
		var mail=/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i; 
		if(!mail.test(val)){ 
			return (false);
		} else	{
			return (true);
		}
	}
	
	//匹配网址,包括 xxx://
	//未完成
	function IsURL(val)
	{
		var reg = /[a-zA-z]+[://][^\s]*/;
		if(!reg.test(val)){ 
			return (false);
		} else	{
			return (true);
		}
	}
	
	//匹配url转向网址
	function IsRefererURL(val)
	{
		var reg = /^(http|ftp|mailto|news|mms|rtsp)\:\/\/[0-9a-zA-Z]*([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,5}?/
		
		if(reg.test(val)){ 
			return (true);
		} else	{
			return (false);
		}
	}
	
	//匹配url转向IP
	function IsRefererIP(val)
	{
		var pos2=0;
		var pos = val.indexOf('://');		
		if(pos<=0)return false;
		
		pos2=val.indexOf('/',pos+3);		
		if(pos2>0)
		{
			val = val.substr(0,pos2);
		}
		
		var portPos=val.indexOf(':',pos+3);
		if(portPos>0)
		{
			var port=val.substr(portPos+1);			
			if(!IsNum(port)) return false;
			val = val.substr(0,portPos);
		}		
		var reg = /^(http|https|ftp|mailto|news|mms|rtsp)\:\/\/([01]?\d{1,2}|2[0-4]\d|25[0-5])(\.([01]?\d{1,2}|2[0-4]\d|25[0-5])){3}$/;		
		
		if(reg.test(val)){ 
			return (true);
		} else	{
			return (false);
		}
	}
	
	
	
	//判断是否数字
	function IsNum(val)
	{
	  if (val == '') return (false);
	  var intStr=/^\d+$/; 
	  if(!intStr.test(val))
		  return (false);
	  else
	  {
			return (true);
	  }
	}
	
	//判断是否数字（含浮点）
	function IsFloat(val)
	{
	  if (val == '') return (false);
	  if (val.substring(0,1)=='.') return (false);
	  if (val.substring(val.length-1,val.length)=='.') return (false);

	  var intStr=/[^0-9.]/g; 
	  if(!intStr.test(val))
		  return (true);
	  else
	  {
		  return (false);
	  }
	}
	
	//是否IP地址
	//还不能正确判断第一个为0
	function IsIP(str)
	{
		var re = /^([01]?\d{1,2}|2[0-4]\d|25[0-5])(\.([01]?\d{1,2}|2[0-4]\d|25[0-5])){3}$/;
		
		if(re.test(str))
			return true;
		else
			return false;
	}

/*以下二个函数用于上传图片时的预览
要点：
文件控件：<input name="XXXX" type="file" onchange="javascript:FileChange(uploadimage,this.value);">

新图预览：<IMG id="uploadimage"  onload="javascript:DrawImage(this ,www ,hhh);" width="1" height="1" border="0" onerror="this.src='../../web_up_file/nopic.jpg'">

旧图预览：<IMG id="uploadimage" src=".........." onload="javascript:DrawImage(this ,www ,hhh);" border="0" onerror="this.src='../../web_up_file/nopic.jpg'">
*/
function FileChange(imgObj,Value){
flag=false;
//imgObj.width=10;
//imgObj.height=10;
imgObj.alt="";
imgObj.src=Value;

}

/*按比例缩小图片,当图片高和宽为0时不处理 -- fire 20061001
传入参数: 
ImgD :图片URL ;
iHH  :高度,可为空
iWW  :宽度,可为空
*/
var flag=false;
function DrawImage(ImgD ,iWW ,iHH){

	if (iHH==""){
		iHH=245;
	}
	if (iWW==""){
		iWW=300
	}
	
	var image=new Image();
	image.src=ImgD.src;
	//当高和宽大于0时处理

	if(image.width>0 && image.height>0){
    	flag=true;
		
		if(image.width/image.height>= iWW/iHH){
		    if(image.width>iWW){  
			    ImgD.width=iWW;
			    ImgD.height=(image.height*iWW)/image.width;
			}else{
			     ImgD.width=image.width;  
			     ImgD.height=image.height;
		    }
	    }
    	else{
    		if(image.height>iHH){  
		    	ImgD.height=iHH;
				ImgD.width=(image.width*iHH)/image.height;     
			}else{
			    ImgD.width=image.width;  
		    	ImgD.height=image.height;
		    }
    	}
    }
   /*else{
    ImgD.src="";
    ImgD.alt=""
    }*/
     ImgD.alt="51gif.net";
} 	

function tagSearch(mfile,value)
{
	window.location.href=mfile+"/Search.aspx?t="+encodeURIComponent(value);	
}

function ding(mfile,gd)
{
    var ashxfile= "../ashx/Ding.ashx";
    var param_url = "class=" + mfile + "&gd=" + gd + "&id=" + $("Id").value;
   	new Ajax.Request(
                ashxfile,
                {
                        method: 'post',
                        postBody: param_url,
                        onComplete: function(response){
                            if (response.responseText != "-1")
                                $("ico1").innerText = response.responseText;
                        }
                }
        );     
}

function IndexList(mfile)
{
	var ashxfile= "ashx/" + mfile +"/IndexList.ashx";
    var param_url = ""; 
	$("more" + mfile).innerHTML = "<img src='images/spinner_gray.gif' alt='读取中..' align='absmiddle'/>数据读取，请稍候...";
   	new Ajax.Request(
                ashxfile,
                {
					method: 'post',
					postBody: param_url,
					onComplete: function(response){
						
						if (response.responseText != "-1")
						{
							$("index" + mfile).innerHTML = response.responseText;
							$("more" + mfile).innerHTML ="<a href=\"javascript:IndexList('" + mfile +"')\">[切换下一屏]</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='" + mfile + "/index.htm' target='_blank'>更多>>></a>";
						}
					}
                }
        );   
}

function EliteList(mfile)
{
	var ashxfile= "../ashx/" + mfile +"/EliteList.ashx";
    var param_url = ""; 
	$("next" + mfile).innerHTML = "<img src='../images/spinner_gray.gif' alt='读取中..' align='absmiddle'/>读取中...";
   	new Ajax.Request(
                ashxfile,
                {
					method: 'post',
					postBody: param_url,
					onComplete: function(response){
						
						if (response.responseText != "-1")
						{
							$("elite").innerHTML = response.responseText;
							$("next" + mfile).innerHTML ="<a href=\"javascript:EliteList('" + mfile +"')\">[切换下一屏]</a>";
						}
					}
                }
        );   
}

function EliteList2(id,ipage)
{
	var ashxfile= "../ashx/Make/EliteList.ashx";
    var param_url = "id=" + id + "&iPage=" + ipage; 
	$("navage").innerHTML = "<img src='../images/spinner_gray.gif' alt='读取中..' align='absmiddle'/>读取中...";
   	new Ajax.Request(
                ashxfile,
                {
                        method: 'post',
                        postBody: param_url,
                        onComplete: function(response){
                            
                            if (response.responseText != "-1")
                            {
                                $("elite").innerHTML = response.responseText;
								$("navage").innerHTML ="[<a href='javascript:prevpage()'>上一页</a>] [<a href='javascript:nextpage()'>下一页</a>]";
                            }
                        }
                }
        );   
}

function PostPL(mfile)
{
    var ashxfile= "../ashx/Comment.ashx";
    var param_url =  Form.serialize('frmpl') + "&Id=" + $("Id").value + "&class=" + mfile;
    if ($('frmpl')!=null) Form.disable('frmpl');
 	
   	new Ajax.Request(
                ashxfile,
                {
                        method: 'post',
                        postBody: param_url,
                        onComplete: function(response){
						 Form.enable('frmpl');
						 if (response.responseText != "0")
								$('plinfo').innerHTML = response.responseText;
						else		
                             {   alert("感谢您对本站的支持，请等待管理员审核！");
								$("txtcomment").value="";
								$('plinfo').style.display='none';
							 }
                        }
                }
        );     
}

function PList(mfile,id)
{
    var ashxfile= "../ashx/CommentList.ashx";
    var param_url = "class=" + mfile + "&Id=" + id ;
   	new Ajax.Request(
                ashxfile,
                {
                        method: 'post',
                        postBody: param_url,
                        onComplete: function(response){
                            
                            if (response.responseText != "-1")
                                $("plist").innerHTML = response.responseText;
                        }
                }
        );     
}

function PageInit(mfile,qId)
{
	var MDelayTime=600;
	ding(mfile,'');
	window.setTimeout("PList('"+mfile+"','" + qId +"');",MDelayTime);
	window.setTimeout("EliteList('"+mfile+"');",MDelayTime);
	window.setTimeout("$('vcodediv').innerHTML='<img src=\"../WebResources/ValidImage.ashx\" align=\"absmiddle\" />';",MDelayTime);
}

function PageInit2(qId)
{
	var MDelayTime=600;
	ding('Make','');
	window.setTimeout("PList('Make','" + qId +"');",MDelayTime);
	if (qId !="010"&& qId !="011"&& qId !="012")
	{
		if (qId =="002" || qId =="006" || qId =="009")
			window.setTimeout("EliteList('QFace');",MDelayTime);	
		else
			window.setTimeout("EliteList2('"+qId+"',1);",MDelayTime);
	}
	window.setTimeout("$('vcodediv').innerHTML='<img src=\"../WebResources/ValidImage.ashx\" align=\"absmiddle\" />';",MDelayTime);	
}

function updateinfo(){
if(wait == 0){
    $('BtnReset').disabled = false;
	$('BtnReset').value = "重设表单";
}
else{
    wait--;
	$('BtnReset').value = "请稍候" + wait;
    window.setTimeout("updateinfo()",speed);
}
}

function updateinfo2(){
if(wait2 == 0){
    $('BtnUndo').disabled = false;
	$('BtnUndo').value = "回上一步";
}
else{
    wait2--;
	$('BtnUndo').value = "请稍候" + wait2;
    window.setTimeout("updateinfo2()",speed);
}
}