﻿
var keywordTip=gMsg.keyword;
$.ajaxSetup( {
        url: "/Service/Service.asmx/",
        global: false,
        dataType:"json",
        contentType:'application/json; charset=utf-8',
   		  type: "POST"
 				} );
     
String.prototype.trim = function() 
{ 
   return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
String.prototype.lengthex=function()
{
	return this.replace(/[^\x00-\xff]/g,"**").length;
	}
String.prototype.subex=function(len,ext)
{
      if (this.length<len)
      {return str;}
      else
      {
      return this.substring(0,len-3)+ext;
      }
      
}
function val(a)
{ if (typeof a!='undefined'){return a}
 	 else {return ''} 
}

 function stopEvent(e) {
    if (!e) e = window.event;
    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
   }
 
function Void(){} 
function subscript()
{
    var url=window.document.getElementById("tb_url").value.trim();
    if ((url=="") || (url==keywordTip)){
        alert(gMsg.pleaseinput);
    }else{
        location.href="/search?q="+encodeURI(url);
    }
}

function subUrlKeyDown(e)
{
var key=e.keyCode?e.keyCode:e.charCode;
if(key==13){subscript();e.returnValue=false}
}

function focusKeyword() {
    var keyword = document.getElementById("tb_url");
    if (keyword.value == keywordTip) {
        keyword.value = "";
        keyword.style.color="#000000"
    }
}
function blurKeyword() {
    var keyword = document.getElementById("tb_url");
    if (keyword.value == "") {
        keyword.value = keywordTip;
        keyword.style.color="#B8B8B8"
    }
}

function doKeyEnter(e,f)
{
 var key=e.keyCode?e.keyCode:e.charCode;
 if(key==13){
 f();
 e.returnValue=false;
 return false;
 }
 
}

//jQuery extend
//josn
(function ($) {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            'array': function (x) {
                var a = ['['], b, f, i, l = x.length, v;
                for (i = 0; i < l; i += 1) {
                    v = x[i];
                    f = s[typeof v];
                    if (f) {
                        v = f(v);
                        if (typeof v == 'string') {
                            if (b) {
                                a[a.length] = ',';
                            }
                            a[a.length] = v;
                            b = true;
                        }
                    }
                }
                a[a.length] = ']';
                return a.join('');
            },
            'boolean': function (x) {
                return String(x);
            },
            'null': function (x) {
                return "null";
            },
            'number': function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            'object': function (x) {
                if (x) {
                    if (x instanceof Array) {
                        return s.array(x);
                    }
                    var a = ['{'], b, f, i, v;
                    for (i in x) {
                        v = x[i];
                        f = s[typeof v];
                        if (f) {
                            v = f(v);
                            if (typeof v == 'string') {
                                if (b) {
                                    a[a.length] = ',';
                                }
                                a.push(s.string(i), ':', v);
                                b = true;
                            }
                        }
                    }
                    a[a.length] = '}';
                    return a.join('');
                }
                return 'null';
            },
            'string': function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            }
        };

	$.toJSON = function(v) {
		var f = isNaN(v) ? s[typeof v] : s['number'];
		if (f) return f(v);
	};
	
	$.parseJSON = function(v, safe) {
		if (safe === undefined) safe = $.parseJSON.safe;
		if (safe && !/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
			return undefined;
		return eval('('+v+')');
	};
	
	$.parseJSON.safe = false;

})(jQuery);

$.postJOSN=function(url, data, callback )
{ 
	
	return $.post(url, $.toJSON(data),function(ret){callback($.parseJSON(ret,true)); });
	 }
/*get*/
$.get=function(name){return document.getElementById(name);}	 
/*
 * DOM node creation for jQuery.
 *
 * Author  :  Sean Gilbertson
 * Created :  2006-01-04
 *
 */

$.create = function() {
	if (arguments.length == 0) {
		return [];
	}
	
	var first_arg = arguments[0];

	/*
	 * In case someone passes in a null object,
	 * assume that they want an empty string.
	 */
	if (first_arg == null) {
		first_arg = "";
	}

	if (first_arg.constructor == String) {
		if (arguments.length > 1) {
			var second_arg = arguments[1];
			
			if (second_arg.constructor == String) {
				var elt = document.createTextNode(first_arg);
				
				var elts = [];
				
				elts.push(elt);

				var siblings = $.create.apply(null, Array.prototype.slice.call(arguments, 1));

				elts = elts.concat(siblings);
				
				return elts;
			} else {
				var elt = document.createElement(first_arg);
				
				/*
				 * Set element attributes.
				 */
				var attributes = arguments[1];

				for (var attr in attributes) {
					$(elt).attr(attr, attributes[attr]);
				}
		
				/*
				 * Add children of this element.
				 */
				var children = arguments[2];

				children = $.create.apply(null, children);

				$(elt).append(children);
		
				/*
				 * If there are more siblings, render those too.
				 */
				if (arguments.length > 3) {
					var siblings = $.create.apply(null, Array.prototype.slice.call(arguments, 3));
					
					return [elt].concat(siblings);
				}
		
				return elt;
			}
		} else {
			return document.createTextNode(first_arg);
		}
	}	else {
		var elts = [];
		
		elts.push(first_arg);

		var siblings = $.create.apply(null, (Array.prototype.slice.call(arguments, 1)));
				
		elts = elts.concat(siblings);
		
		return elts;
	}
}

function Hash()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
   
	this.removeItem = function(in_key)
	{
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}
	   
		return tmp_value;
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value)
	{
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}

			this.items[in_key] = in_value;
		}
	   
		return in_value;
	}

	this.hasItem = function(in_key)
	{
		return typeof(this.items[in_key]) != 'undefined';
	}
}

