function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ){
  var cookie_string = name + "=" + escape ( value );

  if (exp_y){
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if (path){
      cookie_string += "; path=" + escape ( path );
  }
  if (domain){
      cookie_string += "; domain=" + escape ( domain );
  }
  if (secure){
      cookie_string += "; secure";
  }

  document.cookie = cookie_string;
}

function get_cookie(cookie_name){
  var results = document.cookie.match(cookie_name + '=(.*?)(;|$)');
  if(results){
      return (unescape(results[1]));
  }else{
      return null;
  }
}

function delete_cookie( cookie_name ){
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

//获取所有name[]的数目
function getRadioValue(sName){
	var radio=document.getElementsByName(sName);
	for(i=0;i<radio.length;i++){
		if(radio[i].checked){
			return radio[i].value ;
		}

	}

	return 0 ;
}
//选中所有name[]的checkbox
function selectAllBox(sName){
	var i=0;
	var checkBox=document.getElementsByName(sName);
	for(i=0;i<checkBox.length;i++){
		checkBox[i].checked = true;
	}
}

//清空所有name[]的checkbox
function clearAllBox(sName){
	var i=0;
	var checkBox=document.getElementsByName(sName);
	for(i=0;i<checkBox.length;i++){
		checkBox[i].checked = false;
	}
}

//获取所有name[]的数目
function getCheckedBoxNumber(sName){
	var n=0;
	var checkBox=document.getElementsByName(sName);
	for(i=0;i<checkBox.length;i++){
		checkBox[i].checked?(n++):n;
	}
	return n;
}
//根据当前checkbox选择，选择所有的复选框
function checkBox(obj, sName){
	if( !obj.checked ){
		clearAllBox(sName) ;
	}else{
		selectAllBox(sName) ;
	}
}

//
function is_empty(value){
	if( value == '' || value == null || value == 0 || value == false){
		return true ;
	}

	return false ;
}

//数字和字母
function is_alphalet(value){
	if( !value.match( /^[A-Za-z0-9_]{1,20}$/i ) ){
        return false ;
    }

	return true ;
}

//小数
function is_decimal(value){
	if( !value.match( /^[0-9]+(\.?[0-9]+)?$/i ) ){
        return false ;
    }

	return true ;
}

//整数
function is_integer(value){
	if( !value.match( /^[0-9_]{1,20}$/i ) ){
        return false ;
    }

	return true ;
}

//Validate username
function is_username(value){
	if( !value.match( /^[A-z0-9]+$/i ) ){
        return false ;
    }

	return true ;
}
//Email格式
function is_email(value){
	if( !value.match( /^[A-z0-9-_\.]+@[A-z0-9-_\.]+\.+[A-z]+$/i ) ){
        return false ;
    }

	return true ;
}

//网址
function is_url(value){
	if( !value.match( /^http:\/\/.*/i) ){
        return false ;
    }

	return true ;
}

//图片格式
function is_image(value){
	if( !value.match( /^[^\.]+\.+(jpg|jpeg|gif|bmp|png)+$/i ) ){
        return false ;
    }
    
	return true ;
}

//加载flash文件
function load_flash(path,w,h){
	document.write('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height='+h+' width='+w+' classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 >') ;
    document.write('<param name="movie" value='+path+' />') ;
    document.write('<param name="quality" value="high" />') ;
	document.write('<param name="wmode" value="opaque">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />') ;
	document.write('<param name="swLiveConnect" value="true" />') ;
    document.write('<embed src='+path+' wmode="opaque" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" swLiveConnect="true" width='+w+' height='+h+'></embed>') ;
    document.write('</object>') ;
}
function load_mp3_flash(path,focus_width,focus_height,file){
	//path为动画路径,focus_width为动画宽度,text_height为动画底部文本高度,file为mp3路径
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ focus_height +'">');
	document.write('<param name="allowScriptAccess" value="sameDomain">') ;
	document.write('<param name="swLiveConnect" value="true" />') ;
	document.write('<param name="movie" value="'+path+'">') ;
	document.write('<param name="quality" value="high">') ;
	document.write('<param name="menu" value="false">') ;
	document.write('<param name="wmode" value="opaque">');
	document.write('<param name="FlashVars" value="file='+file+'&backcolor=0x000000&frontcolor=0xEECCDD&lightcolor=0xCC0066">');
	document.write('<embed src="'+path+'" wmode="opaque" FlashVars="file='+file+'&backcolor=0x000000&frontcolor=0xEECCDD&lightcolor=0xCC0066" menu="false" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
	document.write('</object>');
}
function load_flash_pic(path,focus_width,focus_height,text_height,pics,links,texts){
	//path为动画路径,focus_width为动画宽度,text_height为动画底部文本高度,pics为图片路径,links为鼠标点击链接,texts为图片说明
	var swf_height = focus_height+text_height;
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">');
	document.write('<param name="allowScriptAccess" value="sameDomain">') ;
	document.write('<param name="swLiveConnect" value="true" />') ;
	document.write('<param name="movie" value="'+path+'">') ;
	document.write('<param name="quality" value="high">') ;
	document.write('<param name="menu" value="false">') ;
	document.write('<param name="wmode" value="opaque">');
	document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
	document.write('<embed src="'+path+'" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
	document.write('</object>');
	/*
	//用法
	<script type="text/javascript">
		imgUrl1="images/1.jpg";
		imgtext1="中保康联人寿保险有限公司"
		imgLink1=escape("");
		imgUrl2="images/2.jpg";
		imgtext2="前沿私人酒店集团"
		imgLink2=escape("");
		imgUrl3="images/3.jpg";
		imgtext3="英国保诚集团"
		imgLink3=escape("");
		imgUrl4="images/4.jpg";
		imgtext4="交银施罗德基金管理有限公司"
		imgLink4=escape("");
		var pics=imgUrl1+"|"+imgUrl2+"|"+imgUrl3+"|"+imgUrl4
		var links=imgLink1+"|"+imgLink2+"|"+imgLink3+"|"+imgLink4
		var texts=imgtext1+"|"+imgtext2+"|"+imgtext3+"|"+imgtext4
		load_flash_pic("images/focus.swf",240,200,18,pics,links,texts) ;
	</script>
	*/
}
function load_flash_flv(path,focus_width,focus_height,file_list){

	var write = '<object type="application/x-shockwave-flash" data="include/js/flash/vcastr3.swf" width="'+focus_width+'" height="'+focus_height+'" id="vcastr3">' ;
	write +=    '	<param name="movie" value="include/js/flash/vcastr3.swf"/> ' ;
	write +=    '	<param name="allowFullScreen" value="true" />' ;
	write +=    '	<param name="wmode" value="transparent" />' ;
	write +=    '	<param name="FlashVars" value="xml=' ;
	write +=    '		<vcastr>' ;
	write +=    '			<channel>' ;
	write +=    '				<item>' ;
	write +=    '					<source>'+file_list+'</source>' ;
	write +=    '					<duration></duration>' ;
	write +=    '					<title></title>' ;
	write +=    '				</item>' ;
	write +=    '			</channel>' ;
	write +=    '			<config>' ;
	write +=    '			<isLoadBegin>true</isLoadBegin>' ;
	write +=    '			<buffertime>0</buffertime>' ;
	write +=    '			<isAutoPlay>false</isAutoPlay>' ;
	write +=    '			<isRepeat>false</isRepeat>' ;
	write +=    '			</config> ' ;
	write +=    '			<plugIns>' ;
	write +=    '				<logoPlugIn>' ;
	write +=    '					<url>include/js/flash/logoPlugIn.swf</url>' ;
	write +=    '					<logoText>www.myshoptown.eu</logoText>' ;
	write +=    '					<logoTextAlpha>0.5</logoTextAlpha>' ;
	write +=    '					<logoTextFontSize>14</logoTextFontSize>' ;
	write +=    '					<logoTextLink>http://www.myshoptown.eu</logoTextLink>' ;
	write +=    '					<logoTextColor>0x000000</logoTextColor>' ;
	write +=    '					<textMargin>0 40 auto auto</textMargin>' ;
	write +=    '				</logoPlugIn>' ;
	write +=    '				<javaScriptPlugIn>' ;
	write +=    '					<url>include/js/flash/javaScriptPlugIn.swf</url>' ;
	write +=    '				</javaScriptPlugIn> ' ;
	write +=    '			</plugIns>' ;
	write +=    '		</vcastr>"/>' ;
	write +=    '	</object>' ;
	document.write(write) ;
}

function load_flash_flv2(path,focus_width,focus_height,file_list){

	var write = '<object type="application/x-shockwave-flash" data="../include/js/flash/vcastr3.swf" width="'+focus_width+'" height="'+focus_height+'" id="vcastr3">' ;
	write +=    '	<param name="movie" value="../include/js/flash/vcastr3.swf"/> ' ;
	write +=    '	<param name="allowFullScreen" value="true" />' ;
	write +=    '	<param name="wmode" value="transparent" />' ;
	write +=    '	<param name="FlashVars" value="xml=' ;
	write +=    '		<vcastr>' ;
	write +=    '			<channel>' ;
	write +=    '				<item>' ;
	write +=    '					<source>'+file_list+'</source>' ;
	write +=    '					<duration></duration>' ;
	write +=    '					<title></title>' ;
	write +=    '				</item>' ;
	write +=    '			</channel>' ;
	write +=    '			<config>' ;
	write +=    '			<isLoadBegin>true</isLoadBegin>' ;
	write +=    '			<buffertime>0</buffertime>' ;
	write +=    '			<isAutoPlay>false</isAutoPlay>' ;
	write +=    '			<isRepeat>false</isRepeat>' ;
	write +=    '			</config> ' ;
	write +=    '			<plugIns>' ;
	write +=    '				<logoPlugIn>' ;
	write +=    '					<url>../include/js/flash/logoPlugIn.swf</url>' ;
	write +=    '					<logoText>www.myshoptown.eu</logoText>' ;
	write +=    '					<logoTextAlpha>0.5</logoTextAlpha>' ;
	write +=    '					<logoTextFontSize>14</logoTextFontSize>' ;
	write +=    '					<logoTextLink>http://www.myshoptown.eu</logoTextLink>' ;
	write +=    '					<logoTextColor>0x000000</logoTextColor>' ;
	write +=    '					<textMargin>0 40 auto auto</textMargin>' ;
	write +=    '				</logoPlugIn>' ;
	write +=    '				<javaScriptPlugIn>' ;
	write +=    '					<url>../include/js/flash/javaScriptPlugIn.swf</url>' ;
	write +=    '				</javaScriptPlugIn> ' ;
	write +=    '			</plugIns>' ;
	write +=    '		</vcastr>"/>' ;
	write +=    '	</object>' ;
	document.write(write) ;
}

function load_flash_flv_xml(path,focus_width,focus_height,xml_path){
	var swf_height = focus_height;
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="flv" width="'+ focus_width +'" height="'+ swf_height +'">');
	document.write('<param name="allowScriptAccess" value="sameDomain">') ;
	document.write('<param name="swLiveConnect" value="true" />') ;
	document.write('<param name="allowFullScreen" value="true" />') ;
	document.write('<param name="movie" value="'+path+'">') ;
	document.write('<param name="quality" value="high">') ;
	document.write('<param name="menu" value="false">') ;
	document.write('<param name="wmode" value="opaque">');
	document.write('<param name="FlashVars" value="vcastr_xml='+xml_path+'">');
	document.write('<embed src="'+path+'" wmode="opaque" FlashVars="vcastr_xml='+xml_path+'" menu="false" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" swLiveConnect="true" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
	document.write('</object>');
}

//加载movie_window窗口
function load_movie_window(w,h,path){
	document.write('<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="movie_window" width="'+w+'" height="'+h+'">') ;
	document.write('<param name="URL" value="'+path+'">') ;
	document.write('<param name="rate" value="1">') ;
	document.write('<param name="balance" value="0">') ;
	document.write('<param name="currentPosition" value="0">') ;
	document.write('<param name="defaultFrame" value>') ;
	document.write('<param name="playCount" value="1">') ;
	document.write('<param name="autoStart" value="-1">') ;
	document.write('<param name="currentMarker" value="0">') ;
	document.write('<param name="invokeURLs" value="-1">') ;
	document.write('<param name="baseURL" value>') ;
	document.write('<param name="volume" value="100">') ;
	document.write('<param name="mute" value="0">') ;
	document.write('<param name="uiMode" value="full">') ;
	document.write('<param name="stretchToFit" value="0">') ;
	document.write('<param name="windowlessVideo" value="-1">') ;
	document.write('<param name="enabled" value="-1">') ;
	document.write('<param name="enableContextMenu" value="-1">') ;
	document.write('<param name="fullScreen" value="0">') ;
	document.write('<param name="SAMIStyle" value>') ;
	document.write('<param name="SAMILang" value>') ;
	document.write('<param name="SAMIFilename" value>') ;
	document.write('<param name="captioningID" value>') ;
	document.write('<param name="enableErrorDialogs" value="0">') ;
	document.write('</object>') ;
}

//更换movie_window影片
function change_movie(id,path){
	var videoWindow=document.getElementById(id);
	videoWindow.URL=path;
}

//toggle 显示div
function toggle_div(id, offset_id, top_offset, left_offset){
	if(top_offset == null){
		top_offset = 0 ;
	}
	if(left_offset == null){
		left_offset = 0 ;
	}
	if(jQuery != null){
        jQuery('#'+id).css({top:jQuery('#'+offset_id).offset().top+top_offset+'px',left:jQuery('#'+offset_id).offset().left+jQuery('#'+offset_id).width()+left_offset+'px'}).toggle() ;
	}else{
		alert('This function requires jQuery library !') ;
	}
}

//显示div
function show_div(id, offset_id, top_offset, left_offset){
	if(top_offset == null){
		top_offset = 0 ;
	}
	if(left_offset == null){
		left_offset = 0 ;
	}
	if(jQuery != null){
        jQuery('#'+id).css({top:jQuery('#'+offset_id).offset().top+top_offset+'px',left:jQuery('#'+offset_id).offset().left+jQuery('#'+offset_id).width()+left_offset+'px'}).show() ;
	}else{
		alert('This function requires jQuery library !') ;
	}
}

//下拉菜单相关函数{{{{{{{{{{{{{{{{
function findPosX(obj) {
	var curleft = 0;
	if (document.getElementById || document.all) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (document.layers) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (document.getElementById || document.all) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (document.layers) {
		curtop += obj.y;
	}
	return curtop;
}

function fnDropDown(obj,Lay){
    var tagName = document.getElementById(Lay);
    var leftSide = findPosX(obj);
    var topSide = findPosY(obj);
    var maxW = tagName.style.width;
    var widthM = maxW.substring(0,maxW.length-2);
    var getVal = eval(leftSide) + eval(widthM);
    if(getVal  > document.body.clientWidth ){
        leftSide = eval(leftSide) - eval(widthM);
        tagName.style.left = leftSide + 34 + 'px';
    }
    else
        tagName.style.left= leftSide + 'px';
    tagName.style.top= topSide + 28 +'px';
    tagName.style.display = 'block';
 }

function fnShowDrop(obj){
	document.getElementById(obj).style.display = 'block';
}

function fnHideDrop(obj){
	document.getElementById(obj).style.display = 'none';
}

function fnvshobj(obj,Lay){
    var tagName = document.getElementById(Lay);
    var leftSide = findPosX(obj);
    var topSide = findPosY(obj);
    var maxW = tagName.style.width;
    var widthM = maxW.substring(0,maxW.length-2);
    if(Lay == 'editdiv') {
        leftSide = leftSide - 225;
        topSide = topSide - 125;
    }else if(Lay == 'transferdiv'){
		leftSide = leftSide - 10;
	    topSide = topSide;
	}
    var IE = document.all?true:false;
    if(IE){
        if($("repposition1")){
            if(topSide > 1200){
                topSide = topSide-250;
            }
        }
   }
	
    var getVal = eval(leftSide) + eval(widthM);
    if(getVal  > document.body.clientWidth ){
        leftSide = eval(leftSide) - eval(widthM);
        tagName.style.left = leftSide + 34 + 'px';
    }else{
        tagName.style.left= leftSide + 'px';
    }
    tagName.style.top= topSide + 'px';
    tagName.style.display = 'block';
    tagName.style.visibility = "visible";
}

function fnhide(Lay){
    var tagName = document.getElementById(Lay);
    tagName.style.visibility = 'hidden';
    tagName.style.display = 'none';
}
function fnshow(divId)
{
	var id = document.getElementById(divId);
    id.style.visibility = 'visible';
	id.style.display = 'inline';
}
//}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}


//改变编辑框高度
function changeEditorSize(bFlag,sID){
	var editor=document.getElementById(sID);
	var h=parseInt(editor.height);
	if((!bFlag) && (h<=100)){
	    return ;
	}
	h=bFlag?(h+100):(h-100);
	editor.height=h+'px';
}
//改变Textarea高度
function changTextareaSize(bFlag,sID){
	var editor=document.getElementById(sID);
	
	var h = 0 ;
	if(editor.style.height == ''){
		h = editor.style.height ;
	}else{
		h = parseInt(editor.style.height) ;
	}

	if((!bFlag) && (h<=60)){
	    return ;
	}
	h=bFlag?(h+60):(h-60);
	editor.style.height=h+'px';
}

function popup_window(url, width, height){
	var iTop  = (window.screen.height - height) / 2; 
	var iLeft = (window.screen.width - width) / 2;
	window.open(url,"Popup","scrollbars=yes,alwaysRaised=yes,toolbar=no,location=0,status=0,direction=no,resizable=0 nor resizable=false,Width="+width+",Height="+height+",top="+iTop+",left="+iLeft) ;
}
//Available to resize the window
function popup_window2(url, width, height){
	var iTop  = (window.screen.height - height) / 2; 
	var iLeft = (window.screen.width - width) / 2;
	window.open(url,"Popup","scrollbars=yes,alwaysRaised=yes,toolbar=no,location=0,status=0,direction=no,resizable=yes,Width="+width+",Height="+height+",top="+iTop+",left="+iLeft) ;
}
//打开一个新页面
var is_open = false ;
var w = null ;
function winopen(url,iWidth,iHeight,scrollbars) { 
	//var iWidth=855; //窗口宽度 
	//var iHeight=548;//窗口高度 
	var iTop  = (window.screen.height - iHeight) / 2; 
	var iLeft = (window.screen.width - iWidth) / 2;

	if(!w){
		w = window.open(url,"Detail","scrollbars="+scrollbars+
				   ",alwaysRaised=yes,toolbar=no,location=0,status=0,direction=no,resizable=yes,Width="+iWidth+",Height="+iHeight+",top="+iTop+",left="+iLeft) ;
	}else{
		w.close() ;
		w = window.open(url,"Detail","scrollbars="+scrollbars+
				   ",alwaysRaised=yes,toolbar=no,location=0,status=0,direction=no,resizable=yes,Width="+iWidth+",Height="+iHeight+",top="+iTop+",left="+iLeft) ;
	}
}
