﻿function getClientWidth()
{
    var mywidth = 0;
    
    if(typeof(window.innerWidth)=='number')
    {
        //non-IE
        mywidth = window.innerWidth;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+
        mywidth = document.documentElement.clientWidth;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4
        mywidth = document.body.clientWidth;
    }
    
    return mywidth;
}

function getClientHeight()
{
    var myheight = 0;
    
    if(typeof(window.innerWidth)=='number')
    {
        //non-IE
        myheight = window.innerHeight;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+
        myheight = document.documentElement.clientHeight;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4
        myheight = document.body.clientHeight;
    }
    
    return myheight;
}

////change css class
//function changecss(obj, stat)
//{
//    if(stat == 1)
//    {
//        obj.className = obj.className + '_h';
//    }
//    else
//    {
//        obj.className = obj.className.substr(0, obj.className.indexOf('_'));
//    }
//}

/* Redirect to page */
function ls(loc)
{
	window.location = loc;
}

/* Only Numeric */
function OnlyInteger(obj, event)
{
    if(event.keyCode != 13)
    {
        var kcode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    
        var curChar    = String.fromCharCode( kcode ); 
        var inpStr     = obj.value + curChar 
        
        window.status  = '';
        obj.title      = '';

        var ua = navigator.userAgent.toLowerCase();
        var exp = "^[0-9-]+$";

        if(ua.indexOf("mozilla") != -1 && ua.indexOf("ie") == -1)
        {
            var regex = new RegExp(exp);
            result = regex.test(inpStr);
        }
        else if(ua.indexOf("ie") != -1)
        {
            result = inpStr.match( exp );
        }

        //result = inpStr.match( '^[0-9-]+$' );
        if ( ! result ) 
        {
            window.status     = 'Only digit allowed';
            obj.title         = window.status;
            event.returnValue = false;
            event.cancel      = true; 
        }
        else
            return true;
    }
}

/* Only float */
function OnlyFloat(obj, event)
{
    if(event.keyCode != 13)
    {
        var curChar    = String.fromCharCode( event.keyCode ); 
        var inpStr     = obj.value + curChar 
        window.status  = '';
        obj.title      = '';

        result = inpStr.match( '^[0-9.-]+$' );
        if ( ! result ) 
        {
            window.status     = 'Only float allowed';
            obj.title         = window.status;
            event.returnValue = false;
            event.cancel      = true; 
        }
    }
}

/* Only Alpha */
function OnlyAlfa(obj, event)
{
    if(event.keyCode != 13)
    {
        var curChar    = String.fromCharCode( event.keyCode ); 
        var inpStr     = obj.value + curChar 
        window.status  = '';
        obj.title      = '';

        result = inpStr.match( '^[a-zA-Z ]+$' );
        if ( ! result ) 
        {
            window.status     = 'Only alphabet allowed';
            obj.title         = window.status;
            event.returnValue = false;
            event.cancel      = true; 
        }
    }
}

/* Only AlphaNumeric */
function AlfaNumeric(obj, event)
{
    if(event.keyCode != 13)
    {
        var curChar    = String.fromCharCode( event.keyCode ); 
        var inpStr     = obj.value + curChar 
        window.status  = '';
        obj.title      = '';

        result = inpStr.match( '^[a-zA-Z0-9_. ]+$' );
        if ( ! result ) 
        {
            window.status     = 'Special characters not allowed';
            obj.title         = window.status;
            event.returnValue = false;
            event.cancel      = true; 
        }
    }
}

/* Only valid date character */
function dateChar(obj, event)
{
    if(event.keyCode != 13)
    {
        var kcode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        var curChar    = String.fromCharCode( kcode ); 
        var inpStr     = obj.value + curChar 
        window.status  = '';
        obj.title      = '';

        result = inpStr.match( '^[0-9//]+$' );
        if ( ! result ) 
        {
            obj.value = '';
            window.status     = 'Special characters not allowed';
            obj.title         = window.status;
            event.returnValue = false;
            event.cancel      = true; 
        }
    }
}



/* Text Sizer */
var tgs = new Array( 'div','td','tr');

var szs = new Array( '11px','12px','14px','16px' );
//var szs = new Array( 'small','medium' );
var startSz = 0;

function textsizer( trgt,inc ) 
{
    methods.saveTextSizerIndex(inc);
    
	if (!document.getElementById) return
	var doc = document,text = null,sz = startSz,i,j,cTags;
	
	for ( i = 0 ; i < tgs.length ; i++ ) 
	{
		cTags = document.getElementsByTagName( tgs[i] );
		for ( j = 0 ; j < cTags.length ; j++ ) 
		{
		    cTags[j].style.fontSize = szs[inc];
		}
	}
}

function getCurrentPage()
{
    var curpage = window.location;
    var cpage = new Array();
    cpage = curpage.toString().split('/');
    
    return cpage[cpage.length-1];
}



//////////////Date Validation//////////////////

function checkdate(objName) {
var datefield = objName;
if (chkdate(objName) == false) {
datefield.select();
alert("That date is invalid.  Please try again.");
datefield.focus();
datefield.value='';
return false;
}
else {
return true;
   }
}
function chkdate(objName) {
var strDatestyle = "US"; //United States date style
//var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
//var strSeparatorArray = new Array("-"," ","/",".");
var strSeparatorArray = new Array("/");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
//strTemp = strDay;
//strDay = strMonth;
//strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
//datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
datefield.value = intday + "/" + intMonth + "/" + strYear;
}
else {
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}

//check leap year
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

//check from & to
function doDateCheck(from, to) {
if (Date.parse(from.value) <= Date.parse(to.value)) {
alert("The dates are valid.");
}
else {
if (from.value == "" || to.value == "") 
alert("Both dates must be entered.");
else 
alert("To date must occur after the from date.");
   }
}

/////////////////////////////End of Date Validation///////////////////////////

function chklength(objName)
{
    if(objName.value.length<4)
    {
        alert("Please enter more than 3 characters for Barcode! ");
        objName.focus();
    }
}

function Checkspace(objName, event)
{
    if(event.keyCode != 13)
    {
        if(event.keyCode == 32)
        {
            alert("Space not Allowed in Barcode! ");
            event.returnValue = false;
            event.cancel      = true; 
            objName.focus();
        }    
    }
}

function alerts(msg)
{
    alert(msg);
}

function pagehelp(h)
{
    resizereinit=true;
    menu[1] = {
    id:'menu3',
    bartext:'<img src=../images/help_button.jpg>',
    //bartext:'HELP',
    menupos:'right',
    kviewtype:'absolute',
    //kviewtype:'fixed',
    allowtransparent:true, 
    menuItems:[[h]]
    };

    make_menus();
}

function gridmouseover(obj)
{
    obj.style.backgroundImage = 'url(\'../images/bg.gif\')';
}

function gridmouseout(obj)
{
    obj.style.backgroundImage = '';
}

function window.confirm(str)
{
    execScript('n=msgbox("'+str+'", "4", "Please Confirm")', "vbscript");
    return(n==6);
}

function openePaper(org_id)
{
    var rnd = Math.random().toString();
    rnd = rnd.substring(2, rnd.length-2);
    rnd = org_id.length.toString() + '.' + rnd + org_id;
    var url = 'http://epaper.cybrarian.in/ePaper/'+rnd+'.aspx';
    //var url = 'http://localhost/MyePaper/ePaper/'+rnd+'.aspx';
    window.open(url, null)
}