﻿
var lang = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);


function $(id) {
	return document.getElementById(id);
}

function LoadYear()
{
    for(var i=2008;i>1920;i--)
    {
        $("YearS").options.add(new Option(i,i));
    }
}

function signs() 
{
    var  birthyear = $("YearS").value, date=$("DayS").value, month=$("MonthS").value;

    with ($("zodiac"))
    {
        if (month == 3  &&  date >=21 || month == 4  &&  date <=19) {value = "1";}
        if (month == 3  &&  date > 31) {value = "OK.  Whatever.";}
        if (month == 4  &&  date >=20 || month == 5  &&  date <=20) {value = "2";}
        if (month == 4  &&  date > 30) {value = "I'm soooo sorry!";}
        if (month == 5  &&  date >=21 || month == 6  &&  date <=21) {value = "3";}
        if (month == 5  &&  date > 31) {value = "Umm ... no.";}
        if (month == 6  &&  date >=22 || month == 7  &&  date <=22) {value = "4";}
        if (month == 6  &&  date > 30) {value = "Sorry.";}
        if (month == 7  &&  date >=23 || month == 8  &&  date <=22) {value = "5";}
        if (month == 7  &&  date > 31) {value = "Excuse me?";}
        if (month == 8  &&  date >=23 || month == 9  &&  date <=22) {value = "6";}
        if (month == 8  &&  date > 31) {value = "Yeah. Right.";}
        if (month == 9  &&  date >=23 || month == 10  &&  date <=22) {value = "7";}
        if (month == 9  &&  date > 30) {value = "Try Again.";}
        if (month == 10  &&  date >=23 || month == 11  &&  date <=21) {value = "8";}
        if (month == 10  &&  date > 31) {value = "Forget it!";}
        if (month == 11  &&  date >=22 || month == 12  &&  date <=21) {value = "9";}
        if (month == 11  &&  date > 30) {value = "Invalid Date";}
        if (month == 12  &&  date >=22 || month == 1  &&  date <=19) {value = "10";}
        if (month == 12  &&  date > 31) {value = "No way!";}
        if (month == 1  &&  date >=20 || month == 2  &&  date <=18) {value = "11";}
        if (month == 1  &&  date > 31) {value = "Huh?";}
        if (month == 2  &&  date >=19 || month == 3  &&  date <=20) {value = "12";}
        if (month == 2  &&  date > 29) {value = "Say what?";}
    }
}

function birthdayOnchange(obj)
{
	var year = $("YearS").value;
	if(year == "YearS")
		return;
	else
		year = parseInt(year , 10);
	
	var month = $("MonthS").value;
	if(month == "MonthS")
		return;
	else
		month = parseInt(month , 10);
	
	var day = $("DayS").value;
	var wholeday = getDays(year , month);

	if(1)
	{
		var options = $("DayS").options;
		for(var i=1 ; i<=wholeday ; i++)	
		{
			var j = i.toString();
			j = j.length==1 ? "0" + j : j;
			options.length = i+1;
			options[i].value = j;
			options[i].text = j;
			if(day <= wholeday && i==day)
			{
				options[i].selected = true;
			}
		}
	}
}

function checkdoublepassword(){

  var pw1=$('PasswordTxt').value;
  var pw2=$('ConfirmPasswordTxt').value;
  
  if(pw1=='' &&  pw2=='') {
    return;
  }
  
  var str;
  
  if(pw1 != pw2) {
    str ="<img src='/images/icon/check_error.gif'/>两次输入的密码不一致";
  } else {
    str="<img src='/images/icon/check_right.gif'/>";
  }
  
  $('password2tips').innerHTML = str;
  
}

function htmlEncode(source, display, tabs) {

	function special(source) {
	
		var result = '';
		
		for (var i = 0; i < source.length; i++) {
			var c = source.charAt(i);
			if (c < ' ' || c > '~') {
				c = '&#' + c.charCodeAt() + ';';
			}
			result += c;
		}
		
		return result;
		
	}
	
	function format(source) {
	
		// Use only integer part of tabs, and default to 4
		tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
		// split along line breaks
		var lines = source.split(/\r\n|\r|\n/);
		// expand tabs
		
		for (var i = 0; i < lines.length; i++) {
		
			var line = lines[i];
			var newLine = '';
			
			for (var p = 0; p < line.length; p++) {
			
				var c = line.charAt(p);
				
				if (c === '\t') {
				
					var spaces = tabs - (newLine.length % tabs);
					
					for (var s = 0; s < spaces; s++) {
						newLine += ' ';
					}
				} else {
					newLine += c;
				}
			}
			
			// If a line starts or ends with a space, it evaporates in html
			// unless it's an nbsp.
			newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
			lines[i] = newLine;
			
		}
		
		// re-join lines
		var result = lines.join('<br />');
		// break up contiguous blocks of spaces with non-breaking spaces
		result = result.replace(/  /g, ' &nbsp;');
		// tada!
		return result;
		
	}
	
	var result = source;
	// ampersands (&)
	result = result.replace(/\&/g,'&amp;');
	// less-thans (<)
	result = result.replace(/\</g,'&lt;');
	// greater-thans (>)
	result = result.replace(/\>/g,'&gt;');
	
	if (display) {
		// format for display
		result = format(result);
	} else {
		// Replace quotes if it isn't for display,
		// since it's probably going in an html attribute.
		result = result.replace(new RegExp('"','g'), '&quot;');
	}
	// special characters
	result = special(result);
	// tada!
	return result;
}


function drawSelect(ctrlid,selectedValue,selectEnable){
  var select = "<select id=\"" + ctrlid + "\" name=\"" + ctrlid + "\"";
  if (!selectEnable) {
    select += "  disabled=\"disabled\"";
  }
  select += " >\r\n";
  select += "  <option value=\"0\">任何人</option>\r\n";
  select += "  <option value=\"1\">仅好友</option>\r\n";
  select += "  <option value=\"2\">隐藏</option>\r\n";
  select += "</select>";
  select += "<script type=\"text/javascript\">$(\"" + ctrlid + "\").value='" + selectedValue + "';</";
  select += "script>";
  document.write(select);
}


function drawHomeProvinceCityList(obj){
  var res = obj.getElementsByTagName("result");
  var resContainer = $("HomeCityS");
  resContainer.length = 0;      
	var result = "";			
	if (res[0] != null && res[0] != undefined) {	
		if (res[0].childNodes.length > 1) {				
		  for(var i = 0; i < res[0].childNodes.length; i++){				  
		    if (res[0].childNodes[i].nodeName == "#text"){
		      i=i+1;
		    }
		    var cityID = res[0].childNodes[i].attributes[0].value;
		    var cityName = res[0].childNodes[i].attributes[1].value;	    
		    resContainer.options.add(new Option(cityName, cityID));
		  }				  
		} else {
			//result = res[0].firstChild.nodeValue;
			var cityID = res[0].childNodes[0].attributes[0].value;
	    var cityName = res[0].childNodes[0].attributes[1].value;			    
	    resContainer.options.add(new Option(cityName, cityID));
		}
	}
}

function drawNowProvinceCityList(obj){
  var res = obj.getElementsByTagName("result");
  var resContainer = $("NowCityS");
  resContainer.length = 0;      
	var result = "";			
	if (res[0] != null && res[0] != undefined) {	
		if (res[0].childNodes.length > 1) {				
		  for(var i = 0; i < res[0].childNodes.length; i++){				  
		    if (res[0].childNodes[i].nodeName == "#text"){
		      i=i+1;
		    }
		    var cityID = res[0].childNodes[i].attributes[0].value;
		    var cityName = res[0].childNodes[i].attributes[1].value;	    
		    resContainer.options.add(new Option(cityName, cityID));
		  }				  
		} else {
			//result = res[0].firstChild.nodeValue;
			var cityID = res[0].childNodes[0].attributes[0].value;
	    var cityName = res[0].childNodes[0].attributes[1].value;			    
	    resContainer.options.add(new Option(cityName, cityID));
		}
	}
}

function showface(id){
  var targettxtid = "";
  if (id == '0'){
    targettxtid = "MessageTxt";
  } else {
    targettxtid = "retxt_" + id;
  }
  if($("#li_"+id).html() != null){
    $("#f_"+id).html("");
  } else {
    var facehtml = "<div class=\"flist\" id=\"li_"+id+"\">\r\n";
  //  alert(facehtml);
    facehtml += "  <ul id=\"f_u_"+id+"\">\r\n";
    
    for(var i=0;i<78;i++){
      var faceid = i+1;
      facehtml += "    <li><div id=\"fl_"+i+"\" class=\"fbg\"><img onclick=\"insertface('"+targettxtid+"','"+faceid+"','"+id+"');\" alt=\"\" src=\"/images/face/"+faceid+".gif\" style=\" margin:3px 0px 0px 3px;\" class=\"cursor\" /></div></li>\r\n";
    }
    
    facehtml += "  </ul>\r\n";
    facehtml += "</div>\r\n";
    
    facehtml += "<script type=\"text/javascript\">";
    for(var i=0;i<78;i++){
      facehtml += "$(\"#fl_"+i+"\").hover(function(){ $(\"#fl_"+i+"\").css(\"border-color\",\"Red\"); },function(){ $(\"#fl_"+i+"\").css(\"border-color\",\"#ccc\"); });";
    }
    facehtml += "</script>";
    
    //alert(facehtml);
    
    $("#f_"+id).html(facehtml);
    $("#f_"+id).hover(function(){},function(){ setTimeout( function (){clearfl("f_"+id);},1500); });
  }
}

function clearfl(facedivid){  
    $("#"+facedivid).html("");  
}

//暂不使用表情功能
function insertface(targetxt,faceid,facedivid){
  //alert(eval(targetxt));
//  $("#"+targetxt).setCaret();
  var img = document.createElement("IMG");
  img.src = "/images/face/"+faceid+".gif";
  $("#"+targetxt)[0].appendChild(img);
//  alert($("#"+targetxt).html());
//  alert(start);
//  appendChildAtCaret(targetxt,img);
  clearfl("f_"+facedivid);
}


//获得Cookie的原始值
function GetCookie(name) {
  var cookies = document.cookie;
  var codeindex = cookies.indexOf(name);
  var startindex = codeindex + (name + "=").length;
  var vcode = cookies.substring(startindex,cookies.length);
  return vcode;
}

