﻿// JScript File

 function Confirm()
 {
    alert("Successfully Updated");
    return true;
 }
    
function SelectAllMessages(Id,chkSel)
{

    var obj=document.getElementById(Id); 
    var Sel=document.getElementById(chkSel).checked;
    for(i=1;i<obj.rows.length;i++)
    {
        if(obj.rows[i].cells[0]!=null)
        {
            var inputs = obj.rows[i].cells[0].getElementsByTagName("input");
            if(inputs[0]!=null)
            {
                if(inputs[0].type=="checkbox")
                {
                    inputs[0].checked=Sel;
                }
            }
        }    
    }
}

function SelectInactiveAllMessages(Id,chkSel)
{
    
    var obj=document.getElementById(Id); 
    var Sel=document.getElementById(chkSel).checked;
    for(i=1;i<obj.rows.length;i++)
    {
       if(obj.rows[i].cells[1]!=null)
       {  
           var inputs = obj.rows[i].cells[1].getElementsByTagName("input");
           if(inputs[0]!=null)
           {
               if(inputs[0].type=="checkbox")        
               {
                    inputs[0].checked=Sel;
               }
           }
       }    
    }
}
function SelectCouponAllMessages(Id,chkSel)
{
    
    var obj=document.getElementById(Id); 
    var Sel=document.getElementById(chkSel).checked;
    for(i=1;i<obj.rows.length;i++)
    {
       if(obj.rows[i].cells[9]!=null)
       {  
           var inputs = obj.rows[i].cells[9].getElementsByTagName("input");
           if(inputs[0]!=null)
           { 
               if(inputs[0].type=="checkbox")        
               {
                    inputs[0].checked=Sel;
               }
           }
       }    
    }
}



function ConfirmDeleteMessage(Id)
{
    var Sel=CheckSelected(Id);
    if(!Sel)
    {
        alert("Please select atleast one item to delete");
        return false;
    }
    if(confirm("Are you sure to delete?"))
        return true;
    else
        return false;
}

function CheckSelected(Id)
{
    var obj=document.getElementById(Id); 
    if(obj!=null)
    {
        for(i=0;i<obj.rows.length;i++)
        {
            if(obj.rows[i].cells[0]!=null)
            {
                var inputs = obj.rows[i].cells[0].getElementsByTagName("input");
                if(inputs[0]!=null)
                {
                    if(inputs[0].type=="checkbox")
                    {
                        if(inputs[0].checked)
                        {
                            return true;
                        }  
                    }
                }
            }    
        }
    }
    return false;
}

function ValidateSelectItem(Id,msg)
{
    var Sel=CheckSelected(Id);
    if(!Sel)
    {
        alert(msg);
        return false;
    }
    return true;
}

function GetDeleteConfirmation()
{
    if(confirm("Are you sure to delete?"))
        return true;
    else
        return false;
}

function OpennewWindow(URL,Title,Width,Height) 
{
    if(screen.width)
    {
        var winl = (screen.width-Width)/2;
        var wint = (screen.height-Height)/2;
    }
    else
    {
        winl = 0;wint =0;
    }
    if (winl < 0) winl = 0;
    if (wint < 0) wint = 0;
    
    var settings = 'height=' + Height + ',';
    settings += 'width=' + Width + ',';
    settings += 'top=' + wint + ',';
    settings += 'left=' + winl + ',';
    //settings += features;
    win = window.open(URL,Title,settings);
    win.window.focus();
}

  function CheckImagePath(obj)
  {
        var ImagePath=obj.value;
 	 	var s=new String(ImagePath);
		//Trim method
		s=s.replace( /^\s+/g,'').replace(/\s+$/g,''); 		
	 	if(s.length<=0)
	 	{
	 		return false;
	 	}
	 	return true;
  }
  function CheckImage(obj)
  {
		if(CheckFileType(obj))
		{			
			return true;
		}
		else
		{
		    return false;
		}	
								
		return true;
  }
  
  function CheckFileType(obj)
  {
 	var ext = GetFileType(obj);
 	
	if(ext != "")
	{
		if( ext != 'jpg' && ext!='jpeg' && ext!='gif')
		{
			//alert('The Image file must be a .jpeg or .jpg or gif');
			return false; 
		}
	}
	return true;
  }
  
  function GetFileType(obj)
  {
		var ext = obj.value;
	 	var i=ext.length-3;
	 	if(ext.substr(i-1,1)==".") //.jpg
	 		ext = ext.substring(i,ext.length);
	 	else //.jpeg
	 		ext = ext.substring(i-1,ext.length);
	 		
	 	ext = ext.toLowerCase();
	 	return ext;
  }
  
  function CheckFlash(obj)
  {
        var ext = GetFileType(obj);
     	
	    if(ext != "")
	    {
		    if( ext != 'swf')
		    {
			    return false; 
		    }
	    }
	    return true;
  }
  
  function CheckAnyFileType(obj,extType)
  {
     var ext = GetFileType(obj);
     if(ext != "")
     {
	     if( ext != extType)
	     {
	       return false; 
	     }
     }
     return true;
  }
  
  function CheckFlashAndImage(obj)
  {
        var ext = GetFileType(obj);
        if(ext != "")
        {
	        if(ext != 'swf' && ext != 'jpg' && ext!='jpeg' && ext!='gif')
	        {
		        return false; 
	        }
        }
        return true;
  }
  
  function CheckSize(obj)
  {
		/*var oas = new ActiveXObject("Scripting.FileSystemObject");
		var d = document.getElementById(obj).value;
		if(d!="")
		{
			var e = oas.getFile(d);
			var f = e.size;
			if(f>2000000) //Check for 2MB
			{
				alert('file size should be less than 2 MB');
				document.getElementById(obj).value="";
				return false;
			}
		}
		*/
		return true;
  }    
    
    function fireClickEvent(Popup)
    {
        if(Popup==null)
            return;
        var isFirefox=false;
        var isIE=false;
        var isNets=false;
        var isOther=false;
            
        //Detecting the browser
        if(navigator.userAgent.indexOf("MSIE")!=-1)
            isIE=true;
        else if(navigator.userAgent.indexOf("Firefox")!=-1)
            isFirefox =true;
        else if(navigator.userAgent.indexOf("Netscape")!=-1)
            isNets =true;
        else
            isOther=true;    
       
        if(isFirefox || isNets)
        { 
            if(document.createEvent)
            {
                var eobj=document.createEvent('MouseEvents');
                                
                eobj.initMouseEvent('click', true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);

                Popup.dispatchEvent(eobj);
            }
        }
        else //For IE
        {
            Popup.fireEvent('onclick');
        }
    }
    
    function GettingValue(obj)
    {
        if(obj!=null)
        {
            if(document.all)//ie
                return obj.innerText;
            else
                return obj.textContent;
        }
    }
    
    function SettingValue(obj,val)
    {
        if(obj!=null)
        {
            if(document.all)//ie
                obj.innerText=val;
            else
                obj.textContent=val;
        }
    }
    
    String.prototype.replaceAll = function(pcFrom, pcTo)
    {
	    var is = this.indexOf(pcFrom);
	    var c = this;
    	
	    while (is > -1){
		    c = c.replace(pcFrom, pcTo); 
		    is = c.indexOf(pcFrom);
	    }
	    return c;
   }
   
   function ImageClick(sURL)
    {
       if(sURL=="")
          return false;
       if(sURL.substring(0,4).toLowerCase()=="http")
         {
            window.location = sURL;          
         }
   }

