// JScript File
function CheckNull(obj,msg)
{
    var strMandatory=document.getElementById('lbl_mandotary');
    
    if(obj.value =="")
    {
        strMandatory.innerHTML=msg;    
    }
    else
    {
        strMandatory.innerHTML='Fields with * Mark are Mandatory';                          
    }
} // function CheckNull(obj,msg)
        
function CheckSelect(obj,msg)
{
    var strMandatory=document.getElementById('lbl_mandotary');
    
    if(obj.value =="--Select--")
        {
            strMandatory.innerHTML=msg;
        }
    else
        {
            strMandatory.innerHTML='Fields with * Mark are Mandatory';                          
        }                                
} // function CheckSelect(obj,msg)

function clearInput(e,v)
{
if(e.value==v)e.value="";
}

function displayInput(e,v)
{
if(e.value=="")e.value=v;
} 

function doClick(buttonName,e)
{//the purpose of this function is to allow the enter key to point to the correct button to click.
    var key;
    if(window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }
} // function doClick(buttonName,e)

//----------------------------- Convert Time into AM/PM Format-------------------

function monthdays(lmonth,lyear)
{
    if(lmonth == 1 || lmonth == 3 || lmonth == 5 || lmonth == 7 || lmonth == 8 || lmonth == 10 || lmonth == 12)
    {
        return 31;
    }
    else if(lmonth == 4 || lmonth == 6 || lmonth == 9 || lmonth == 11)
    {
        return 30;
    }
    else if(lyear % 4 == 0)
    {
        return 29;
    }
    else
    {
        return 28;
    }
}

function padout(number)
{
	return (number < 10) ? '0' + number : number;
}

function ampm(time) {
    var hours = time.getHours(), minutes = padout(time.getMinutes());
    var seconds = padout(time.getSeconds());
    var adjhours = (hours == 0) ? 12 : ((hours < 13) ? hours : hours-12);
	var year = time.getFullYear();
	var month;
	switch(time.getMonth())
	{
		case 0: month="Jan";
			break;
		case 1: month="Feb";
			break;
		case 2: month="Mar";
			break;
		case 3: month="Apr";
			break;
		case 4: month="May";
			break;
		case 5: month="Jun";
			break;
		case 6: month="Jul";
			break;
		case 7: month="Aug";
			break;
		case 8: month="Sep";
			break;
		case 9: month="Oct";
			break;
		case 10: month="Nov";
			break;
		case 11: month="Dec";
	}	
	var date = time.getDate();
    return month+" "+date+", "+(year)+" "+
			((adjhours < 10) ? ' ' : '') + adjhours + ':' + minutes + ':' + seconds + ((hours < 12) ? ' am' : ' pm');
}

//----------------------------- Convert Time into AM/PM Format-------------------

function myPopUp(obj,winName,features)
{
    var theURL = obj.src
    window.open(theURL,winName,features);
    return false;  
} // function myPopUp(obj,winName,features)

function imgPopUp(theURL,winName,features)
{
    window.open(theURL,winName,features);  
    return false;  
} // function imgPopUp(theURL,winName,features)
            
function closeWindow()
{
    window.close(); 
} // function closeWindow()

function Delete_Alert()
{
if (confirm('Are you sure you want to delete ??') == true)
    {
        return true;
    }
else
    {
        return false;
    }
} // function Delete_Alert()

function Delete_Deny()
{
        alert('Cannot Delete selected record as it is already referenced in another Module !!');
} // function Delete_Deny()

function Hide_Row(id)
{
    document.getElementById(id).style.display = 'none';
} // function Hide()



// Date Picker & Calendar Control functions
        
function Picker_OnSelectionChanged(Picker)
{
    Picker.AssociatedCalendar.SetSelectedDate(Picker.GetSelectedDate());
} // function Picker_OnSelectionChanged(Picker)

function Calendar_OnSelectionChanged(calendar)
{
  calendar.AssociatedPicker.SetSelectedDate(calendar.GetSelectedDate());
} // function Calendar_OnSelectionChanged(calendar)

function Button_OnClick(alignElement, calendar)
{
  if (calendar.PopUpObjectShowing)
  {
    calendar.Hide();
  }
  else
  {
    calendar.SetSelectedDate(calendar.AssociatedPicker.GetSelectedDate());
    calendar.Show(alignElement);
  }
} // function Button_OnClick(alignElement, calendar)

function Button_OnMouseUp(calendar)
{
  if (calendar.PopUpObjectShowing)
  {
    event.cancelBubble=true;
    event.returnValue=false;
    return false;
  }
  else
  {
    return true;
  }
} // function Button_OnMouseUp(calendar)

// Date Picker & Calendar Control functions

function resizetoimage(ImgWidth, ImgHeight)
{
    //alert(document.images['Image1'].width);
    //alert(document.images['Image1'].height);
    
    var minwt = 350;
    if (ImgWidth == 0) {ImgWidth = document.images['Image1'].width}
    if (ImgHeight == 0) {ImgHeight = document.images['Image1'].height}
    
    var maxwt = ImgWidth + 50;
    var maxht = ImgHeight + 130;
    if (maxwt < minwt) {maxwt = minwt;}
    
    window.moveTo(5,5);
    window.resizeTo(maxwt, maxht);
}

function resizetoControlSize(CtlWidth, CtlHeight)
{   
    var CtlWidth = CtlWidth + 0;
    var CtlHeight = CtlHeight + 0;
    
    window.resizeTo(CtlWidth, CtlHeight);
}

function resizetoFullScreen()
{
    var maxwt = screen.availwidth
    var maxht = screen.availheight

    window.moveTo(0,0);
    window.resizeTo(maxwt, maxht);
}

function fnIntegerValidation(f,evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if(charCode == 46)
{
    var arr=f.value.split('.');

    if (arr.length > 1)
        {
            return false;
        }
    return true;
}

if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

    return true;
}

function fnNumberValidation(f,evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if(charCode == 46)
{
    var arr=f.value.split('.');

    if (arr.length >= 1)
        {
            return false;
        }
    return true;
}

if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

    return true;
}

function fnAlphaSpaceValidation(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode == 32 || charCode == 46 || charCode == 95 
     || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) )
    {
            return true;
        }
    return false;
}

function fnAlphaNumericSpaceValidation(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode == 32 || charCode == 46 || charCode == 95 
     || (charCode >= 48 && charCode <= 57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) )
    {
            return true;
        }
    return false;
}

function fnSMSNumberValidation(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode == 13 || (charCode >= 48 && charCode <= 57))
    {
            return true;
        }
    return false;
}

function fnSMSMessageValidation(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode == 32 || charCode == 46 || charCode == 95 || charCode == 37
     || (charCode >= 48 && charCode <= 57) || (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) )
    {
            return true;
        }
    return false;
}

function fnValidateInput(obj, command, cmdvalue)
{
 switch(command) 
 {
    case "getlength":
    case "getlen":
    { 
         var val = obj.value;
         val = val.replace(/^\s+|\s+$/g,"");
            
		 ret = eval(val.length)
         break; 
    }//case getlen 
    case "maxlength": 
    case "maxlen": 
      { 
		 ret = true;
         var strMaxLen = cmdvalue;
         
         if(eval(obj.value.length) >  eval(strMaxLen)) 
         { 
            ret = false;   
         }//if 
         break;  
      }//case maxlen 
    case "minlength": 
    case "minlen": 
       { 
         ret = true;
         var strMinLen = cmdvalue;
         
         if(eval(obj.value.length) <  eval(strMinLen)) 
         { 
            ret = false;   
         }//if 
         break; 
        }//case minlen 
    case "alnum": 
    case "alphanumeric": 
       { 
			ret = true;

            var charpos = obj.value.search("[^A-Za-z0-9\\_\.]"); 
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break; 
       }
    case "pass": 
    case "password": 
       { 
			ret = true;

            var charpos = obj.value.search("[^A-Za-z0-9]"); 
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break; 
       }
    case "alnum_s": 
    case "alphanumeric_space": 
       { 
			ret = true;

            var charpos = obj.value.search("[^A-Za-z0-9\\s\\_\.]"); 
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break;  
       }
    case "num_sms": 
    case "numeric_sms": 
       { 
			ret = true;

            var charpos = obj.value.search("[^0-9[\r\n]|$]");
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if  (Enter Key or New Line -- [\r\n]|$
            break;  
       }
    case "alnum_sms": 
    case "alphanumeric_sms": 
       { 
			ret = true;

            var charpos = obj.value.search("[^A-Za-z0-9\\s\\_\.\%]");  
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break;  
       }		   
    case "num": 
    case "numeric": 
       { 
            ret = true;

            var charpos = obj.value.search("[^0-9]"); 
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break;
       }
    case "dec": 
    case "decimal": 
       { 
            ret = true;

            var charpos = obj.value.search("[^0-9\.]"); 
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break;              
       }
    case "alphabetic": 
    case "alpha": 
       { 
            ret = true;

            var charpos = obj.value.search("[^A-Za-z\\_\.]"); 
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break; 
       }
    case "alphabetic_space": 
    case "alpha_s": 
       { 
            ret = true;

            var charpos = obj.value.search("[^A-Za-z\\s\\_\.]"); 
            if(obj.value.length > 0 &&  charpos >= 0) 
            { 
              ret = false; 
            }//if 
            break;  
       }	 
 }//switch
 return ret;
}

function fnViewPDFFile(obj,format)
{
    if (format == 'obj')
        {
            var path = document.getElementById(obj).value;
            if (path=="") { return false;}
            path = "../Products/" + path;
        }
    else if (format == 'root')
        {
            var path = document.getElementById(obj).value;
            if (path=="") { return false;}
            path = "Products/" + path;
        }
    else if (format == 'path')
        {
            path = obj;
        }
    var maxwt = screen.availwidth -50;
    var maxht = screen.availheight - 50;
    
    window.open(path ,'ViewPDFFile','resizable=no,scrollbars=yes,width=' + maxwt + ',height=' + maxht + '');
    return false;
}

/* ------- Disable Right Click ------- */
//var message="Sorry, right-click has been disabled !!";
var message="";  //Disable Message Poppup...
function fnRighClickDisabled()
{
    function clickIE4()
    {
        if (event.button==2)
        {
            //alert(message);
            (message);
            return false;
        }
    }

    function clickNS4(e)
    {
        if (document.layers||document.getElementById&&!document.all)
        {
            if (e.which==2||e.which==3)
            {
                //alert(message);
                (message);
                return false;
            }
        }
    }

    if (document.layers)
    {
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown=clickNS4;
    }
    else if (document.all&&!document.getElementById)
    {
        document.onmousedown=clickIE4;
    }

    //document.oncontextmenu=new Function("alert(message);return false")
    document.oncontextmenu=new Function("(message);return false")
}

/* ------- Document Text Sizer ------- */
//Specify affected tags. Add or remove from list:
var arrTgs = new Array( 'div','td','tr');

//Specify spectrum of different font sizes:
var arrSizes = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function fnTextSize( target,pxls ) {
	if (!document.getElementById) return
	var d = document,cEl = null,size = startSz,i,j,cTags;
	
	size += pxls;
	if ( size < 0 ) size = 0;
	if ( size > 6 ) size = 6;
	startSz = size;
		
	if ( !( cEl = d.getElementById( target ) ) ) cEl = d.getElementsByTagName( target )[ 0 ];

	cEl.style.fontSize = arrSizes[ size ];

	for ( i = 0 ; i < arrTgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( arrTgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = arrSizes[ size ];
	}
}

function ShowBiggerImage(obj) 
{
//    document.getElementById("LargeImage").innerHTML = "<img src='" + obj.src + "'+'width=250 height=400' >";
    document.getElementById("LargeImage").innerHTML = "<img src='" + obj.src + "'+'' >";
}

function ShowDefaultImage(obj) 
{
    document.getElementById("LargeImage").innerHTML = "";
}

function move_Area(event)
{
 event = event || window.event;
 
    var divCollection = document.getElementsByTagName("div");
    for (var i=0; i<divCollection.length; i++) {
        if(divCollection[i].getAttribute("id") == "LargeImage") {
            LargeImage.style.left=event.clientX+document.body.scrollLeft+10;
            LargeImage.style.top=event.clientY+document.body.scrollTop+10;
        } 
    }
}
document.onmousemove = move_Area;
