﻿function ResizeWindow()
{
    if (document.body.clientWidth==0) return;
    
    var header = document.getElementById("header");
    var mainSection = document.getElementById("mainSection");
    
    if (mainSection == null) return;
    
    document.body.scroll = "no";
    mainSection.style.overflow = "auto";
    header.style.width = document.body.offsetWidth - 2;
    mainSection.style.width = document.body.offsetWidth - 2;
    mainSection.style.top = 0;  

    mainSection.style.height = document.documentElement.clientHeight - header.offsetHeight;
}

function IsGreaterThanZero(val)
{
    if (isNaN(val))
    {
        return false;
    }
    else
    {
        if (val <= 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}

function IsGreaterThaneQualZero(val)
{
    if (isNaN(val))
    {
        return false;
    }
    else
    {
        if (val < 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}

function Copy()
{
    fnSelect("DataGridList");
}

function Copy2()
{
    fnSelect("mainBody");
}

function Copy3()
{
    fnSelect("DataGridList2");
}

function fnSelect(objId)
{
    fnDeSelect();
    if (document.selection) 
    {
        var range = document.body.createTextRange();
        range.moveToElementText(document.getElementById(objId));
        range.select();
        range.execCommand("Copy");
    }
    else if (window.getSelection) 
    {
        var range = document.createRange();
        range.selectNode(document.getElementById(objId));
        window.getSelection().addRange(range);
    }
}


function fnDeSelect() 
{
    if (document.selection)
        document.selection.empty();
    else if (window.getSelection)
        window.getSelection().removeAllRanges();
}

function load()
{
	window.location.reload();
}

function IsMobilePhone(mobilePhone)
{
    reg=/^1\d{10}$/gi;

    if(!reg.test(mobilePhone))
    {
       return false; 
    }   
    else
    {
        return true;
    }
}

function FormatDate(str)
{
    var d = new Date(str);   
  
    var d = d.format("yyyy-MM-dd");   
  
    return d;
}


function FormatDateTime(str)
{
    var d = new Date(str);   
  
    var d = d.format("yyyy-MM-dd hh:mm:ss");   
  
    return d;
}

function FormatDateTime2(str)
{
    var d = new Date(str);   
  
    var d = d.format("hh:mm");   
  
    return d;
}

Date.prototype.format = function(format){   
 var o = {   
  "M+" :  this.getMonth()+1,
  "d+" :  this.getDate(), 
  "h+" :  this.getHours(),
      "m+" :  this.getMinutes(),
      "s+" :  this.getSeconds(),
      "q+" :  Math.floor((this.getMonth()+3)/3),
      "S"  :  this.getMilliseconds() 
   }   
    
   if(/(y+)/.test(format)) {   
    format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
   }   
    
   for(var k in o) {   
    if(new RegExp("("+ k +")").test(format)) {   
      format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));   
    }   
   }   
 return format;   
}  

function GetCurrentDate()
{
        var tempdate = new Date();
        
        var nYear = tempdate.getFullYear();
        var nMonth = tempdate.getMonth()+1;
        var nDay = tempdate.getDate();
        return nYear + "-" + nMonth + "-" + nDay;
}

function GetKeyPressNumber(keycode)
{
    if ((parseInt(keycode) >= 96 && parseInt(keycode) <= 105) || (parseInt(keycode) >= 48 && parseInt(keycode) <= 57))
    {
        if (parseInt(keycode) >= 96)
        {
            return (parseInt(keycode) - 96);
        }
        return (parseInt(keycode) - 48);
    }
    
    return;
}

function SelectedRow(obj)
{
    obj.runtimeStyle.backgroundColor = "HIGHLIGHT";
	obj.runtimeStyle.color = "HIGHLIGHTTEXT";
}

function UnSelectedRow(obj)
{
    obj.runtimeStyle.backgroundColor = "";
	obj.runtimeStyle.color = "";
}

function SelectedRow2(cssName)
{
    $("tr." + cssName).mousemove(function() {    
        this.runtimeStyle.backgroundColor = "HIGHLIGHT";
		this.runtimeStyle.color = "HIGHLIGHTTEXT";
		
		for(var i=0; i < $("tr." + cssName).eq(this.rowIndex-1).children("td").children("a").length; i++)
		{
		    obj = $("tr." + cssName).eq(this.rowIndex-1).children("td").children("a").get(i); 
		    obj.runtimeStyle.color = "HIGHLIGHTTEXT";
		}
		for(var i=0; i < $("tr." + cssName).eq(this.rowIndex-1).children("td").children("div").length; i++)
		{
		    obj = $("tr." + cssName).eq(this.rowIndex-1).children("td").children("div").get(i); 
		    obj.runtimeStyle.color = "HIGHLIGHTTEXT";
		}
    });
    
    $("tr." + cssName).mouseout(function() {
        this.runtimeStyle.backgroundColor = "";
		this.runtimeStyle.color = "";
		
		for(var i=0; i < $("tr." + cssName).eq(this.rowIndex-1).children("td").children("a").length; i++)
		{
		    obj = $("tr." + cssName).eq(this.rowIndex-1).children("td").children("a").get(i); 
		    obj.runtimeStyle.color = "";
		}
		for(var i=0; i < $("tr." + cssName).eq(this.rowIndex-1).children("td").children("div").length; i++)
		{
		    obj = $("tr." + cssName).eq(this.rowIndex-1).children("td").children("div").get(i); 
		    obj.runtimeStyle.color = "";
		}

	});
}
