﻿
//Include script manager, while using this page...

function confirmation(msg)
{    
    if(confirm(msg))
    {
        return true;
    }
    else
        return false;
}

function alertmsg(msg)
{
    alert(msg);
}


function setinnertext(item,val)
{
    if(item)
    {
        if(document.all)
            item.innerText = val;
        else
            item.textContent = val;
    }
}


function getregex(type)
{
    switch(type)
    {
        case '+int':
            return new RegExp(/^(0|[1-9][0-9]*)$/);
        case '+decimal':
            return new RegExp(/(^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$)/);
        case '+intdecimal':
            return new RegExp(/(^(0|[1-9][0-9]*)$)|((^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$))/);
        case 'signedintdecimal':
            return new RegExp(/(^[+]?0(\.0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*\.0+$)/);    
        case 'signedfloat':
            return new RegExp(/^([-+]?[0-9]*\.?[0-9]+)$/);
        case 'email':
            return new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
        default:
            return '';  
//        case 1: // positive integer
//            return '/^(0|[1-9][0-9]*)$/';
//        case 2: // positive decimal
//            return '/(^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$)/';
//        case 3: // positive integer,decimal
//            return '/(^(0|[1-9][0-9]*)$)|((^(0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)$)|(^[1-9]+[0-9]*\.0+$)|(^0\.0+$))/';
//        case 4: // signed integer,decimal
//            return '/(^[+]?0(\.0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)\.(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*\.0+$)/';    
//        case 5: // signed float
//            return '/^([-+]?[0-9]*\.?[0-9]+)$/'; 
//        default:
//            return '';             
    }
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function hidemsg()
{    
    document.body.removeChild(document.getElementById('msgbox'));
    removemodaldiv();   
}

function showmsg(title,msg,width,height,left,top)
{
    if(!width)
        width = 350;
    if(!height)
        height = 50;
    if(!top)
        top = 250;
    if(!left)
        left = 500;
    if(!title)
        title = "Message Box"
    msg = "<div style='height:20px;width:100%;background-color: #930049;color:#ffffff;font-weight:bold;font-family:verdana;font-size:10pt;padding-top:2px;padding-bottom:2px'>&nbsp;" + title + "</div><div style='padding:10px;font-family:verdana;font-size:10pt;'>" + msg + "<div><br/><table style='width:100%'><tr><td align='center'><input type='button' value='ok' class='button' style='width:50px' onclick='hidemsg();'/></td></tr></table>";    
    showmodaldiv();
    var msgbox = document.createElement('div');
    msgbox.setAttribute('id', 'msgbox');
    //msgbox.style.padding = '10px';
   if (width) {
       msgbox.style.width = width+ 'px';
   }
   
   if (height) {
       msgbox.style.height = (height * 1 + 60) + 'px';       
   }
   
   if ((left || top) || (left && top)) {
       msgbox.style.position = "absolute";
       
       if (left) {
           msgbox.style.left = left+ 'px';
       }
       
       if (top) {
           msgbox.style.top = top+ 'px';
       }
   }
   
   msgbox.style.background = "#ffffff";
   msgbox.style.border = "1px solid #930049";
   
   if (msg) {
       msgbox.innerHTML = msg;
   } 
   
   document.body.appendChild(msgbox);     
}

function showmodaldiv()
{
    var modal = document.createElement('div');
    modal.setAttribute('id', 'modal');     
    modal.style.background = "#ffffff";
    modal.style.width = '100%';
    modal.style.height = '100%';
    modal.style.position = "absolute";
    modal.style.left = '0px';
    modal.style.top = '0px';
    modal.style.border = "0px solid #ffffff";     
    //if(modal.style.filter)
        modal.style.filter = 'alpha(opacity=80)';
    //if(modal.style.opacity)
        modal.style.opacity = '.80';
    //modal.setAttribute('style','position:absolute;left:0px;top:0px;width:100%;height:100%;background:#ffffff;filter:alpha(opacity=80);opacity:.80;');
    modal.innerHTML = " ";
    document.body.appendChild(modal);
}

function removemodaldiv()
{
    document.body.removeChild(document.getElementById('modal'));  
}


function showpopupwindow(title,msg,width,height,left,top)
{
    if(!width)
        width = 350;
    if(!height)
        height = 50;
    if(!top)
        top = 250;
    if(!left)
        left = 500;
    if(!title)
        title = "Message Box"
    msg = "<div style='height:22px;width:100%;background:#507CD1;color:#ffffff;font-family:courier new;font-size:8pt;font-weight:bold;padding-top:2px;padding-bottom:2px'><table width=\"100%\"><tr><td>&nbsp;" + title + "</td><td valign=\"top\" align=\"right\"><img alt=\"close\" src=\"../Images/close_btn.jpg\" onclick='hidemsg();'/></td></tr></table></div><div style='padding:10px' class='SimpleText'>" + msg + "<div><br/>";    
    showmodaldiv();
    var msgbox = document.createElement('div');
    msgbox.setAttribute('id', 'msgbox');
    //msgbox.style.padding = '10px';
   if (width) {
       msgbox.style.width = width+ 'px';
   }
   
   if (height) {
       msgbox.style.height = (height * 1 + 60) + 'px';       
   }
   
   if ((left || top) || (left && top)) {
       msgbox.style.position = "absolute";
       
       if (left) {
           msgbox.style.left = left+ 'px';
       }
       
       if (top) {
           msgbox.style.top = top+ 'px';
       }
   }
   
   msgbox.style.background = "#EFF3FB";
   msgbox.style.border = "1px solid #B5C7DE";
   
   if (msg) {
       msgbox.innerHTML = msg;
   } 
   
   document.body.appendChild(msgbox);     
}



        var dtCh= "/";
        var minYear=1900;
        var maxYear=2100;

        function isInteger(s){
	        var i;
            for (i = 0; i < s.length; i++){   
                // Check that current character is number.
                var c = s.charAt(i);
                if (((c < "0") || (c > "9"))) return false;
            }
            // All characters are numbers.
            return true;
        }

        function stripCharsInBag(s, bag){
	        var i;
            var returnString = "";
            // Search through string's characters one by one.
            // If character is not in bag, append to returnString.
            for (i = 0; i < s.length; i++){   
                var c = s.charAt(i);
                if (bag.indexOf(c) == -1) returnString += c;
            }
            return returnString;
        }

        function daysInFebruary (year){
	        // February has 29 days in any year evenly divisible by four,
            // EXCEPT for centurial years which are not also divisible by 400.
            return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
        }
        function DaysArray(n) {
	        for (var i = 1; i <= n; i++) {
		        this[i] = 31
		        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		        if (i==2) {this[i] = 29}
           } 
           return this
        }

        function isDate(dtStr){
	        var daysInMonth = DaysArray(12)
	        var pos1=dtStr.indexOf(dtCh)
	        var pos2=dtStr.indexOf(dtCh,pos1+1)
	        var strMonth=dtStr.substring(0,pos1)
	        var strDay=dtStr.substring(pos1+1,pos2)
	        var strYear=dtStr.substring(pos2+1)
	        strYr=strYear
	        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	        for (var i = 1; i <= 3; i++) {
		        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	        }
	        month=parseInt(strMonth)
	        day=parseInt(strDay)
	        year=parseInt(strYr)
	        if (pos1==-1 || pos2==-1){
		        showmsg('Error',"The date format should be : mm/dd/yyyy",350,50,500,250)
		        return false
	        }
	        if (strMonth.length<1 || month<1 || month>12){
		        showmsg('Error',"Please enter a valid month",350,50,500,250)
		        return false
	        }
	        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		        showmsg('Error',"Please enter a valid day",350,50,500,250)
		        return false
	        }
	        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		        showmsg('Error',"Please enter a valid 4 digit year between "+minYear+" and "+maxYear,400,50,500,250)
		        return false
	        }
	        if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		        showmsg('Error',"Please enter a valid date",350,50,500,250)
		        return false
	        }
        return true
        }
        
  
  //Effects
  
  
  function jumpnvanish(id,cnt)
{
    var div = $get(id);
    if(div)
    {
        div.style.position = 'absolute';
        if(cnt == null || cnt > 10)
        {
            div.style.display = 'none'; 
        }
        else
        {
            //div.style.top = Math.floor((Math.random() * 1001)) + 'px';
            //div.style.left = Math.floor((Math.random() * 1001)) + 'px';
            div.style.top = ((10-cnt) * 80) + 'px';
            div.style.left = ((10-cnt) * 100) + 'px';
            window.setTimeout("jumpnvanish('" + id + "'," + (cnt+1) + ")",200);
        }
//        else if(cnt == 1)
//        {
//            div.style.top = '800px';
//            div.style.left = '800px';
//            window.setTimeout("jumpnvanish('" + id + "'," + (cnt+1) + ")",1000);
//        }
//        else if(cnt == 3)
//        {
//            div.style.top = '100px';
//            div.style.left = '800px';
//            window.setTimeout("jumpnvanish('" + id + "'," + (cnt+1) + ")",1000);
//        }
//        else if(cnt == 4)
//        {
//            div.style.top = '100px';
//            div.style.left = '100px';
//            window.setTimeout("jumpnvanish('" + id + "'," + (cnt+1) + ")",1000);
//        }
//        else
//        {
//            div.style.display = 'none'; 
//        }
    }
}


function fadediv(id,ow,oh)
{
    var div = $get(id);
    if(div)
    {
        var width = div.style.width.toLowerCase().replace('px','') * 1;
        var height = div.style.height.toLowerCase().replace('px','') * 1;
        if(width > 20 && height > 20)
        {
            if(oh == null || ow == null)
            {
                ow = width;
                oh = height;
            }
            width = width - 5;
            height = height - 5;
            div.style.width = width + 'px';
            div.style.height = height + 'px';            
            window.setTimeout("fadediv('" + id + "'," + ow + "," + oh + ")",10);
            
        }
        else
        {
            div.style.display = 'none';                       
            blossom(id,ow,oh);
            //jumpnvanish(id,0);
        }
    }
}

function blossom(id,ow,oh)
{
    var div = $get(id);
    if(div)
    {
        var width = div.style.width.toLowerCase().replace('px','') * 1;
        var height = div.style.height.toLowerCase().replace('px','') * 1;
        if(width <= ow && height <= oh)
        {
            width = width + 5;
            height = height + 5;
            div.style.width = width + 'px';
            div.style.height = height + 'px';
            window.setTimeout("blossom('" + id + "'," + ow + "," + oh + ")",10);
        }
        else
        {
            div.style.display = 'block';
        }
    }
}