﻿function $$(o)
{
	return document.getElementById(o);
}


function ck(o)
{
	switch(typeof(o))
	{
		case "undefind":
			return false;
		break;
		case "object":
			if(null===o)
			{
				return false;
			}
			else
			{
				return true;
			}
		break;
		case "string":
			if(o.length==0)
			{
				return false;
			}
			else
			{
				return true;	
			}
		break;
		case "number":
			if(0===o)
			{
				return false;
			}
			else
			{
				return true;
			}
		break;	
		case "boolean":
			return o;
		break;
		case "function":
			return true;
		break;
		default:
			return false;
		break;
	}
}

function is_email(str)
{
	var regexp = /[\w\d\.]+@[\w\d]+(\.[\w\d]+)+/g;
	var result = str.match(regexp);
	return result != null && result.join("").length == str.length ? true : false;
}




function check_username()
{
	var username = $$('username');
	if(!ck(username.value))
	{
		$$('username_msg').innerHTML = "Username unavailable";
		return false;
	}
	else
	{
		$$('username_msg').innerHTML = "";
	}
	var url = "check_username.php?username="+username.value+"";	
	$.getScript(url,function()
	{
		$$('username_msg').style.display = "block";
		if(!ck(err_str))
		{
			
			$$('username_msg').innerHTML = "<font color='#00ff00'>"+content+"</font>";
		}
		else
		{
			$$('username_msg').innerHTML = ""+err_str+"";
		}		
	});
	
}

<!--  
function ShowSize(source)  
{  
  var fso,f;  
  fso=new ActiveXObject("Scripting.FileSystemObject");  
  f=fso.GetFile(source); 
  if(f.size>40*1024)
  {
	  alert(f.size+" Mega byte"); 
  }
  	  alert(f.size+" Mega byte"); 
//file format check	  
 var pos = str.lastIndexOf(".");
 var lastname = str.substring(pos,str.length)  //此处文件后缀名也可用数组方式获得str.split(".") 
 if (lastname.toLowerCase()!=".jpg" && lastname.toLowerCase()!=".gif")
 {
     alert("您上传的文件类型为"+lastname+"，图片必须为.jpg,.gif类型");
     document.myform.pic.focus();
     return false;
 }
 else 
 {
  return true;
 }
	  
	  

}  
//--> 

function my_copy(text2copy)
{ 
      if (window.clipboardData)
      {   
        window.clipboardData.setData("Text",text2copy); 
        alert('复制成功');  
      }
      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="_clipboard.swf" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
 				document.getElementById(flashcopier).innerHTML = divinfo;
 				alert('复制成功');
 			}
}

function check_reply_text()
{
	var content2 = $$('content2');
	if(''==content2.value)
	{
		alert("内容不能为空");
		return false;
	}
	return true;
}

function check_reply_video()
{
	var title = $$('title');
	if(""==title.value)
	{
		alert("title is null");
		return false;
	}
	var description = $$("description");
	if(""==description.value)
	{
		alert("内容不能为空");
		return false;
	}
	return true;
}

function check_recommend()
{
	var to_friend = $$("to_friend");	
	if(""==to_friend.value)
	{
		alert(lang('input_friend_email'));
		return false;
	}
	var msg = $$("msg");
	if(""==msg.value)
	{
		alert("内容不能为空");
		return false;
	}
	return true;
}

function show_page(ctype,page)
{
	if(!ck(ctype))
	{
		return false;
	}
	if(!ck(page))
	{
		page = 1;
	}
	var url = "show_page.php?ctype="+ctype+"&page="+page+"";
	$.get(url,function(data)
	{
		$("#video_list"+ctype).html(data);
	});
	
	
}


/*-------------------------------------------*/

//图片按比例缩放
function DrawImage(ImgD, iwidth, iheight) {
    var flag = false;
    var image = new Image;
    if (!iwidth) {
        iwidth = 480;
    }
    if (!iheight) {
        iheight = 360;
    }
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
                ImgD.height = image.height * iwidth / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        } else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = image.width * iheight / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}

function fix(o)
{
	var _pp = o.parentNode.parentNode;
	var _p = o.parentNode;
	if(!_p||!o)
	{
		return false;
	}
	var _pw = _p.offsetWidth;
	var _ph = _p.offsetHeight;	
	var _tw = o.width;
	var _th = o.height;
	o.style.marginLeft  = parseInt((_pw-_tw)/2)+"px";
	o.style.marginTop = parseInt((_ph-_th)/2)+"px";
}

