/*全局变量*/
var SITE_URL = "http://www.mythakitas.com";
var SITE_NAME = "神话犬舍";
if(window.location.hostname.toLowerCase() == 'localhost'){
	SITE_URL = "http://localhost:" + window.location.port; //window.location.hostname + ':' + window.location.port
}

//收藏本站
function addfavorite(){
	if (document.all){
		window.external.addFavorite(SITE_URL, SITE_NAME);
	}else if (window.sidebar){
		window.sidebar.addPanel(SITE_NAME, SITE_URL, "");
	}
} 

/*检测合法日期格式*/
function check_date(str){  
	var dateReg = /^(\d{4})-([0-9]{1,2})-([0-9]{1,2})$/;  
    if(str=="") return false;  
    if(!dateReg.test(str)){ // && RegExp.$2<=12 && RegExp.$3<=31    
		return false;  
    }
    return true;  
}

/*检测合法邮箱格式*/
function check_email(str){  
	var emailReg=/^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if(str=="") return false;  
    if(!emailReg.test(str)){
		return false;
    }
    return true;  
}

/*检测合法OICQ格式*/
function check_oicq(str){
	if(str=="") return false; 
	if((isNaN(parseInt(str))) || str.length<=4 || str.length>=12){
		return false;
	}
	return true;
}

function check_all(ck) {
	if ($(ck).attr('checked')) {
		$("form :input[name='id[]']").each(function() {
			$(this).attr('checked','checked');
			$(this).parent().parent().addClass('highlight');
		});
	} else {
		$("form :input[name='id[]']").each(function() {
			$(this).removeAttr('checked');
			$(this).parent().parent().removeClass('highlight');
		});
	}
}

function check_all2(ck) {
	if ($(ck).attr('checked')) {
		$("form :input[id='id']").each(function() {
			$(this).attr('checked','checked');
			$(this).parent().parent().addClass('highlight');
		});
	} else {
		$("form :input[id='id']").each(function() {
			$(this).removeAttr('checked');
			$(this).parent().parent().removeClass('highlight');
		});
	}
}

function show_tip(msg) {
	var html = '<span id="show_tip"><div>'+msg+'</div></span>';
	$('body').append(html);
	setTimeout("$('#show_tip').remove();",3000);
}

function do_submit(ac,form) {
	$('#do').val(ac);
	form.submit();
}

//获取SESSION中的验证码
function ajax_get_vdcode(){
	var vdcode = "";
	
	var data = "u=" + Math.random();
	$.ajax({
		async : false,
		type : 'POST',
		url : SITE_URL + '/include/getvdcode.php',
		data : data,
		cache : false,
		success : function(msg){			
			eval("var message = " + msg);
			vdcode = message.vdcode;
		}		
	});

	return vdcode;
}

//parent.document.title=document.title; 
//parent.window.location.hash = window.location.hash;
//parent.window.location.hash="aaaa";
//alert(main.src);
//if(window.location.href.indexOf("shou3-ye4-geng1-xin1.htm")==-1){ 
	
//} 


//图片按比例缩放
function DrawImage(ImgD,iwidth,iheight){
	//参数(图片,允许的宽度,允许的高度)
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		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;
			}
			//ImgD.alt=image.width+"×"+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;
			}
			//ImgD.alt=image.width+"×"+image.height;
		}
	}
}

//构建并输出FLASH
function bulid_flash(fName, fWidth, fHeight){
	var str	 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + fWidth + '" height="' + fHeight + '">';
		str += '<param name="movie" value="' + fName + '" />';
		str += '<param name="quality" value="high" />';
		str += '<param name="wmode" value="transparent">';
		str += '<embed src="' + fName + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + fWidth + '" height="' + fHeight + '"></embed>';
		str += '</object>';

	document.write(str);
}

//解决frame应用中地址栏不变的问题
(function()
{
	if(top != self)
	{
		var sURL = location.href.replace('&dj%5Fmenu0=%5Btype+Function%5D&%E5%8F%B3%E9%94%AE%E8%8F%9C%E5%8D%95=%5Bobject+Object%5D', '');
		sURL = sURL.replace(/http:\/\/www.mythakitas.com\//gi, '');

		top.document.title = document.title;
		top.location.href = SITE_URL + '/site.html#' + sURL;
		
	}
})()

window.onload = function(){
	for(var i = 0; i < document.links.length; i++)
	{
		//if(document.links[i].href.indexOf('#') != -1) document.links[i].href = document.links[i].href.replace(/#/gi, '');
	}
}
