﻿/*	dream`s kernel script 
	create 2007.03.15
*/

function timing()
{
	var timenow = new Date();
	var days = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日");
	var day = days[timenow.getDay()];
	
	timenow = timenow.toLocaleString() + '&nbsp;&nbsp;' + day;

	document.getElementById('timing').innerHTML = timenow;
	setTimeout("timing()", 1000);
}

function change_bgcolor(place,thecolor)
{ place.bgColor = thecolor; }

function restore_bgcolor(place,thecolor)
{ place.bgColor = thecolor; }

function msgMove(boxwidth, boxheight,direction)
{
	var msgBox = document.getElementById('msgbox');
	msgBox.innerHTML = '<div style="width:' + boxwidth + 'px; height:' + boxheight + 'px; position:relative; overflow:hidden; border:solid 0px; text-align:left;"><marquee style="height:' + boxheight +'px;" direction="'+direction+'" scrollamount="1" scrolldelay="10" onMouseOver="this.stop();" onMouseOut="this.start();">' +
	msgBox.innerHTML + '</marquee></div>';
}


function hide_and_show(target, status)
{
	status = (typeof(status) != 'undefined') ? status : '';
	
	var show_status = document.getElementById(target).style.display;
	if(typeof(show_status) != 'undefined')
	{
		if(status)
		{ document.getElementById(target).style.display = status; return true;}
		
		else
		{
			if( show_status == 'none')
			{ document.getElementById(target).style.display = 'block'; return true;}
			if( show_status != 'none')
			{ document.getElementById(target).style.display = 'none';  return true; }
		}
	}
}

function create_upfile_field(target)
{
	var htmlcode = '';
	if(document.getElementById(target).innerHTML == '')
	{ htmlcode = '<input type="file" name="' + target + '" size="20" class=input_button>'; }
	document.getElementById(target).innerHTML = htmlcode;
	return true;
}

function resetTimeTable()
{
	var yearid = document.getElementById('yyyy');
	var monthid = document.getElementById('mm');
	var dateid = document.getElementById('dd');
	var hourid = document.getElementById('hh');
	var minuteid = document.getElementById('mi');
	var secondid = document.getElementById('ss');
	
	var timeValue = new Date();
	
	yearid.value = '';
	monthid.value = '';
	dateid.value = '';
	hourid.value = timeValue.getHours();
	minuteid.value = timeValue.getMinutes();
	secondid.value = timeValue.getSeconds();
}

function timeHtmlCode(group, mgm, gp, loopend, timeTarget,str)	
{
	var groupid = new Array();
	var thc = '<option value="">' + str + '</option>';
	var codeTarget = document.getElementById(timeTarget);
	
	for(loop = 0; loop < loopend; loop++)
	{
		groupid[loop] = loop + gp;
		if(groupid[loop] == mgm)
		{ thc = thc + '<option value=\"' + groupid[loop] + '\" selected=\"selected\">' + groupid[loop] + str + '</option>'; }
		else
		{ thc = thc + '<option value=\"' + groupid[loop] + '\">' + groupid[loop] + str + '</option>'; }
	}
	
	codeTarget.innerHTML = '<select id=\"' + group + '\" onChange=\"getTimeTableValue();\">' + thc + '</select>';
	return true;
}

function createTimeTable(onlySecond,format)
{
	format = typeof(format) == 'undefined' ? 'full' : 'short';
	var timeValue = (onlySecond) ? new Date(parseInt(onlySecond + '000')) : new Date();
	var years = timeValue.getFullYear();
	var months = timeValue.getMonth() + 1;
	var dates = timeValue.getDate();
	var hours = timeValue.getHours();
	var minutes = timeValue.getMinutes();
	var seconds = timeValue.getSeconds();
	
	//var tthc = format == 'full' ? '<table cellspacing="0" cellpadding="0"><tr><td id="year"></td><td id="month"></td><td id="date"></td><td id="hour"></td><td id="minute"></td><td id="second"></td></tr></table>' : '<table cellspacing="0" cellpadding="0"><tr><td id="year"></td><td id="month"></td><td id="date"></td><td id="hour" style="display:none;"></td><td id="minute" style="display:none;"></td><td id="second" style="display:none;"></td></tr></table>';
	var tthc = format == 'full' ? '<span id="year"></span><span id="month"></span><span id="date"></span><span id="hour"></span><span id="minute"></span><span id="second"></span>' : '<span id="year"></span><span id="month"></span><span id="date"></span><span id="hour" style="display:none;"></span><span id="minute" style="display:none;"></span><span id="second" style="display:none;"></span>';
	
	document.getElementById('timetable').innerHTML = tthc;

	var year_start = 1998; 
	var thisyear = new Date();
	thisyear = thisyear.getFullYear();
	
	timeHtmlCode('yyyy', years, 1998, (thisyear + 1 - year_start), 'year','年');
	timeHtmlCode('mm', months, 1, 12, 'month','月');
	timeHtmlCode('dd', dates, 1, 31, 'date','日');
	timeHtmlCode('hh', hours, 0, 24, 'hour','时');
	timeHtmlCode('mi', minutes, 0, 60, 'minute','分');
	timeHtmlCode('ss', seconds, 0, 60, 'second','秒');
	
}

function getTimeTableValue()
{
	var yearid = document.getElementById('yyyy');
	var monthid = document.getElementById('mm');
	var dateid = document.getElementById('dd');
	var hourid = document.getElementById('hh');
	var minuteid = document.getElementById('mi');
	var secondid = document.getElementById('ss');
	var timecode = yearid.value + '/' + monthid.value + '/' + dateid.value + '\x20' + hourid.value + ':' + minuteid.value + ':' + secondid.value;
	document.getElementById('timevalue').value = timeToSecond(timecode);
	
}

function timeToSecond(timeString)
{
	var timeValue = (timeString) ? timeString : new Date();
	timeValue = Date.parse(timeValue);
	timeValue = new Date(timeValue);
	timeValue = timeValue.getTime();
	var onlySecond = timeValue.toString();
	onlySecond += 'dream';
	var secondlength = onlySecond.indexOf('000dream');
	onlySecond = onlySecond.substring(0,secondlength);
	return onlySecond;
}

function create_drawdown(target,thename,arr,firstoption,str,funs)
{
	var htmlcode = '';
	
	funs = typeof(funs) != 'undefined' ? funs : '';
	funs = funs ? 'onchange=\"'+funs+'\"' : '';
	
	arrLength = arr.length;
	htmlcode = htmlcode + '<select name=\"'+thename+'\" id=\"'+thename+'\" '+funs+'>';
	htmlcode = htmlcode + '<option value = \"\">'+firstoption+'</option>'; 
	
	for(var loop = 0; loop < arrLength; loop++)
	{
		htmlcode = htmlcode + '<option value=\"'+arr[loop]+'\">'+arr[loop]+str+'</option>';
	}
	
	htmlcode = htmlcode + '</select>';
	
	document.getElementById(target).innerHTML = htmlcode;
	return true;
}

function setmonthTable(yearnum,monthnum)
{
	document.getElementById('yyyy').value = yearnum;
	year2month();
	document.getElementById('mm').value = monthnum;
	month2second();
}

function monthTable(onlySecond)
{
	var timeValue = (onlySecond) ? new Date(parseInt(onlySecond + '000')) : new Date();
	var years = timeValue.getFullYear();
	var months = timeValue.getMonth() + 1;
	
	var tthc = '<table cellspacing="0" cellpadding="0"><tr><td id="year"></td><td id="month"></td></tr></table>';
	document.getElementById('timetable').innerHTML = tthc;
	
	
	var months_arr = new Array();
	var years_arr = new Array();
	var year_start = 1998;
	
	var year_range = years - year_start + 1;
	
	for(loop = 0; loop < year_range; loop++)
	{ years_arr[loop] = year_start + loop; }
	
	create_drawdown('year', 'yyyy', years_arr, '年份', '年', 'year2month()');
	create_drawdown('month', 'mm', months_arr, '月份', '月', 'month2second()');
}

function year2month()
{
	var the_year = parseInt(document.getElementById('yyyy').value);
	var timenow = new Date();
	var current_year = timenow.getFullYear();
	var current_month = timenow.getMonth() + 1;
	
	var months_arr = new Array();
	var month_range = (the_year == current_year) ? current_month : 12;
	
	if(!the_year)
	{ month_range = 0; }
	
	for(loop = 0; loop < month_range; loop++)
	{ months_arr[loop] = loop + 1; }
	
	create_drawdown('month','mm', months_arr,'月份','月','month2second()');
	month2second();
}



function month2second()
{
	var year = parseInt(document.getElementById('yyyy').value);
	var month = parseInt(document.getElementById('mm').value);
	
	if(!year && !month)
	{
		return;
	}
	
	if(year && month)
	{
		end_year = month == 12 ? year + 1 : year;
		end_month = month == 12 ? 1 : month + 1;
	}
	
	if(year && !month)
	{
		month = 1;
		end_year = year + 1;
		end_month = 1;
	}
	
	
	var timestart = year + '/' + month + '/' + '1' + ' ' + '0:0:0'; 
	var timeend = end_year + '/' + end_month + '/' + '1' + ' ' + '0:0:0';
	
	document.getElementById('timestart').value = timeToSecond(timestart);
	document.getElementById('timeend').value = timeToSecond(timeend);
	
	
}




function create_textarea(target, ttname, ttvalue, ttrows, ttcols, show)
{
	var htmlcode = '';
	
	show = (typeof(show) != 'undefined') ? 'style="display:'+ show +'"' : '';

	htmlcode = htmlcode + '<div '+show+'><textarea rows="'+ttrows+'" cols="'+ttcols+'" name="'+ttname+'">'+ttvalue+'</textarea></div>';
	document.getElementById(target).innerHTML =  htmlcode;
	return true;
}

function create_input_text(target, iname, ivalue, show)
{	
	var htmlcode = '';
	
	show = (typeof(show) != 'undefined') ? 'style="display:'+ show +'"' : '';
	
	htmlcode = htmlcode + '<input type="text" name="' + iname + '" id="'+iname+'" value="'+ivalue+'" size="10">';
	
	document.getElementById(target).innerHTML = htmlcode;
	return true;
}

function create_array_checkbox(target, arrName, arr, show)
{
	var htmlcode = '';
	
	show = (typeof(show) != 'undefined') ? 'style="display:'+ show +'"' : '';
	
	arrLength = arr.length;
	htmlcode = htmlcode + '<div id=' + arrName + '>';
	for(var loop = 0; loop < arrLength; loop++)
	{
		if(typeof(arr[loop]) != 'undefined')
		{
			htmlcode = htmlcode + '<div class="small" id="'+loop+'"' +show+'><input type="checkbox" name="' + arrName + '" value="'+ loop +'" id="a'+loop+'">' + arr[loop] +'</div>';
		}
		
	}
	htmlcode = htmlcode + '</div>';
	
	document.getElementById(target).innerHTML =  htmlcode;
	return true;
}

function select_array_checkbox(target,arrName,select_arr)
{
	target_arrLength = document.getElementById(target).elements.length;
	arrLength = select_arr.length;
	for(var loop = 0; loop < target_arrLength; loop++)
	{
		var stuff = document.getElementById(target).elements[loop];
		if(stuff.name == arrName  && stuff.type == 'checkbox')
		{
			for(loop2 = 0; loop2 < arrLength; loop2++)
			{
				if(stuff.value == select_arr[loop2])
				{ stuff.checked = true; } 
			}
		}
		
	}
	
}

function dream_user_city(P_name,A_name,Division)
{
	var current_p = parseInt(document.getElementById(P_name).value);
	Division = parseInt(Division);
	
	var range_s = current_p * Division;
	var range_e = range_s + Division;
	
	var htmlcode = '<select name="'+A_name+'" id="'+A_name+'"><option value = "">选择城市</option>';
	
	for(var loop = range_s; loop < range_e; loop++)
	{
		if(typeof(area_staff[loop]) != 'undefined' && parseInt(loop / Division) == current_p)
		{
			htmlcode = htmlcode + '<option value = "'+loop+'">'+area_staff[loop]+'</option>';
		}
	}
	
	htmlcode = htmlcode + '</select>';
	
	document.getElementById(A_name+'s').innerHTML = htmlcode;
	return true;
}

function dream_user_province(Code_tar,P_name, P_arr, A_name, A_arr, Division)
{

	var P_htmlcode = '';
	var A_htmlcode = '';
	
	P_arr_len = P_arr.length;
	A_arr_len = A_arr.length;
	
	A_htmlcode = A_htmlcode + '<span id="'+A_name+'s"><select name="'+A_name+'" id="'+A_name+'">';
	A_htmlcode = A_htmlcode + '<option value = "">选择城市</option>';
	
	P_htmlcode = P_htmlcode + '<select name="'+P_name+'" id="'+P_name+'" onchange="dream_user_city(\''+P_name+'\',\''+A_name+'\',\''+Division+'\');">';
	
	P_htmlcode = P_htmlcode + '<option value = "">选择省份</option>';
	for(var loop = 0; loop < P_arr_len; loop++)
	{
		if(typeof(P_arr[loop]) != 'undefined')
		{
			P_htmlcode = P_htmlcode + '<option value = "'+loop+'">'+P_arr[loop]+'</option>';
		}
	}
	
	A_htmlcode = A_htmlcode + '</select></span>';
	P_htmlcode = P_htmlcode + '</select>';
	
	document.getElementById(Code_tar).innerHTML = P_htmlcode + A_htmlcode;
	return true;
}

function dream_default_PC(P_tar,P_value,A_tar,A_value,Division)
{	
	document.getElementById(P_tar).value = P_value;
	dream_user_city(P_tar,A_tar,Division);
	document.getElementById(A_tar).value = A_value;
	return true;
}



function dream_checkall_area(pid, division)
{
	var range = pid * division;
	var p_tar = document.getElementById('p'+pid);
	for(loop = range; loop < range + division; loop++)
	{
		if(typeof(area_staff[loop]) != 'undefined')
		{
			document.getElementById('a'+loop).checked = p_tar.checked;
		}
	}
}


function dream_switch_area(id,division)
{
	arrLength = area_staff.length;
	var newArr = new Array();
	
	var tempcode = '<input type="checkbox" id="p' + id + '" onclick="dream_checkall_area('+id+','+division+')";>' + '<span style="color:#FF0000;">' + province_staff[id] + '</span>';
	document.getElementById('checkall').innerHTML = tempcode;
	for(var loop = 0; loop < arrLength; loop++)
	{
		if(typeof(area_staff[loop]) != 'undefined')
		{
			if(parseInt(loop / division) == id)
			{ document.getElementById(loop).style.display = 'block';}
			else
			{ document.getElementById(loop).style.display = 'none';}
		}
	}
}

function dream_create_province(Code_tar,P_tar, P_arr, A_tar, A_name, A_arr, Division)
{
	var p_htmlcode = '';
	var a_htmlcode = '';
	
	arrLength = P_arr.length;
	p_htmlcode = p_htmlcode + '<div id=' + P_tar + '>';
	
	a_htmlcode = a_htmlcode + '<div id=' + A_tar + '></div>';
	
	for(var loop = 0; loop < arrLength; loop++)
	{
		if(typeof(P_arr[loop]) != 'undefined')
		{
			p_htmlcode = p_htmlcode + '<div class="small"><input onclick="dream_switch_area('+loop +','+Division+');" type="radio" name="' + P_tar + '" value="'+ loop +'">' + P_arr[loop] +'</div>';
		}
	}
	p_htmlcode = p_htmlcode + '</div><div style="clear:both;"></div><br><div id="checkall"></div>';
	
	document.getElementById(Code_tar).innerHTML =  p_htmlcode + a_htmlcode;
	document.getElementById(Code_tar).style.display = 'block';
	
	create_array_checkbox(A_tar, A_name,A_arr,'none');
	return true;
	
}

function dream_tagname_check(tagname)
{	
	var tag = document.getElementsByName(tagname);
	var checkpass = '';
	
	for(var loop = 0; loop < tag.length; loop++)
	{
		if(tag.item(loop).checked == true)
		{
			//alert(tag.item(loop).value);
			checkpass = 1;
			break;
		}
	}
	
	return checkpass ? true : false;
}

function wait()
{
	document.getElementById('lockback').style.display = "block";
	document.getElementById('lockback').style.width = document.body.clientWidth;
	document.getElementById('lockback').style.height = document.body.clientHeight;
	document.getElementById('lockmsg').style.display = 'block';
}

function dream_reconstruct_screen(offset)
{
	offset = typeof(offset) != 'undefined' ? offset : 0;
	var main_left = document.getElementById('main_left');
	var main_right = document.getElementById('main_right');
	var newheight = main_right.offsetHeight;
	
	newheight = newheight - offset;
	
	main_left.style.height = newheight < 575 ? 575 : newheight;
	//main_right.style.height = newheight;
	return true;
}

function dream_inputnum()
{
	//if(window.event)
	//{
		var inputnum = window.event.keyCode;
		//alert(inputnum);
		
		var result = ((inputnum >= 48 && inputnum <= 57) || (inputnum >= 96 && inputnum <= 105) || inputnum == 8 || inputnum == 144) ? true : false;
		window.event.returnValue = result;
		return result;
	//}
}

function dream_checkemail(target)
{
	var email = document.getElementById(target).value;
	
	var RegExpEmail = /^[\w\.]+[\w]+@{1,1}[\w\.]+[\.]{1,1}[\w]+$/gi;
	var result = RegExpEmail.test(email);
	return result;
}

function playtv(host,tv,w,h,autostart,image)
{
	
	tv = unescape(tv);
	tv = host+'/video/'+tv;
	
	var htmlcode = '<div style="background-color:#000000; width='+w+'px; height='+h+'px;"><embed src="mediaplayer/mediaplayer.swf" width="'+w+'" height="'+h+'" allowfullscreen="true" allowscriptaccess="always" flashvars="&file='+tv+'&height='+h+'&width='+w+'&autostart='+autostart+'&backcolor=0xC1C1C1&frontcolor=0x000000&lightcolor=0x996600&image='+image+'" /></div>';
	
	document.getElementById('tvshow').innerHTML = htmlcode;
}


function dream_print_data(parea)
{	
	if(!confirm("确定要打印？"))   return false;
	
	var pdata = document.getElementById(parea).innerHTML;
	
	var head_msg = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Print</title><link href="../css/dream.css" rel="stylesheet" type="text/css"></head><body>';

	var foot_msg = '</body></html>';
	
	var htmlcode = head_msg + pdata + foot_msg;
	
	var WindowFeatures = 'width=' + screen.width * 0.80 + ',height=' + screen.height * 0.35 +',';
	WindowFeatures = WindowFeatures + 'location=no,scrollbars=yes,resizable=yes';
	var resultWindow = window.open('', 'codeWin', WindowFeatures);
		resultWindow.document.write(htmlcode);
		resultWindow.document.close();
		resultWindow.print();
}


function swap_3_bkimage(startnum,status)
{
	var tar_0 = document.getElementById(startnum+'_0');
	var tar_1 = document.getElementById(startnum+'_1');
	var tar_2 = document.getElementById(startnum+'_2');
	
	tar_0.style.backgroundImage = (status == 'over') ? 'url(images/new_20.jpg)' : 'url()';
	tar_1.style.backgroundImage = (status == 'over') ? 'url(images/new_21.jpg)' : 'url()';
	tar_2.style.backgroundImage = (status == 'over') ? 'url(images/new_22.jpg)' : 'url()';
	
	tar_0.className = (status == 'over') ? 'white' : '';
	tar_1.className = (status == 'over') ? 'white' : '';
	tar_2.className = (status == 'over') ? 'white' : '';
	
	return;
}
