function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function CheckDate(ctrlMonth, ctrlDay, ctrlYear,ctrlMonth2, ctrlDay2, ctrlYear2)
{
	
	var Wdate="DateFrom";
	var Wdate2="DateTo";
	var month = document.getElementById(ctrlMonth).value; 	
	var day = document.getElementById(ctrlDay).value; 
	var year = document.getElementById(ctrlYear).value; 	
	
	var month2 = document.getElementById(ctrlMonth2).value; 	
	var day2 = document.getElementById(ctrlDay2).value; 
	var year2 = document.getElementById(ctrlYear2).value; 	
	//alert(month + "/" + day + "/" + year)
	var sDate = String(month) + "/" + String(day) +  "/"+  year;		
	
	var sDate2 = String(month2) + "/" + String(day2) +  "/"+  year2;		
	
	if((sDate == "//" || IsDate(sDate,Wdate) == true)&&(sDate2 == "//" || IsDate(sDate2,Wdate2) == true))		
	{		
		return true;
	}
	//alert("Invalid date.\n" + errorDate);
	var ctrl = document.getElementById(ctrlMonth);
	ctrl.focus();			
	return false;
}
function IsDate(dateStr,Wdate) 
{
	//Modified by DO 12/31/2003
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	var datestatus=true;
	datemsg="";
	if (matchArray == null || matchArray[1]==null) 
	{
		datemsg="Please enter date as mm/dd/yyyy " + "\n";
		errorDate = datemsg;
		return false;
	}
	else
	{
		if(matchArray[3]==null || matchArray[5]==null)
		{
			datemsg="Please enter date as mm/dd/yyyy " + "\n";
			errorDate = datemsg;
			return false;
		}
	}

	month = matchArray[1]; // p@rse date into variables
	day = matchArray[3];
	year = matchArray[5];		
	
	if (month < 1 || month > 12) 
	{ // check month range
		datemsg=datemsg + "Month must be between 1 and 12." + "\n";
		datestatus=false;
	}
	if (day < 1 || day > 31) 
	{
		datemsg=datemsg + "Day must be between 1 and 31." + "\n";
		datestatus=false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		datemsg=datemsg + "Month " + month + " doesn`t have 31 days!" + "\n";
		datestatus=false;
	}
	if (month == 2) 
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) 
		{
			datemsg=datemsg + "February " + year + " doesn`t have " + day + " days!" + "\n";
			datestatus=false;
		}
	}		
	errorDate = datemsg;
	var check="";
	if(datemsg!=""){
	    check=Wdate+":"+"\n"+datemsg;
	    alert(check);
	}
	return datestatus; 
}
function GLCheckBoxAll(chkMaster, chks)
{           
    var arraychk = chks.split(',');       
    var chkType = document.getElementById(chkMaster).checked;
    for(var c = 0; c < arraychk.length - 1; c++)
    {
        document.getElementById(arraychk[c]).checked = chkType;
    }                        
}
function GLUpdateDelete(chks)
{           
    var arraychk = chks.split(',');           
    for(var c = 0; c < arraychk.length - 1; c++)
    {        
        if(document.getElementById(arraychk[c]).checked == true)
            return true;                 
    }            
    alert("Please select an item to delete");
    return false;     
}

function DeleteConfirm()
{    
    return confirm("Do you really want to delete the selected item(s)?");    
}


////////Bulk mail
function ConfirmDeleteMailer(item)
{    
     if(document.getElementById(item).value=="")
    {
        alert("Mailer list is null.");
        return false;
     }
     else
    return confirm("Do you really want to delete this mailer?");    
}
function CheckDeleteSaleLead()
{   
    
    return confirm("Do you really want to delete this record?");    
}

function CheckGallery(txtAdd)
{
       if(document.getElementById(txtAdd).value=="")
    {
        alert("Please check Gallery name again!");
        return false;
    }
    return true;      

}

function CheckAddMailer(txtAdd)
{
    if(document.getElementById(txtAdd).value=="")
    {
        alert("Please check mailer name again!");
        return false;
    }
    return true;        

}
function CheckSendMailer(ddl1,ddl2)
{
       
    //alert(ddl1);
    var str="";
    if(document.getElementById(ddl1).value==""||document.getElementById(ddl1).value=="undefine")
    {       
        str=str+"Please select a mailer!" + "\n";
        
    }
     //alert(document.getElementById(ddl1).value);
    if(document.getElementById(ddl2).value=="")
    {       
        str=str+"Please select a group of email!" + "\n";
        
    }
    if(str!=""){        
        alert(str);
        return false;        
        
     }
    else
        return true;
        
}
function CheckSendTestMail(txtAdd)
{    
    var email;
    email=document.getElementById(txtAdd).value;
    if(email==""||email.indexOf("`") != -1||email.indexOf("&") != -1||email.indexOf("'") != -1||email.indexOf(">") != -1||email.indexOf("<") != -1||email.indexOf("~") != -1||email.indexOf(",") != -1||email.indexOf("!") != -1||email.indexOf("#") != -1||email.indexOf("$") != -1||email.indexOf("%") != -1||email.indexOf("-") != -1||email.indexOf("+") != -1||email.indexOf("\\") != -1||email.indexOf("]") != -1||email.indexOf("[") != -1||email.indexOf("^") != -1||email.indexOf("/") != -1||email.indexOf("@") == -1||filename.indexOf(".") == -1)             
        {
            alert("Please enter a valid Email Address.");
            return false;
        }
      
    return true;        
}

////Photogallerty
function DeleteConfirmPhotogallery()
{    
    
        return confirm("You are about to remove a gallery and all of it's images, are you sure you want to proceed?");    
}
function ConfirmPhotogalleryView(item)
{    
    if(document.getElementById(item).value=="")
    {
        alert("Gallery list is null.");
        return false;
     }
    
}

//////
//////SaleLead
function ConfirmDeleteItemForm(item)
{    
    if(document.getElementById(item).value=="")
    {
        alert("There is no item to delete.");
        return false;
     }
    
}
function OpenNewWindow(sLocation)

{
    if( (newWindow == null ) || (newWindow.closed) )
    { 
        newWindow = window.open( sLocation, "", 'fullscreen=no,resizable,scrollbars=yes,status=yes,width=800px,height=600px');newWindow.document.open( "text/plain" );

    } 

    newWindow.moveTo(0,0);

    newWindow.focus();

    newWindow.window.location.href = sLocation;

    newWindow.document.close();

} 
function wopen(url, name, w, h)

{

    // Fudge factors for window decoration space.   

    w += 32;

    h += 96;

    wleft = (screen.width - w) / 2;

    wtop = (screen.height - h) / 2;

    // IE5 and other old browsers might allow a window that is

    // partially offscreen or wider than the screen. Fix that.

    // (Newer browsers fix this for us, but let's be thorough.)
    if (wleft < 0) {

    w = screen.width;

    wleft = 0;

    }
    if (wtop < 0) {

    h = screen.height;

    wtop = 0;

    }
    var win = window.open(url,

    name,
    'width=' + w + ', height=' + h + ', ' +

    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, modal=yes' +

    'status=no, toolbar=no, scrollbars=yes, resizable=yes', 'tite=no', 'resizable=no', 'directories=no', 'status=no');

    // Just in case width and height are ignored

    win.resizeTo(w, h);

    // Just in case left and top are ignored

    win.moveTo(wleft, wtop);

    win.focus();

} 

////retrieve code

function copyText(theId) {
   var obj=document.getElementById(theId);
   obj.focus();
   obj.select();
   copyToClipb(obj.value); 
}
function copyToClipb(txt) {
 if (window.clipboardData) {
   window.clipboardData.setData("Text", txt); 
   } 
   else if (window.netscape) 
   { 
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

   var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return; 
 
   var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
   if (!trans) return; 
   trans.addDataFlavor('text/unicode');  
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=txt;   
   str.data=copytext;   
   trans.setTransferData("text/unicode",str,copytext.length*2);   
   var clipid=Components.interfaces.nsIClipboard;   
   if (!clip) return false;   
   clip.setData(trans,null,clipid.kGlobalClipboard);   
   }
   //alert("Following info was copied to your clipboard:\n\n" + txt);
   return false;
}

function checkFilename( field )
     {
       	var filename=document.getElementById(field).value;
      
      	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-()'`: ";
		var checkStr = filename;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		}
		if (!allValid)
		{
			alert("Please enter valid characters in the field.");			
			return false;
		}
     }
function CheckDeleteImage()
{   
    
    return confirm("Do you really want to delete this image?");    
}
function CheckMailType(type)
{
     
     //alert("anc");
     var mailtype=document.getElementById(type).value;
     if(mailtype=="")             
       {
         alert( "Please select a mailer or create a mailer to send." );
         return false;
       }
       else{         
         return true;
       }
       
}
function CheckMailList(list)
{
     
     //alert("anc");
     var mailist=document.getElementById(list).value;
     if(mailist=="")             
       {
         alert( "Please select a group of email!" );
         return false;
       }
       else{         
         return true;
       }
       
}
function GLUpdateDelete2(chks)
{           
    var arraychk = chks.split(',');           
    for(var c = 0; c < arraychk.length - 1; c++)
    {        
        if(document.getElementById(arraychk[c]).checked == true)
            return true;                 
    }            
    alert("Please select an email to send.");
    return false;     
}
function DeleteConfirm2()
{    
    return confirm("Do you really want to send the selected email(s)?");    
}
function CheckFromAddress(add)
{
     
     //alert("anc");
     var mailist=document.getElementById(add).value;
     if(mailist=="")             
       {
         alert( "Please Configure Your Mailer's From Address!" );
         return false;
       }
       else{         
         return true;
       }
       
}



