function setCookie( name, value, expiredays )
{
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + '=' + escape( value ) + '; domain=' + location.hostname + ';path=/; expires=' + todayDate.toGMTString() + ';';
}

function getCookie( name )
{
    var nameOfCookie = name + '=';
    var x = 0;
    while ( x <= document.cookie.length )
    {
        var y = (x+nameOfCookie.length);
        if ( document.cookie.substring( x, y ) == nameOfCookie )
        {
            if ( (endOfCookie=document.cookie.indexOf( ';', y )) == -1 )
                endOfCookie = document.cookie.length;
            return unescape( document.cookie.substring( y, endOfCookie ) );
        }
        x = document.cookie.indexOf( ' ', x ) + 1;
        if ( x == 0 )
            break;
    }
    return '';
}


function fnCut(str,lengths)
{
    var len = 0;
    var newStr = '';

    for (var i=0;i<str.length; i++){
        var n = str.charCodeAt(i);
        var nv = str.charAt(i);

        if(n < 128){
            len++;
        }
        else if(n < 2048){
		    len +=2;
        }
        else if(n < 65536){
		    len +=3;
        }
        else{
		    len +=4;
	    }

        if (len>lengths) break;
        else newStr = newStr + nv;
    }
    return newStr;
}

function getBytes(sString) {
	var c = 0;
	for(var i= 0; i <sString.length;i++){
		c +=parseInt(getByte(sString.charAt(i)));
	}
	return c;

}

function getByte(sChar) {
	var c = 0;
	var s = parseInt(sChar.charCodeAt(0));

    if(s < 128){
        c++;
    }
    else if(s < 2048){
		c +=2;
    }
    else if(s < 65536){
		c +=3;
    }
    else{
		c +=4;
	}
	return c;
}

function checkInputBox(type, e)
{
    var unicode = e.charCode ? e.charCode : e.keyCode;

    //document.getElementById("console").innerHTML += unicode + ", ";

    if(unicode == 9)
        return true;

    if(unicode != 8 && unicode != 39 && unicode != 46)
    {
        if(type == "num")
        {
            if(unicode >= 48 && unicode <= 57)
            {
                return true;
            }
            if(unicode >= 96 && unicode <= 105)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else if(type == "ip")
        {
            if(unicode < 48 ||
               (unicode > 57 && unicode < 96) ||
               (unicode > 105 && unicode < 110) ||
               (unicode > 110 && unicode < 190) ||
               unicode > 190)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        else if(type == "alnum")
        {
            if(unicode < 48 ||
               (unicode > 57 && unicode < 65) ||
               (unicode > 90 && unicode < 96) ||
               (unicode > 107 && unicode < 109) ||
               (unicode > 111 && unicode < 186) ||
               (unicode > 192 && unicode < 219) ||
               unicode > 222)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        else if(type == "webchar")
        {
            //if(unicode != 16){
            //    alert("aa"+unicode+"bb");
            //}
            if(unicode == 222 || unicode == 220)
            {
                return true;
            }
            else
            {
                return true;
            }
        }
        else
        {
            return false;
        }
    }
    else
    {
        return true;
    }
}

function isValidMulticastIP(value)
{
    var iplength = (value.split(/\./)).length;

    if(iplength == 4)
    {
        if(value.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1)
        { // ip 4
            var myArray = value.split(/\./);
            if(Number(myArray[1]) > 255 ||
               Number(myArray[2]) > 255 ||
               Number(myArray[3]) > 255)
            {
                return false;
            }

            if(Number(myArray[0]) < 224 || Number(myArray[0]) > 239)
            {
                return false;
            }

            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

function IPMaskCheck(ip, gw, sm)
{
    if((ip.split(/\./)).length == 4 && (gw.split(/\./)).length == 4 && (sm.split(/\./)).length == 4){
        var IPArray = ip.split(/\./);
        var GWArray = gw.split(/\./);
        var SMArray = sm.split(/\./);

    	for(var i= 0; i < 4; i++){
            if((Number(IPArray[i]) & Number(SMArray[i])) != (Number(GWArray[i]) & Number(SMArray[i]))){
                return false;
            }
        }
        return true;
    }
    
    return false;
}

function CheckLocalIPv4Setting(ip, gw, sm)
{
	if( ((ip.split(/\./)).length != 4) ||
		((gw.split(/\./)).length != 4) ||
	   	((sm.split(/\./)).length != 4) ) {
		return false;
	}

	if( (ip.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) == -1) ||
		(gw.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) == -1) ||
		(sm.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) == -1) ) {
		return false;
	}

	var ipArray = ip.split(/\./);
	var gwArray = gw.split(/\./);
	var smArray = sm.split(/\./);

	// check ip
	if(Number(ipArray[0] >= 224)) {
		return false;
	}

	var ip2 = ((Number(ipArray[0]) << 24) + (Number(ipArray[1]) << 16) + (Number(ipArray[2]) << 8) + (Number(ipArray[3]))) >>> 0;
	var gw2 = ((Number(gwArray[0]) << 24) + (Number(gwArray[1]) << 16) + (Number(gwArray[2]) << 8) + (Number(gwArray[3]))) >>> 0;
	var sm2 = ((Number(smArray[0]) << 24) + (Number(smArray[1]) << 16) + (Number(smArray[2]) << 8) + (Number(smArray[3]))) >>> 0;

	// check subnetmask 
	if(sm2 == 0) {
		return false;
	} else {
		for(var i = 31; i >= 0; i--) {
			if(((sm2 >>> i) & 0x1) == 0) {
				for(var j = i; j >= 0; j--) {
					if(((sm2 >>> j) & 0x1) != 0) {
						return false;
					}
				}
			}
		}
	}

	// check gateway
	var networkip, broadcastip;
	networkip = (ip2 & sm2) >>> 0;
	broadcastip = (networkip | (~sm2)) >>> 0;
	if((gw2 == ip2) || (gw2 == networkip) || (gw2 == broadcastip)) {
		return false;
	}

	return true;
}

function isValidIP(value)
{
    var iplength = (value.split(/\./)).length;

    if(iplength == 4)
    {
        if(value.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1)
        { // ip 4
            var myArray = value.split(/\./);
            if(Number(myArray[0]) > 255 ||
               Number(myArray[1]) > 255 ||
               Number(myArray[2]) > 255 ||
               Number(myArray[3]) > 255)
            {
                return false;
            }

            if(Number(myArray[0]) == 0 &&
               Number(myArray[1]) == 0 &&
               Number(myArray[2]) == 0 &&
               Number(myArray[3]) == 0)
            {
                return true;
            }

            return true;
        }
        else
        {
            return false;
        }
    }
    else if(iplength == 6)
    {
        if(value.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}$/) != -1)
        { // ip 6
            var myArray2 = value.split(/\./);
            //alert(myArray2);
            if(Number(myArray2[0]) > 255 ||
               Number(myArray2[1]) > 255 ||
               Number(myArray2[2]) > 255 ||
               Number(myArray2[3]) > 255 ||
               Number(myArray2[4]) > 255 ||
               Number(myArray2[5]) > 255)
            {
                return false;
            }

            if(Number(myArray2[0]) == 0 &&
               Number(myArray2[1]) == 0 &&
               Number(myArray2[2]) == 0 &&
               Number(myArray2[3]) == 0 &&
               Number(myArray2[4]) == 0 &&
               Number(myArray2[5]) == 0)
            {
                return false;
            }

            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

alpha_numeric = new String("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

function check_alphanumber(str)
{
        if(str.length == 0){
            return false;
        }
        for(j = 0 ; j < str.length; j++)
        {
                rtn = is_alpha_numeric(str.charAt(j));
                if(rtn == false)
                {
                        return rtn;
                }
        }
        return true;
}

function is_alpha_numeric(cha1)
{
        for(i=0;i<alpha_numeric.length;i++)
        {
                if(alpha_numeric.charAt(i) == cha1)
                        return true;
        }
        return false;
}

function IsAlpha(c)
{
        if (c >= '0' && c <= '9')
                return 1;
        if (c >= 'a' && c <= 'z')
                return 1;
        if (c >= 'A' && c <= 'Z')
                return 1;
        else return 0;
}

network_address = new String("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-")

function check_network_address(str)
{
        if(str.length == 0){
            return false;
        }
        if(str.length == 1){
            return false;
        }
        if(is_alpha_numeric(str.charAt(0)) == false){
            return false;
        }
        for(j = 1 ; j < str.length; j++)
        {
                rtn = is_network_address(str.charAt(j));
                if(rtn == false)
                {
                        return rtn;
                }
        }
        return true;
}

function is_network_address(cha1)
{
        for(i=0;i<network_address.length;i++)
        {
                if(network_address.charAt(i) == cha1)
                        return true;
        }
        return false;
}

password_string = new String("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+|-\\`~[]{},./:;\"\'")

function check_password(str)
{
        if(str.length == 0){
            return false;
        }
        if(str.length == 1){
            return false;
        }
        for(j = 0 ; j < str.length; j++)
        {
                rtn = is_password_string(str.charAt(j));
                if(rtn == false)
                {
                    alert("Password string cannot contain \'" + str.charAt(j) + "\'");
                        return rtn;
                }
        }
        return true;
}

function is_password_string(cha1)
{
        for(i=0;i<password_string.length;i++)
        {
                if(password_string.charAt(i) == cha1)
                        return true;
        }
        return false;
}

password_special_char = new String("!@#$%^&*()_+|-\\`~[]{},./:;\"\'")

function check_password_special_char(str)
{
        if(str.length == 0){
            return false;
        }
        if(str.length == 1){
            return false;
        }
        for(j = 0 ; j < str.length; j++)
        {
                rtn = is_password_special_char_string(str.charAt(j));
                if(rtn == true)
                {
                        return rtn;
                }
        }
        return false;
}

function is_password_special_char_string(cha1)
{
        for(i=0;i<password_special_char.length;i++)
        {
                if(password_special_char.charAt(i) == cha1)
                        return true;
        }
        return false;
}

function check_password_len(str, min_len)
{
	if(str.length < min_len) {
		return false;
	}
	return true;
}

function check_password_char_type_num(str, min_num)
{
	var num = -1, upper = -1, lower = -1, special = -1;
	var type_count = 0;

	if((num = str.search(/[0-9]/g)) != -1) {
		type_count++;
	}

	if((upper = str.search(/[A-Z]/g)) != -1) {
		type_count++;
	}

	if((lower = str.search(/[a-z]/g)) != -1) {
		type_count++;
	}

	for(j = 0; j < str.length; j++) {
		if(is_password_special_char_string(str.charAt(j))) {
			special = j;
			type_count++;
			break;
		}
	}

	//console.log(num + ", " + upper + ", " + lower + ", " + special + ", " + min_num);
	if(type_count < min_num) {
		return false;
	}

	return true;
}

function Tencryption(s) {
  var key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

  var i = 0, len = s.length,
      c1, c2, c3,
      e1, e2, e3, e4,
      result = [];
 
  while (i < len) {
    c1 = s.charCodeAt(i++);
    c2 = s.charCodeAt(i++);
    c3 = s.charCodeAt(i++);
   
    e1 = c1 >> 2;
    e2 = ((c1 & 3) << 4) | (c2 >> 4);
    e3 = ((c2 & 15) << 2) | (c3 >> 6);
    e4 = c3 & 63;
   
    if (isNaN(c2)) {
      e3 = e4 = 64;
    } else if (isNaN(c3)) {
      e4 = 64;
    }
   
    result.push(e1, e2, e3, e4);
  }
 
	return jQuery.map(result, function (e) { return key.charAt(e); }).join('');
}

function TEncodeUrl(str){
//    return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
    var pass = str.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
    var ln = pass.length;
    return str.substr(ln-1,1) + str.substr(ln/2,1) + pass;
}

function macro_16(length)
{
	return ((length+0xF) & ~(0xF))/16;
}

function getperformance_macroblock(res, fps)
{
	var m_width = 0;
	var m_height = 0;
	var weight = 0;

	switch(res) {
		case 0: //720x480
			m_width = macro_16(720);
			m_height = macro_16(480);
			break;
		case 1: //720x240
			m_width = macro_16(720);
			m_height = macro_16(240);
			break;
		case 2: //352x480
			m_width = macro_16(352);
			m_height = macro_16(480);
			break;
		case 3: //352x240
			m_width = macro_16(352);
			m_height = macro_16(240);
			break;
		case 4: //720x576
			m_width = macro_16(720);
			m_height = macro_16(576);
			break;
		case 5: //720x288
			m_width = macro_16(720);
			m_height = macro_16(288);
			break;
		case 6: //352x576
			m_width = macro_16(352);
			m_height = macro_16(576);
			break;
		case 7: //352x288
			m_width = macro_16(352);
			m_height = macro_16(288);
			break;
		case 8: //640x480
			m_width = macro_16(640);
			m_height = macro_16(480);
			break;
		case 9: //800x600
			m_width = macro_16(800);
			m_height = macro_16(600);
			break;
		case 10: //1024x768
			m_width = macro_16(1024);
			m_height = macro_16(768);
			break;
		case 11: //1280x960
			m_width = macro_16(1280);
			m_height = macro_16(960);
			break;
		case 12: //1280x1024
			m_width = macro_16(1280);
			m_height = macro_16(1024);
			break;
		case 13: //1440x900
			m_width = macro_16(1440);
			m_height = macro_16(900);
			break;
		case 14: //1600x900
			m_width = macro_16(1600);
			m_height = macro_16(900);
			break;
		case 15: //1680x1050
			m_width = macro_16(1680);
			m_height = macro_16(1050);
			break;
		case 16: //1280x720
			m_width = macro_16(1280);
			m_height = macro_16(720);
			break;
		case 17: //1920x1080
			m_width = macro_16(1920);
			m_height = macro_16(1080);
			break;
		case 18: //176x128
			m_width = macro_16(176);
			m_height = macro_16(128);
			break;
		case 19: //176x144
			m_width = macro_16(176);
			m_height = macro_16(144);
			break;
		case 22: //320x240
			m_width = macro_16(320);
			m_height = macro_16(240);
			break;
		case 23: //2048x1536
			m_width = macro_16(2048);
			m_height = macro_16(1536);
			break;
		case 24: //2560x1600
			m_width = macro_16(2560);
			m_height = macro_16(1600);
			break;
		case 25: //2592x1936
			m_width = macro_16(2592);
			m_height = macro_16(1936);
			break;
		case 26: //1920x1056
			m_width = macro_16(1920);
			m_height = macro_16(1056);
			break;
		case 27: //640x360
			m_width = macro_16(640);
			m_height = macro_16(360);
			break;
		case 28: //1440x540
			m_width = macro_16(1440);
			m_height = macro_16(540);
			break;
		case 29: //1792x1344
			m_width = macro_16(1792);
			m_height = macro_16(1344);
			break;
		case 30: //1440x1080
			m_width = macro_16(1440);
			m_height = macro_16(1080);
			break;
		case 47: //1600x1200
			m_width = macro_16(1600);
			m_height = macro_16(1200);
			break;
		case 48: //1920x1200
			m_width = macro_16(1920);
			m_height = macro_16(1200);
			break;
		case 49: //704x480
			m_width = macro_16(704);
			m_height = macro_16(480);
			break;
		case 50: //3840x2160
			m_width = macro_16(3840);
			m_height = macro_16(2160);
			break;
		case 51: //4096x2160
			m_width = macro_16(4096);
			m_height = macro_16(2160);
			break;
		case 52: //4000x3000
			m_width = macro_16(4000);
			m_height = macro_16(3000);
			break;
		case 53: //1280x768
			m_width = macro_16(1280);
			m_height = macro_16(768);
			break;
		case 54: //1152x864
			m_width = macro_16(1152);
			m_height = macro_16(864);
			break;
		case 55: //1360x768
			m_width = macro_16(1360);
			m_height = macro_16(768);
			break;
		case 56: //1400x1050
			m_width = macro_16(1400);
			m_height = macro_16(1050);
			break;
		case 57: //2048x2048
			m_width = macro_16(2048);
			m_height = macro_16(2048);
			break;
		case 58: //2592x1944
			m_width = macro_16(2592);
			m_height = macro_16(1944);
			break;
		case 59: //960x540
			m_width = macro_16(960);
			m_height = macro_16(540);
			break;
		case 60: //768x432
			m_width = macro_16(768);
			m_height = macro_16(432);
			break;
        case 67: //1080x1920
            m_width = macro_16(1080);
            m_height = macro_16(1920);
            break;
        case 68: //720x1280
            m_width = macro_16(720);
            m_height = macro_16(1280);
            break;
        case 69: //360x640
            m_width = macro_16(360);
            m_height = macro_16(640);
            break;
        case 70: //1944X2592
            m_width = macro_16(1944);
            m_height = macro_16(2592);
            break;
        case 71: //1600X2560
            m_width = macro_16(1600);
            m_height = macro_16(2560);
            break;
        case 72: //1536X2048
            m_width = macro_16(1536);
            m_height = macro_16(2048);
            break;
        case 73: //1366X768
            m_width = macro_16(1366);
            m_height = macro_16(768);
            break;
        case 74: //2560X1440
            m_width = macro_16(2560);
            m_height = macro_16(1440);
            break;
        case 75: //800X448
            m_width = macro_16(800);
            m_height = macro_16(448);
            break;
        case 77: //3200x1800
            m_width = macro_16(3200);
            m_height = macro_16(1800);
            break;            
        case 78: //3072x1728
            m_width = macro_16(3072);
            m_height = macro_16(1728);
            break;            
        case 81: //2160x3840
            m_width = macro_16(2160);
            m_height = macro_16(3840);
            break;
        case 82: //1296x2304
            m_width = macro_16(1296);
            m_height = macro_16(2304);
            break;
        case 83: //1808x3200
            m_width = macro_16(1808);
            m_height = macro_16(3200);
            break;
        case 84: //1728x3072
            m_width = macro_16(1728);
            m_height = macro_16(3072);
            break;
		default:
			m_width = macro_16(720);
			m_height = macro_16(480);
			break;
	}

    switch(fps){
    case 0 : 
        weight = 30;
        break;
    case 1 : 
        weight = 25;
        break;
    case 2 : 
        weight = 20;
        break;
    case 3 : 
        weight = 15;
        break;
    case 4 : 
        weight = 10;
        break;
    case 5 : 
        weight = 8;
        break;
    case 6 : 
        weight = 6;
        break;
    case 7 : 
        weight = 5;
        break;
    case 8 : 
        weight = 4;
        break;
    case 9 : 
        weight = 3;
        break;
    case 10 : 
        weight = 2;
        break;
    case 11 : 
        weight = 1;
        break;
    case 150 : 
        weight = 50;
        break;
    case 160 : 
        weight = 60;
        break;

    case 175: 
        weight = 75;
        break;

    case 185: 
        weight = 85;
        break;
    }

	return (m_width*m_height*weight);
}

function getperformance_res(res) {
    var weight1 = 0;

    switch(res){
    case 2 : 
    case 3 : 
    case 6 : 
    case 7 : 
    case 22 : 
        weight1 = 2;
        break;
    case 0 : 
    case 1 : 
    case 4 : 
    case 5 : 
    case 8 : 
    case 18 : 
    case 19 : 
    case 27 : 
	case 49 :
	case 60 :
    case 69 :
    case 80 :
            weight1 = 4;
        break;
    case 9 : 
    case 10 : 
    case 16 : 
	case 28 :
	case 54 :
	case 59 :
    case 68 :
    case 75 :
        weight1 = 10;
        break;
	case 53 :
        weight1 = 12;
		break;
    case 12 : 
		weight1 = 14;
		break;
    case 30 : 
		weight1 = 15;
		break;
    case 11 : 
    case 13 : 
    case 14 : 
    case 15 : 
    case 17 : 
	case 26 :
	case 30 :
	case 47 :
	case 48 :
	case 55 :
	case 56 :
    case 67 :
	case 73 :
    case 79 :
        weight1 = 20;
        break;
	case 29 :
        weight1 = 25;
        break;
    case 23 :     
    case 76 : 
	case 82 : //1296x2304
        weight1 = 30;
        break;    
    case 74 : //2560X1440
        weight1 = 35;
        break;
	case 24:
	case 57:
		weight1 = 40;
		break;
	case 25:
	case 58: // 2592x1944
        weight1 = 50;
        break;
    case 77: //3200x1800
	case 83: //1808x3200
        weight1 = 57;
        break;
    case 78: //3072x1728
    case 84: //1728x3072
        weight1 = 53;
        break;
	case 50: //3840x2160
    case 81: //2160x3840
		weight1 = 80;
		break;
	case 51:
		weight1 = 85;
		break;
	case 52:
		weight1 = 120;
		break;
	default:
		weight1 = 20;
		break;
    }
    
    return weight1;

}

function getperformance_fps(fps) {
    var weight2 = 0;

    switch(fps){
    case 0 : 
        weight2 = 30;
        break;
    case 1 : 
        weight2 = 25;
        break;
    case 2 : 
        weight2 = 20;
        break;
    case 3 : 
        weight2 = 15;
        break;
    case 4 : 
        weight2 = 10;
        break;
    case 5 : 
        weight2 = 8;
        break;
    case 6 : 
        weight2 = 6;
        break;
    case 7 : 
        weight2 = 5;
        break;
    case 8 : 
        weight2 = 4;
        break;
    case 9 : 
        weight2 = 3;
        break;
    case 10 : 
        weight2 = 2;
        break;
    case 11 : 
        weight2 = 1;
        break;
    case 150 : 
        weight2 = 50;
        break;
    case 160 : 
        weight2 = 60;
        break;

    case 175: 
        weight2 = 75;
        break;

    case 185: 
        weight2 = 85;
        break;
    }
    
    return weight2;

}

function getperformance(res, fps, _force_4k_calculation)
{
    var weight1 = 0;
    var weight2 = 0;

    switch(res){
    case 0 : 
    case 1 : 
    case 2 : 
    case 3 : 
    case 4 : 
    case 5 : 
    case 6 : 
    case 7 : 
    case 8 : 
    case 18 : 
    case 19 : 
    case 22 : 
    case 27 : 
	case 49 :
	case 60 :
    case 69 :
    case 80 :
            weight1 = 4;
        break;
    case 9 : 
    case 10 : 
    case 16 : 
	case 28 :
	case 54 :
	case 59 :
    case 68 :
    case 75 :
        weight1 = 10;
        break;
	case 53 :
        weight1 = 12;
		break;
    case 30 : 
		weight1 = 15;
		break;
    case 11 : 
    case 12 : 
    case 13 : 
    case 14 : 
    case 15 : 
    case 17 : 
	case 26 :
	case 30 :
	case 47 :
	case 48 :
	case 55 :
	case 56 :
    case 67 :
	case 73 :
    case 79 :
            weight1 = 20;
        break;
	case 29 :
        weight1 = 25;
        break;
    case 23 :     
    case 76 : 
	case 82 : //1296x2304
        weight1 = 30;
        break;    
    case 74 : //2560X1440
        if(_force_4k_calculation)  {
            weight1 = 80;
        }
        else {
            weight1 = 35;
        }        
        break;
	case 24:
	case 57:
		weight1 = 40;
		break;
	case 25:
	case 58: // 2592x1944
        if(_force_4k_calculation)  {
            weight1 = 80;
        }
        else {
            weight1 = 50;
        }		
        break;
    case 77: //3200x1800
	case 83: //1808x3200
        if(_force_4k_calculation)  {
            weight1 = 80;
        }
        else {
            weight1 = 57;
        }        
        break;
    case 78: //3072x1728
    case 84: //1728x3072
        if(_force_4k_calculation)  {
            weight1 = 80;
        }
        else {
            weight1 = 53;
        }
        break;
	case 50: //3840x2160
    case 81: //2160x3840
		weight1 = 80;
		break;
	case 51:
		weight1 = 85;
		break;
	case 52:
		weight1 = 120;
		break;
	default:
		weight1 = 20;
		break;
    }

    switch(fps){
    case 0 : 
        weight2 = 30;
        break;
    case 1 : 
        weight2 = 25;
        break;
    case 2 : 
        weight2 = 20;
        break;
    case 3 : 
        weight2 = 15;
        break;
    case 4 : 
        weight2 = 10;
        break;
    case 5 : 
        weight2 = 8;
        break;
    case 6 : 
        weight2 = 6;
        break;
    case 7 : 
        weight2 = 5;
        break;
    case 8 : 
        weight2 = 4;
        break;
    case 9 : 
        weight2 = 3;
        break;
    case 10 : 
        weight2 = 2;
        break;
    case 11 : 
        weight2 = 1;
        break;
    case 150 : 
        weight2 = 50;
        break;
    case 160 : 
        weight2 = 60;
        break;

    case 175: 
        weight2 = 75;
        break;

    case 185: 
        weight2 = 85;
        break;
    }
    
    return (weight1*weight2);
}

function DBG(str)
{
	if(window.console == undefined) {
		console = { log : function() {} };
	}

	console.log(str);
}


function getwidth(res,real)
{
    if(real) {
        switch(res) {
            case 0:
                return 720 ; // 720x480
            case 1:
                return 720 ; // 720x240
            case 2:
                return 352; // 352x480
            case 3:
                return 352; // 352x240
            case 4:
                return 720; // 720x576
            case 5:
                return 720; // 720x288
            case 6:
                return 352; // 352x576
            case 7:
                return 352; // 352x288
            case 8:
                return 640; // 640x480
            case 18:
                return 176; // 176x128
            case 19:
                return 176; // 176x144
            case 22:
                return 320; // 320x240
        };
    }
 
    switch(res){
    case 0 : 
    case 1 : 
    case 2 : 
    case 3 : 
    case 18 : 
        return 720;
    case 4 : 
    case 5 : 
    case 6 : 
    case 7 : 
    case 19 : 
        return 720;
    case 8 : 
        return 640;
    case 9 : 
        return 800;
    case 10 : 
        return 1024;
    case 11 : 
        return 1280;
    case 12 : 
        return 1280;
    case 13 : 
        return 1440;
    case 14 : 
        return 1600;
    case 15 : 
        return 1680;
    case 16 : 
        return 1280;
    case 17 : 
        return 1920;
    case 23 : 
        return 2048;
    case 26 : 
        return 1920;
    case 24 : 
        return 2560;
    case 25 : 
        return 2592;
    case 27 : 
        return 640;
    case 28 : 
        return 1440;
    case 29 : 
        return 1792;
	case 30 :
        return 1440;
	case 47:
		return 1600;
	case 48:
		return 1920;
	case 50:
		return 3840;
	case 51:
		return 4096;
	case 52:
		return 4000;
	case 53:
		return 1280;
	case 54:
		return 1152;
	case 55:
		return 1360;
	case 56:
		return 1400;
    case 57:
        return 2048;
	case 58:
        return 2592;
    case 59:
        return 960;
    case 60:
        return 768;
    case 66:
        return 960;
    case 67:
        return 1080;
    case 68:
        return 720;
    case 69:
        return 360;
	case 70:
		return 1944;
	case 71:
		return 1600;
	case 72:
		return 1536;
	case 73:
		return 1366;
	case 74:
        return 2560;
    case 76:
		return 2304;
    case 77:
        return 3200;
    case 78:
        return 3072;      
    case 79:
        return 1088;        
    case 80:
        return 368;        
    case 81:
        return 2160;
    case 82:
        return 1296;
    case 83:
        return 1808;
    case 84:
        return 1728;
    default :
        return 720;
    }

}

function getheight(res,real)
{
    if(real) {
        switch(res) {
            case 0:
                return 480 ; // 720x480
            case 1:
                return 240 ; // 720x240
            case 2:
                return 480; // 352x480
            case 3:
                return 240; // 352x240
            case 4:
                return 576; // 720x576
            case 5:
                return 288; // 720x288
            case 6:
                return 576; // 352x576
            case 7:
                return 288; // 352x288
            case 8:
                return 480; // 640x480
            case 18:
                return 128; // 176x128
            case 19:
                return 144; // 176x144
            case 22:
                return 240; // 320x240
        };
    }
    switch(res){
    case 0 : 
    case 1 :
    case 2 : 
    case 3 :
    case 8 : 
    case 18 : 
        return 480;
    case 4 : 
    case 5 : 
    case 6 : 
    case 7 : 
    case 19 : 
        return 576;
    case 9 : 
        return 600;
    case 10 : 
        return 768;
    case 11 : 
        return 960;
    case 12 : 
        return 1024;
    case 13 : 
        return 900;
    case 14 : 
        return 900;
    case 15 : 
        return 1050;
    case 16 : 
        return 720;
    case 17 : 
        return 1080;
    case 23 : 
        return 1536;
    case 26 : 
        return 1056;
    case 24 : 
        return 1600;
    case 25 : 
        return 1936;
    case 27 : 
        return 360;
    case 28 : 
        return 540;
    case 29 : 
        return 1344;
	case 30:
		return 1080;
	case 47:
	case 48:
		return 1200;
	case 50:
		return 2160;
	case 51:
		return 2160;
	case 52:
		return 3000;
	case 53:
		return 768;
	case 54:
		return 864;
	case 55:
		return 768;
	case 56:
		return 1050;
	case 57:
		return 2048;
	case 58:
        return 1944;
    case 59:
        return 540;
    case 60:
        return 432;
    case 66:
        return 600;
    case 67:
        return 1920;
    case 68:
        return 1280;
    case 69:
        return 640;
	case 70:
		return 2592;
	case 71:
		return 2560;
	case 72:
		return 2048;
	case 73:
		return 768;
	case 74:
        return 1440;
    case 76:
        return 1296;        
    case 77:
        return 1800;
    case 78:
        return 1728;
    case 79:
        return 1920;
    case 80:
        return 640;
    case 81:
        return 3840;
    case 82:
        return 2304;
    case 83:
        return 3200;
    case 84:
        return 3072;
    default :
        return 360;
    }

}


