/*
 * hipic.web.app
 * Copyright(c) 2010, FeiKan.
 * 
 * This code is licensed under BSD license. Use it as you wish, 
 * but keep this copyright intact.
 */


var namespace=function()
{var o,d;$.each(arguments,function(u,v)
{d=v.split(".");o=window[d[0]]=window[d[0]]||{};if(d.length)
{$.each(d.slice(1),function(u2,v2)
{o=o[v2]=o[v2]||{};});}});return o;};namespace('hipic.type');namespace('hipic.math');namespace('hipic.guid');namespace('app');namespace('app.enum');namespace('app.controls');namespace('app.ui');namespace('app.entity');Boolean.prototype.toCString=function()
{return this==true?'True':'False';};String.prototype.mapUrl=function()
{var ret=this;if(this)
{ret=ret.replace(/^([~[/?]])+/,OP['url-flicker-base']);}
return ret;};String.prototype.toString=function()
{var args=arguments;if(args.length&&(typeof args[0]=="object")&&(args[0]instanceof Array))
{args=args[0];}
return args.length&&this.replace(/\{(\d+)\}/g,function(m,i)
{return args[i];})||this;}
String.prototype.toInt32=function()
{var ret=0;if(this)
{var s=(/-?\d+/g).exec(this);if(s)
{ret=parseInt(s.join());}}
return ret;}
String.prototype.trim=function()
{return this&&$.trim(this)||'';}
String.prototype.len=function()
{var s=$.trim(this||'');if(!s)
return 0;else
return s.replace(/[^\x00-\xff]/g,'??').length;};String.prototype.noHtml=function()
{return this.replace(/<\/?[^>]*>/g,'').replace(/[ | ]*\n/g,'\n').replace(/\n[\s| | ]*\r/g,'\n');};String.prototype.len2=function()
{var s=$.trim(this||'');return s?s.length:0;};String.prototype.sub=function(len)
{var s=$.trim(this||'');if(!s)
return'';var l=0;var ret='';var cr=/[^\x00-\xff]/g;var sc='';var sl=s.replace(cr,'??').length;for(var i=0;i<sl;i++)
{sc=s.charAt(i).toString();if(sc.match(cr))
l+=2;else
l++;if(l>len)
break;ret+=sc;}
if(sl>len)
ret+="...";return ret;};String.prototype.startWith=function(s)
{if(this)
{return new RegExp('^'+s).test(this.trim());}
else
{return false;}};String.prototype.endWith=function(s)
{if(this)
{return new RegExp(s+'$').test(this.trim());}
else
{return false;}};String.prototype.toDate=function()
{return Date.parse(this);};String.prototype.stripHtml=function(exceptTag)
{return this.replace(/<br[.]*>/gi,'\r').replace(/<("[^"]*"|'[^']*'|[^'">])*?>/gi,'').replace(/\r/g,'<br />');};Date.prototype.format=function(fmt,notZero)
{var o={'M+':this.getMonth()+1,'d+':this.getDate(),'h+':this.getHours()%12==0?12:this.getHours()%12,'H+':this.getHours(),'m+':this.getMinutes(),'n+':this.getMinutes()+this.getHours()*60,'s+':this.getSeconds(),'q+':Math.floor((this.getMonth()+3)/3),'S':this.getMilliseconds()};var week={'0':'\u65e5','1':'\u4e00','2':'\u4e8c','3':'\u4e09','4':'\u56db','5':'\u4e94','6':'\u516d'};if(/(y+)/.test(fmt))
{fmt=fmt.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length));}
if(/(E+)/.test(fmt))
{fmt=fmt.replace(RegExp.$1,((RegExp.$1.length>1)?(RegExp.$1.length>2?'\u661f\u671f':'\u5468'):'')+week[this.getDay()+'']);}
for(var k in o)
{if(new RegExp('('+k+')').test(fmt)&&(!notZero||RegExp.$1!=0))
{var v=hipic.type.isNumber(o[k])?o[k]:'0';fmt=fmt.replace(RegExp.$1,(RegExp.$1.length==1)?v:(('00'+v).substr((''+v).length)));}}
return fmt;};Date.prototype.toFullShortString=function()
{};Date.prototype.parse=function(s)
{var d=Date.parse(s,this);return d||this;};Date.prototype.toUtc=function()
{return Date.toUtc(this);};Date.toUtc=function(date)
{return TYPE.isDate(date)?'\/Date({0}+0800)\/'.toString(date.getTime()):null;};Date.fromUtc=function(s,fmt)
{var v=/-?\d+/.exec(s);if(v)
{var d=s?new Date(+v):null;if(d&&fmt)
{d=d.format(fmt);}
return d||null;}};Date.parse=function(s,date,fmt)
{var d=Date.fromUtc(s,fmt||date);if(d)
{return d;}
else if(/(([12]\d{3})-?(1[0-2]|0?\d)?-?([1-2]\d|3[0-1]|0?\d)?)?\D?((2[0-3]|[0|1]?\d)\:?([1-5]\d|0?\d)?\:?([1-5]\d|0?\d)?)?/.test(s))
{var d=new Date(date||null);if(!d)
{d=new Date();}
if(RegExp.$2)
{d.setFullYear(RegExp.$2<1970?1970:(RegExp.$2>2099?2099:RegExp.$2));}
if(RegExp.$3)
{d.setMonth((RegExp.$3<1?1:(RegExp.$3>12?12:RegExp.$3))-1);}
if(RegExp.$4)
{var day=RegExp.$4;if(day<1)
{day=1;}
else
{var v=[d.getFullYear(),d.getMonth()];var days=OP['ui-calendar-day-of-month'][v[1]];if(v[1]==2&&(!(v[0]%4)&&v[0]%100))
{days++;}
if(day>days)
{day=days;}}
d.setDate(day);}
if(RegExp.$6)
{d.setHours((RegExp.$6<0?0:(RegExp.$6>23?23:RegExp.$6)));}
if(RegExp.$7)
{d.setMinutes((RegExp.$7<0?0:(RegExp.$7>59?59:RegExp.$7)));}
if(RegExp.$8)
{d.setSeconds((RegExp.$8<0?0:(RegExp.$8>59?59:RegExp.$8)));}
return fmt?d.format(fmt):d;}
else
{return null;}};Date.milliseconds=function(s)
{if(!isNaN(s))
{if(s==0)
{return 0;}
else if(s>1000)
{return Date.milliseconds(s/1000);}
else
{return s.toFixed(1);}}
else
{return 0;}};Date.format=function(date,fmt)
{var d=fmt&&date||new Date();var f=fmt||date;return d.format(f);}
Date.formatBorn=function(fmt,diff)
{var d1=new Date(),d2=new Date(2007,9,4);var t=d1.getTime()-d2.getTime();var SEC=1000;var MIN=SEC*60;var HOUR=MIN*60;var DAY=HOUR*24;var MONTH=DAY*30;var YEAR=MONTH*12;var ms=t;if(diff)
{ms+=DAY*diff;}
var yy=parseInt(ms/YEAR);ms-=YEAR*yy;var MM=parseInt(ms/MONTH);ms-=MONTH*MM;var dd=parseInt(ms/DAY);ms-=DAY*dd;var hh=parseInt(ms/HOUR);ms-=HOUR*hh;var mm=parseInt(ms/MIN);ms-=MIN*mm;var ss=parseInt(ms/SEC);ms-=SEC*ss;var o={'YY':yy,'yy':yy,'MM':MM,'dd':dd,'HH':hh,'hh':hh,'mm':mm,'ss':ss,'SS':ms}
for(var k in o)
{if(new RegExp('('+k+')').test(fmt))
{fmt=fmt.replace(RegExp.$1,o[k]);}}
return fmt;}
Number.prototype.toSeconds=function()
{if(this<=0)
{return 0;}
else if(this>1000)
{return(this/1000).toSeconds();}
else
{return this.toFixed(1);}}
Number.prototype.toFileSize=function()
{var f=0;try
{if(this<1024)
f=this+" bytes";else if(this<1048576)
f=(Math.round(((this*10)/1024))/10)+" KB";else
f=(Math.round(((this*10)/1048576))/10)+" MB";}
catch(ex)
{f='0 bytes'}
return f;};Number.prototype.PadLeft=function(len)
{var s=!isNaN(s)&&this.toString()||'';if(s.length<len)
{for(var i=s.length;i<=len;i++)
{s='0'+s;}}
return s;};Number.prototype.abs=function()
{if(!isNaN(+this))
{return Math.abs(this);}}
Number.prototype.or=function(value)
{if(!isNaN(+value)&&value.abs()==value)
{return this|value;}
return this;}
Number.prototype.and=function(value)
{if(!isNaN(+value)&&value.abs()==value)
{return(this&value)==value;}
else
{return this;}}
Number.prototype.not=function(value)
{if(!isNaN(+value)&&value.abs()==value)
{return this.and(value)?this&(this^value):this;}
else
{return this;}}
location.hash2=(function()
{var s=location.hash;if(s)
{s=s.replace(/\D/g,'');}
return s;})();hipic.type=function()
{throw new Error("hipic.type 是命名空间.");}
hipic.type.isString=function(value)
{return((typeof(value)=="string")||((typeof value=="object")&&(value instanceof String)));}
hipic.type.isDate=function(value)
{return((typeof value=="object")&&(value instanceof Date));}
hipic.type.isRegExp=function(value)
{return((typeof value=="object")&&(value instanceof RegExp));}
hipic.type.isArray=function(value)
{return((typeof value=="object")&&(value instanceof Array));}
hipic.type.isNumber=function(value)
{return!isNaN(value);}
hipic.type.isBoolean=function(value)
{return((typeof(value)=="boolean")||((typeof value=="object")&&(value instanceof Boolean)));}
hipic.type.isFunction=function(value)
{return((typeof value=="function")||((typeof value=="object")&&(value instanceof Function)));}
hipic.type.isInteger=function(value)
{return(hipic.type.isNumber(value)&&(Math.round(value)==value));}
hipic.type.isFloat=function(value)
{if(hipic.type.isString(value))
{return false;}
return(hipic.type.isNumber(value)&&(Math.round(value)!=value));}
hipic.type.isError=function(value)
{return((typeof value=="object")&&(value instanceof Error));}
hipic.type.isCustom=function(value,typeString,instance)
{var ts=instance&&typeString;var ins=instance||typeString;if(!ts)
{ts=typeof value;}
return((typeof value==ts)&&(value instanceof ins));}
hipic.math=function()
{throw new Error("hipic.math 是命名空间.")}
hipic.math.dec2Bin=function(decInt)
{return decInt.toString(2);}
hipic.math.hexNumArray=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");hipic.math.dec2Hex=function(decInt)
{return decInt.toString(16).toUpperCase();}
hipic.math.numHexArray={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","A":"10","B":"11","C":"12","D":"13","E":"14","F":"15"};hipic.math.hex2Dec=function(oriHexStr)
{return parseInt(oriHexStr,16);}
hipic.math.bin2Dec=function(binStr)
{return parseInt(binStr,2);}
hipic.math.binHexArray={"0000":"0","0001":"1","0010":"2","0011":"3","0100":"4","0101":"5","0110":"6","0111":"7","1000":"8","1001":"9","1010":"A","1011":"B","1100":"C","1101":"D","1110":"E","1111":"F"};hipic.math.bin2Hex=function(binStr)
{var n=0;while(binStr.charAt(n)=="0")
{n++;}
if(n>0)
{binStr=binStr.substring(n,binStr.length);}
var i,hexStrArray=[],binHexArray=hipic.math.binHexArray,len=binStr.length;for(i=len;i>3;i=i-4)
{hexStrArray.push(binHexArray[binStr.substring(i-4,i)]);}
hexStrArray.push(binHexArray[hipic.math.fillZero(binStr.substring(i-4,i),4)]);return hexStrArray.reverse().join("");}
hipic.math.hexBinArray={"0":"0000","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101","6":"0110","7":"0111","8":"1000","9":"1001","A":"1010","B":"1011","C":"1100","D":"1101","E":"1110","F":"1111"};hipic.math.hex2Bin=function(hexStr)
{var n=0;while(hexStr.charAt(n)=="0")
{n++;}
if(n>0)
{hexStr=hexStr.substring(n,hexStr.length);}
var hexStrArray=hexStr.sivalit(""),len=hexStrArray.length,binStrArray=[],hexBinArray=hipic.math.hexBinArray;for(var i=0;i<len;i++)
{binStrArray.push(hexBinArray[hexStrArray[i]]);}
return binStrArray.join("");}
hipic.math.fillZero=function(str,stdLength,allowEmpty)
{if(str==""&&!allowEmpty)
{return"";}
c=stdLength-str.length;var str0=""
for(var i=0;i<c;i++)
{str0="0"+str0;}
return str0+str;}
hipic.math.genRandomString=function(len)
{if(!(hipic.type.typeUtil.isInteger(len)&&len>0))
{len=2;}
var rnd="";for(var i=0;i<len;i++)
{rnd+=hipic.math.__genRandomString();}
return rnd;}
hipic.hashTable=function()
{this.o={};for(key in this.o)
{delete this.o[key];}
this.size=0;}
hipic.hashTable.prototype.getSize=function()
{return this.size;}
hipic.hashTable.prototype.add=function(key,value)
{if(!(key in this.o))
{this.size++;}
this.o[key]={"v":value};}
hipic.hashTable.prototype.get=function(key)
{if(key in this.o)
{return this.o[key]["v"];}
return null;}
hipic.hashTable.prototype.containsKey=function(key)
{return(key in this.o);}
hipic.hashTable.prototype.getKeyListByValue=function(value)
{var list=[];for(key in this.o)
{if(this.o[key]["v"]==value)
{list.push(key);}}
return list;}
hipic.hashTable.prototype.remove=function(key)
{if(key in this.o)
{this.size--;delete this.o[key]["v"];delete this.o[key];}}
hipic.hashTable.prototype.removeAll=function()
{for(key in this.o)
{delete this.o[key]["v"];delete this.o[key];}
this.size=0;}
hipic.hashTable.prototype.getO=function()
{return this.o;}
hipic.hashTable.prototype.join=function(str1,str2)
{var a=new Array();for(key in this.o)
{a.push(key+str1+this.get(key));}
return a.join(str2);}
hipic.hashTable.disivaose=function(oht)
{oht.disivaose();oht=null;}
hipic.hashTable.prototype.disivaose=function()
{this.removeAll();}
hipic.guid=function()
{throw new Error("hipic.guid 是命名空间.")}
hipic.guid.__GUIDPool=new hipic.hashTable();hipic.guid.__GUIDCheckAndAdd=function(guid)
{if(!hipic.guid.__GUIDPool.containsKey(guid))
{hipic.guid.__GUIDPool.add(guid,true);return true;}
else
{return false;}}
hipic.guid.__newGuid=function()
{var part1=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFF")+1)));var part2=hipic.math.dec2Hex(Math.floor(Math.random()*65536));var str4=hipic.math.fillZero(hipic.math.dec2Bin(Math.floor(Math.random()*256)));var part3=hipic.math.dec2Hex(Math.floor(Math.random()*65536));var part4=hipic.math.bin2Hex(str4.substr(0,5)+"01"+str4.substr(7,1));var part5=hipic.math.dec2Hex(Math.floor(Math.random()*256));var part6=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFFFFFF")+1)));var guid=""+part1+"-"+part2+"-"+part3+"-"+part4+part5+"-"+part6;if(hipic.guid.__GUIDCheckAndAdd(guid))
{return guid;}
else
{return hipic.guid.__newGuid();}}
hipic.guid.newGuid=function()
{var part1=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFF")+1)));var part2=hipic.math.dec2Hex(Math.floor(Math.random()*65536));var str4=hipic.math.fillZero(hipic.math.dec2Bin(Math.floor(Math.random()*256)));var part3=hipic.math.dec2Hex(Math.floor(Math.random()*65536));var part4=hipic.math.bin2Hex(str4.substr(0,5)+"01"+str4.substr(7,1));var part5=hipic.math.dec2Hex(Math.floor(Math.random()*256));var part6=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFFFFFF")+1)));part1=hipic.math.fillZero(part1,8);part2=hipic.math.fillZero(part2,4);part3=hipic.math.fillZero(part3,4);part4=hipic.math.fillZero(part4,2);part5=hipic.math.fillZero(part5,2);part6=hipic.math.fillZero(part6,12);var guid=""+part1+"-"+part2+"-"+part3+"-"+part4+part5+"-"+part6;if(hipic.guid.__GUIDCheckAndAdd(guid))
{return guid;}
else
{return hipic.guid.newGuid();}}
hipic.guid.newGuidV4=function()
{var part1=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFF")+1)));var part2=hipic.math.dec2Hex(Math.floor(Math.random()*65536));var str3=hipic.math.fillZero(hipic.math.dec2Bin(Math.floor(Math.random()*65536)),16);var part3=hipic.math.bin2Hex(str3.substr(0,12)+"0100");var str4=hipic.math.fillZero(hipic.math.dec2Bin(Math.floor(Math.random()*256)));var part4=hipic.math.bin2Hex(str4.substr(0,5)+"01"+str4.substr(7,1));var part5=hipic.math.dec2Hex(Math.floor(Math.random()*256));var part6=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFFFFFF")+1)));part1=hipic.math.fillZero(part1,8);part2=hipic.math.fillZero(part2,4);part3=hipic.math.fillZero(part3,4);part4=hipic.math.fillZero(part4,2);part5=hipic.math.fillZero(part5,2);part6=hipic.math.fillZero(part6,12);var guid=""+part1+"-"+part2+"-"+part3+"-"+part4+part5+"-"+part6;if(hipic.guid.__GUIDCheckAndAdd(guid))
{return guid;}
else
{return hipic.guid.newGuidV4();}}
hipic.guid.__genRandomString=function()
{var part1=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFF")+1)));var part2=hipic.math.dec2Hex(Math.floor(Math.random()*65536));var str4=hipic.math.fillZero(hipic.math.dec2Bin(Math.floor(Math.random()*256)));var part3=hipic.math.dec2Hex(Math.floor(Math.random()*65536));var part4=hipic.math.bin2Hex(str4.substr(0,5)+"01"+str4.substr(7,1));var part5=hipic.math.dec2Hex(Math.floor(Math.random()*256));var part6=hipic.math.dec2Hex(Math.floor(Math.random()*(hipic.math.hex2Dec("FFFFFFFFFFFF")+1)));part1=hipic.math.fillZero(part1,8);part2=hipic.math.fillZero(part2,4);part3=hipic.math.fillZero(part3,4);part4=hipic.math.fillZero(part4,2);part5=hipic.math.fillZero(part5,2);part6=hipic.math.fillZero(part6,12);var guid=part1+part2+part3+part4+part5+part6;return guid;};hipic.keypad=(function()
{return{Keys:{BACKSPACE:8,CAPS_LOCK:20,COMMA:188,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,F5:116},isNumber:function(v)
{switch(v)
{case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case this.Keys.F5:case this.Keys.TAB:case this.Keys.DELETE:case this.Keys.BACKSPACE:case this.Keys.LEFT:case this.Keys.RIGHT:case this.Keys.ENTER:return true;default:return false;}}}})();hipic.cookie=function(name,reset)
{if(reset===true)
{document.cookie='User=';}
else
{var cookieValue=null;if(document.cookie&&document.cookie!='')
{var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++)
{var cookie=jQuery.trim(cookies[i]);if(cookie.substr(0,5)==('User='))
{var str=cookie.substr(5,cookie.length-5);var arr=str.split('&');for(var j=0;j<arr.length;j++)
{var s=arr[j].trim();if(s.substr(0,name.length+1)==(name+'='))
{cookieValue=decodeURIComponent(s.substring(name.length+1));break;}}}
if(cookieValue)
{break;}}}
return cookieValue;}};hipic.cookie2=function(name,value,options)
{if(typeof value!='undefined')
{options=options||{};if(value===null)
{value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString))
{var date;if(typeof options.expires=='number')
{date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else
{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');return this;}
else
{var cookieValue=null;if(document.cookie&&document.cookie!='')
{var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++)
{var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'='))
{cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};
